-
Notifications
You must be signed in to change notification settings - Fork 3
Dockerfile Enhancements #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,10 @@ | ||
| node_modules | ||
| npm-debug.log | ||
| images | ||
| images | ||
| .git | ||
| .github | ||
| coverage | ||
| packages/**/coverage | ||
| packages/frontend | ||
| packages/jobs | ||
| **/*.log | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,37 +2,31 @@ | |
| FROM node:20-alpine AS build | ||
| WORKDIR /usr/src/app | ||
|
|
||
| # Copy root package files for workspaces | ||
| # Copy workspace and backend files required for compilation and minification. | ||
| COPY package.json package-lock.json ./ | ||
| COPY tsconfig.base.json ./ | ||
| COPY packages/backend/package.json ./packages/backend/ | ||
| COPY packages/backend/tsconfig.json ./packages/backend/ | ||
| COPY packages/backend/tsconfig.prod.json ./packages/backend/ | ||
| COPY packages/backend/src ./packages/backend/src | ||
|
|
||
| # Build and minify backend artifact inside Docker. | ||
| RUN npm ci \ | ||
| && npm run build:prod -w @mocker/backend \ | ||
| && npm run minify -w @mocker/backend \ | ||
|
Comment on lines
6
to
+16
|
||
| && npx esbuild /usr/src/app/packages/backend/dist/index.js --bundle --minify --platform=node --target=node20 --format=cjs --outfile=/usr/src/app/packages/backend/dist/runtime.cjs \ | ||
| && mkdir -p /usr/src/app/images | ||
|
|
||
| FROM gcr.io/distroless/nodejs20-debian12:nonroot AS release | ||
| ENV NODE_ENV=production \ | ||
| PORT=80 | ||
|
|
||
| # Copy backend package | ||
| COPY packages/backend/package.json packages/backend/ | ||
| COPY packages/backend/tsconfig.json packages/backend/ | ||
| COPY packages/backend/tsconfig.prod.json packages/backend/ | ||
| COPY packages/backend/src packages/backend/src | ||
|
|
||
| # Install dependencies and build | ||
| RUN npm ci | ||
| RUN npm run build:prod -w @mocker/backend | ||
|
|
||
| FROM node:20-alpine AS release | ||
| ENV NODE_ENV=production PORT=80 | ||
| WORKDIR /usr/src/app | ||
|
|
||
| # Copy built output | ||
| COPY --from=build /usr/src/app/packages/backend/dist ./ | ||
|
|
||
| # Copy package files for production install | ||
| COPY --from=build /usr/src/app/package.json ./ | ||
| COPY --from=build /usr/src/app/package-lock.json ./ | ||
| COPY --from=build /usr/src/app/packages/backend/package.json ./packages/backend/ | ||
|
|
||
| RUN mkdir -p /usr/src/app/images | ||
|
|
||
| # Install production dependencies only for the backend workspace | ||
| RUN npm pkg delete scripts.prepare && npm ci --omit=dev -w @mocker/backend --ignore-scripts | ||
| # Copy bundled runtime artifact and writable path from build stage. | ||
| COPY --from=build --chown=65532:65532 /usr/src/app/packages/backend/dist/runtime.cjs ./runtime.cjs | ||
| COPY --from=build --chown=65532:65532 /usr/src/app/images ./images | ||
|
Comment on lines
+26
to
+28
|
||
|
|
||
| EXPOSE 80 | ||
|
|
||
| CMD ["node", "/usr/src/app/index.js"] | ||
| CMD ["/usr/src/app/runtime.cjs"] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.dockerignoreexcludespackages/frontend, but the Docker build currently runsnpm cifrom the repo root with npm workspaces enabled. If you address the workspace install issue by copyingpackages/frontend/package.jsoninto the build stage, this ignore rule will prevent it from being available toCOPY. Consider un-ignoring at least the workspace manifest(s) needed for install (e.g. add a!packages/frontend/package.jsonexception) or adjust the Docker build to install solely frompackages/backendso other workspaces can remain ignored.