-
Notifications
You must be signed in to change notification settings - Fork 0
Dockerize API application with multi-stage build and update utils #49
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
base: feat/new-template
Are you sure you want to change the base?
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 |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| ### Base Image | ||
| FROM node:24-alpine AS base | ||
| RUN apk add --no-cache git libc6-compat tzdata g++ make py3-pip && \ | ||
| apk update | ||
| ENV TZ=America/Caracas | ||
|
|
||
| ENV SCOPE=@repo/api | ||
| ENV APP_PATH=apps/api | ||
|
|
||
|
|
||
| ### Builder | ||
| FROM base AS builder | ||
| WORKDIR /app | ||
| COPY . . | ||
| RUN npx turbo prune --scope=${SCOPE} --docker | ||
|
|
||
| ### Installer | ||
| FROM base AS installer | ||
| WORKDIR /app | ||
|
|
||
| # Install deps | ||
| COPY --from=builder /app/out/json/ . | ||
| COPY --from=builder /app/out/package-lock.json ./package-lock.json | ||
| RUN npm ci --no-audit | ||
|
|
||
| # Build project | ||
| COPY --from=builder /app/out/full/ . | ||
| COPY --from=builder /app/out/full/turbo.json turbo.json | ||
| RUN npx turbo build --filter=${SCOPE} | ||
|
|
||
| ### Production Dependencies | ||
| FROM base AS prod-deps | ||
| WORKDIR /app | ||
| COPY --from=builder /app/out/json/ . | ||
| COPY --from=builder /app/out/package-lock.json ./package-lock.json | ||
| RUN npm ci --omit=dev --no-audit | ||
|
|
||
| ### Runner | ||
| FROM node:24-alpine AS runner | ||
| RUN apk add --no-cache tzdata | ||
| ENV TZ=America/Caracas | ||
| ENV NODE_ENV=production | ||
| ENV APP_PATH=apps/api | ||
| WORKDIR /app | ||
|
|
||
| RUN addgroup --system --gid 1001 avilatek && \ | ||
| adduser --system --uid 1001 nestjs | ||
| USER nestjs | ||
|
|
||
| COPY --from=prod-deps --chown=nestjs:nodejs /app/node_modules ./node_modules | ||
| COPY --from=installer --chown=nestjs:nodejs /app/packages ./packages | ||
| COPY --from=installer --chown=nestjs:nodejs /app/${APP_PATH}/dist ./${APP_PATH}/dist | ||
| COPY --from=installer --chown=nestjs:nodejs /app/${APP_PATH}/package.json ./${APP_PATH}/package.json | ||
| COPY --from=installer --chown=nestjs:nodejs /app/package.json ./package.json | ||
|
|
||
| ENV PORT=3000 | ||
| EXPOSE 3000 | ||
|
|
||
| WORKDIR /app/${APP_PATH} | ||
| CMD ["node", "dist/src/main.js"] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The Dockerfile Suggested FixUpdate the Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
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.
Bug: The
COPY --chowncommand in the Dockerfile references a non-existent groupnodejsinstead of the createdavilatekgroup, causing file permission errors at runtime.Severity: CRITICAL
Suggested Fix
In the Dockerfile, change all instances of
COPY --chown=nestjs:nodejstoCOPY --chown=nestjs:avilatekto correctly assign file ownership to the user and group created within the Docker image.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.