diff --git a/.dockerignore b/.dockerignore index b7f91f5..a22f477 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,7 @@ node_modules # Ignore common folders that we do not need +.git .next .github .vscode \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index a7c2e4b..c05d73b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] \ No newline at end of file +CMD ["/bin/ash", "/app/entrypoint.sh"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..f9a0010 --- /dev/null +++ b/entrypoint.sh @@ -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