Skip to content

Commit 8712074

Browse files
committed
Add Dockerfile and docker build github action
1 parent eab184b commit 8712074

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.github/workflows/publish-docker.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
on:
2+
push:
3+
branches:
4+
#branches: [main]
5+
6+
jobs:
7+
build-push:
8+
- name: Checkout
9+
uses: actions/checkout@v4
10+
- name: Docker metadata
11+
id: meta
12+
uses: docker/metadata-action@v5
13+
with:
14+
# list of Docker images to use as base name for tags
15+
images: |
16+
${{ secrets.DOCKERHUB_USERNAME }}/pkl-playground
17+
# generate Docker tags based on the following events/attributes
18+
tags: |
19+
type=schedule
20+
type=sha
21+
22+
- name: Set up QEMU
23+
uses: docker/setup-qemu-action@v3
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
- name: Login to Docker Hub
29+
uses: docker/login-action@v3
30+
with:
31+
username: ${{ secrets.DOCKERHUB_USERNAME }}
32+
password: ${{ secrets.DOCKERHUB_TOKEN }}
33+
34+
- name: Build and push
35+
uses: docker/build-push-action@v5
36+
with:
37+
push: false
38+
# push: true
39+
tags: ${{ steps.meta.outputs.tags }}
40+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
FROM node:18-alpine AS base
2+
3+
# Install dependencies only when needed
4+
FROM base AS deps
5+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
6+
RUN apk add --no-cache libc6-compat
7+
WORKDIR /app
8+
9+
# Install dependencies based on the preferred package manager
10+
COPY package.json package-lock.json ./
11+
RUN npm ci
12+
13+
# Rebuild the source code only when needed
14+
FROM base AS builder
15+
WORKDIR /app
16+
COPY --from=deps /app/node_modules ./node_modules
17+
COPY . .
18+
19+
ENV NEXT_TELEMETRY_DISABLED 1
20+
21+
RUN npm run build
22+
23+
# Production image, copy all the files and run next
24+
FROM base AS runner
25+
WORKDIR /app
26+
27+
ENV NODE_ENV production
28+
# Uncomment the following line in case you want to disable telemetry during runtime.
29+
ENV NEXT_TELEMETRY_DISABLED 1
30+
31+
RUN addgroup --system --gid 1001 nodejs
32+
RUN adduser --system --uid 1001 nextjs
33+
34+
COPY --from=builder /app/public ./public
35+
36+
# Set the correct permission for prerender cache
37+
RUN mkdir .next
38+
RUN chown nextjs:nodejs .next
39+
40+
# Automatically leverage output traces to reduce image size
41+
# https://nextjs.org/docs/advanced-features/output-file-tracing
42+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
43+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
44+
45+
USER nextjs
46+
47+
EXPOSE 3000
48+
49+
ENV PORT 3000
50+
# set hostname to localhost
51+
ENV HOSTNAME "0.0.0.0"
52+
53+
# server.js is created by next build from the standalone output
54+
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
55+
CMD ["node", "server.js"]

0 commit comments

Comments
 (0)