Skip to content

Dockerfile Enhancements#183

Merged
sfreeman422 merged 1 commit intomasterfrom
feature/improve-harden-docker
Mar 22, 2026
Merged

Dockerfile Enhancements#183
sfreeman422 merged 1 commit intomasterfrom
feature/improve-harden-docker

Conversation

@sfreeman422
Copy link
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings March 22, 2026 12:46
@sfreeman422 sfreeman422 merged commit f0e9605 into master Mar 22, 2026
7 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the backend container build to produce a smaller production image by bundling/minifying the backend into a single runtime artifact and switching the runtime stage to a distroless Node.js base image, alongside tightening the Docker build context via .dockerignore.

Changes:

  • Refactors packages/backend/Dockerfile to build + bundle a single runtime.cjs artifact and run it from a distroless nodejs20 nonroot image.
  • Removes production npm ci --omit=dev install from the runtime stage (no node_modules copied into the final image).
  • Expands .dockerignore to exclude VCS metadata, coverage outputs, and other workspace directories from the build context.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/backend/Dockerfile Builds and bundles the backend into a single runtime.cjs and runs it in a distroless nonroot image.
.dockerignore Shrinks Docker build context by ignoring repo metadata, coverage, and other package directories.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 6 to +16
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 \
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm ci is executed from the repo root, but the image only copies the backend workspace files into /usr/src/app/packages. Since the root package.json declares workspaces ("packages/*") and the repo also has packages/frontend/package.json, npm workspaces installs can fail when the other workspace manifests aren’t present in the container filesystem. Consider either copying the missing workspace package.json files (at least packages/frontend/package.json) before npm ci, or switching the Docker build to install/build from packages/backend using packages/backend/package-lock.json so the root workspaces aren’t involved.

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +28
# 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
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The release stage only copies a single bundled runtime.cjs. The backend uses TypeORM’s getConnectionOptions() and requires TYPEORM_ENTITIES to be set (see src/index.ts), which typically points to entity files on disk (e.g. dist/shared/db/models/*.js). With only runtime.cjs present, TypeORM won’t be able to load entities from the filesystem, so DB initialization is likely to fail at runtime. Either keep/copy the compiled entity files into the image and set TYPEORM_ENTITIES accordingly, or change the app configuration to pass entity classes explicitly (and avoid relying on glob paths) when running from a bundled artifact.

Copilot uses AI. Check for mistakes.
coverage
packages/**/coverage
packages/frontend
packages/jobs
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.dockerignore excludes packages/frontend, but the Docker build currently runs npm ci from the repo root with npm workspaces enabled. If you address the workspace install issue by copying packages/frontend/package.json into the build stage, this ignore rule will prevent it from being available to COPY. Consider un-ignoring at least the workspace manifest(s) needed for install (e.g. add a !packages/frontend/package.json exception) or adjust the Docker build to install solely from packages/backend so other workspaces can remain ignored.

Suggested change
packages/jobs
packages/jobs
!packages/frontend/package.json
!packages/jobs/package.json

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants