Production build at container run time
All checks were successful
Build Production Image / Build Production Image (push) Successful in 58s

This commit is contained in:
Tony Grosinger 2024-01-14 12:39:49 -08:00
parent d98da909ae
commit e666588cc3
3 changed files with 11 additions and 20 deletions

View File

@ -2,6 +2,7 @@
node_modules
# Ignore common folders that we do not need
.git
.next
.github
.vscode

View File

@ -1,6 +1,7 @@
FROM docker.io/library/node:18-alpine AS build-env
# Disable telemetry
ENV NODE_ENV production
ENV PORT 3000
ENV NEXT_TELEMETRY_DISABLED 1
WORKDIR /app
@ -15,23 +16,5 @@ RUN npm install
# Copy files. Use dockerignore to avoid copying node_modules
COPY . .
# Build
RUN npm run build
# Running the app
FROM gcr.io/distroless/nodejs:18 AS runner
WORKDIR /app
# Mark as prod, disable telemetry, set port
ENV NODE_ENV production
ENV PORT 3000
ENV NEXT_TELEMETRY_DISABLED 1
# Copy from build
COPY --from=build-env /app/next.config.mjs ./
COPY --from=build-env /app/public ./public
COPY --from=build-env /app/.next ./.next
COPY --from=build-env /app/node_modules ./node_modules
# Run app command
CMD ["./node_modules/next/dist/bin/next", "start"]
CMD ["/bin/ash", "/app/entrypoint.sh"]

7
entrypoint.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
# The build step hard-codes variables from the environment into HTML, so it must
# be done with the correct .env.local for runtime.
./node_modules/next/dist/bin/next build
./node_modules/next/dist/bin/next start