-
Notifications
You must be signed in to change notification settings - Fork 195
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
fix: updated docker base image to node:20-alpine3.21 #733
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,10 +1,10 @@ | ||||||
# run directly from the repo root directory | ||||||
# docker build -f ./apps/webapp/Dockerfile . | ||||||
FROM node:20-alpine AS base | ||||||
FROM node:20-alpine3.21 AS base | ||||||
# ======================================================================= | ||||||
# Turbo: Prepare a standalone workspace for docker | ||||||
FROM base AS builder | ||||||
RUN apk add --no-cache libc6-compat | ||||||
RUN apk add --no-cache libc6-compat openssl | ||||||
RUN apk update | ||||||
|
||||||
# Set pnpm | ||||||
|
@@ -23,7 +23,7 @@ RUN ls -la ./out/full/apps/webapp | |||||
# ======================================================================= | ||||||
# Install Deps and build project using PNPM | ||||||
FROM base AS installer | ||||||
RUN apk add --no-cache libc6-compat | ||||||
RUN apk add --no-cache libc6-compat openssl | ||||||
RUN apk update | ||||||
# Set pnpm | ||||||
ENV PNPM_HOME="/pnpm" | ||||||
|
@@ -47,8 +47,6 @@ RUN corepack enable | |||||
|
||||||
WORKDIR /app | ||||||
|
||||||
RUN ls -la | ||||||
|
||||||
# First install the dependencies (as they change less often) | ||||||
COPY .gitignore .gitignore | ||||||
COPY --from=builder /app/out/json/ . | ||||||
|
@@ -63,5 +61,4 @@ RUN pnpm install --shamefully-hoist | |||||
COPY --from=builder ./app/out/full/ . | ||||||
RUN pnpm run build | ||||||
|
||||||
CMD cd /app/apps/webapp/ && pnpm run start | ||||||
|
||||||
CMD cd /app/apps/webapp/ && pnpm run start | ||||||
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. 🧹 Nitpick (assertive) Improve CMD instruction format. Use JSON array notation for CMD as recommended by Docker best practices: -CMD cd /app/apps/webapp/ && pnpm run start
+CMD ["sh", "-c", "cd /app/apps/webapp/ && pnpm run start"] 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Hadolint (2.12.0)[warning] 64-64: Use arguments JSON notation for CMD and ENTRYPOINT arguments (DL3025) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# run directly from the repo root directory | ||
# docker build -f ./apps/webapp/Dockerfile.dev . | ||
FROM node:20-alpine AS base | ||
FROM node:20-alpine3.21 AS base | ||
# ======================================================================= | ||
FROM base AS builder | ||
RUN apk add --no-cache libc6-compat | ||
RUN apk add --no-cache libc6-compat openssl | ||
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. 🧹 Nitpick (assertive) Consider Pinning Package Versions in For consistent and reproducible builds, consider pinning the versions of the installed packages. Example: -RUN apk add --no-cache libc6-compat openssl
+RUN apk add --no-cache \
+ libc6-compat=1.2.3-r0 \
+ openssl=1.1.1k-r0 Ensure the versions match the required dependencies for your application.
🧰 Tools🪛 Hadolint (2.12.0)[warning] 6-6: Pin versions in apk add. Instead of (DL3018) |
||
RUN apk update | ||
|
||
# Set pnpm | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,61 +1,57 @@ | ||||||||||||||||||||
FROM node:20-alpine AS base | ||||||||||||||||||||
ENV PNPM_HOME="/pnpm" | ||||||||||||||||||||
ENV PATH="$PNPM_HOME:$PATH" | ||||||||||||||||||||
RUN apk add --no-cache libc6-compat && \ | ||||||||||||||||||||
corepack enable | ||||||||||||||||||||
# Alpine image | ||||||||||||||||||||
FROM node:20-alpine3.21 AS alpine | ||||||||||||||||||||
RUN apk update | ||||||||||||||||||||
RUN apk add --no-cache libc6-compat openssl | ||||||||||||||||||||
|
||||||||||||||||||||
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. 🧹 Nitpick (assertive) Consider Pinning Package Versions in Pinning specific package versions ensures reproducibility and consistency across builds. This helps prevent unexpected behavior due to upstream changes. Example: RUN apk update && apk add --no-cache \
- libc6-compat openssl
+ libc6-compat=1.2.3-r0 openssl=1.1.1k-r0 Replace
🧰 Tools🪛 Hadolint (2.12.0)[warning] 4-4: Pin versions in apk add. Instead of (DL3018) [info] 4-4: Multiple consecutive (DL3059)
Comment on lines
+2
to
+4
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. 🧹 Nitpick (assertive) Consolidate Combining consecutive Apply this diff to consolidate the commands: FROM node:20-alpine3.21 AS alpine
-RUN apk update
-RUN apk add --no-cache libc6-compat openssl
+RUN apk update && apk add --no-cache libc6-compat openssl 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Hadolint (2.12.0)[warning] 4-4: Pin versions in apk add. Instead of (DL3018) [info] 4-4: Multiple consecutive (DL3059) |
||||||||||||||||||||
WORKDIR /app | ||||||||||||||||||||
# Setup pnpm and turbo on the alpine base | ||||||||||||||||||||
FROM alpine as base | ||||||||||||||||||||
RUN npm install pnpm turbo --global | ||||||||||||||||||||
RUN pnpm config set store-dir ~/.pnpm-store | ||||||||||||||||||||
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. 🧹 Nitpick (assertive) Pin Versions When Installing Global NPM Packages To ensure consistent builds and avoid potential issues due to updated package versions, consider pinning the versions of Example: -RUN npm install pnpm turbo --global
+RUN npm install [email protected] [email protected] --global Ensure that
🧰 Tools🪛 Hadolint (2.12.0)[warning] 8-8: Pin versions in npm. Instead of (DL3016) |
||||||||||||||||||||
|
||||||||||||||||||||
Comment on lines
+8
to
+9
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. 🧹 Nitpick (assertive) Consolidate Similarly, combining these Apply this diff: -RUN npm install pnpm turbo --global
-RUN pnpm config set store-dir ~/.pnpm-store
+RUN npm install pnpm turbo --global && pnpm config set store-dir ~/.pnpm-store 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Hadolint (2.12.0)[warning] 8-8: Pin versions in npm. Instead of (DL3016) [info] 9-9: Multiple consecutive (DL3059) |
||||||||||||||||||||
# Install Turbo | ||||||||||||||||||||
RUN pnpm add -g [email protected] | ||||||||||||||||||||
# Prune projects | ||||||||||||||||||||
FROM base AS pruner | ||||||||||||||||||||
ARG PROJECT | ||||||||||||||||||||
|
||||||||||||||||||||
# Copy necessary files for turbo prune | ||||||||||||||||||||
WORKDIR /app | ||||||||||||||||||||
COPY . . | ||||||||||||||||||||
|
||||||||||||||||||||
# Prune the workspace | ||||||||||||||||||||
RUN turbo prune --scope=webapp --docker | ||||||||||||||||||||
|
||||||||||||||||||||
# Installer stage | ||||||||||||||||||||
FROM base AS installer | ||||||||||||||||||||
# Build the project | ||||||||||||||||||||
FROM base AS builder | ||||||||||||||||||||
ARG PROJECT | ||||||||||||||||||||
|
||||||||||||||||||||
WORKDIR /app | ||||||||||||||||||||
|
||||||||||||||||||||
# Copy pruned files | ||||||||||||||||||||
COPY --from=base /app/out/json/ . | ||||||||||||||||||||
COPY --from=base /app/out/pnpm-lock.yaml ./pnpm-lock.yaml | ||||||||||||||||||||
COPY --from=base /app/out/full/ . | ||||||||||||||||||||
# Copy lockfile and package.json's of isolated subworkspace | ||||||||||||||||||||
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml | ||||||||||||||||||||
COPY --from=pruner /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml | ||||||||||||||||||||
COPY --from=pruner /app/out/json/ . | ||||||||||||||||||||
|
||||||||||||||||||||
# Install dependencies | ||||||||||||||||||||
RUN pnpm install --shamefully-hoist | ||||||||||||||||||||
# First install the dependencies (as they change less often) | ||||||||||||||||||||
RUN --mount=type=cache,id=pnpm,target=~/.pnpm-store pnpm install --frozen-lockfile | ||||||||||||||||||||
|
||||||||||||||||||||
# Build shared package first | ||||||||||||||||||||
RUN cd packages/shared && pnpm run build | ||||||||||||||||||||
# Copy source code of isolated subworkspace | ||||||||||||||||||||
COPY --from=pruner /app/out/full/ . | ||||||||||||||||||||
|
||||||||||||||||||||
# Build the webapp | ||||||||||||||||||||
RUN pnpm run build --filter=webapp... | ||||||||||||||||||||
RUN turbo build --filter=webapp | ||||||||||||||||||||
RUN --mount=type=cache,id=pnpm,target=~/.pnpm-store pnpm prune --prod --no-optional | ||||||||||||||||||||
RUN rm -rf ./**/*/src | ||||||||||||||||||||
|
||||||||||||||||||||
# Runner stage | ||||||||||||||||||||
FROM node:20-alpine AS runner | ||||||||||||||||||||
WORKDIR /app | ||||||||||||||||||||
# Final image | ||||||||||||||||||||
FROM alpine AS runner | ||||||||||||||||||||
ARG PROJECT | ||||||||||||||||||||
|
||||||||||||||||||||
# Don't run production as root | ||||||||||||||||||||
RUN addgroup --system --gid 1001 nodejs | ||||||||||||||||||||
RUN adduser --system --uid 1001 nextjs | ||||||||||||||||||||
|
||||||||||||||||||||
# Copy necessary files | ||||||||||||||||||||
COPY --from=installer /app/apps/webapp/.next/standalone ./ | ||||||||||||||||||||
COPY --from=installer /app/apps/webapp/.next/static ./apps/webapp/.next/static | ||||||||||||||||||||
COPY --from=installer /app/apps/webapp/public ./apps/webapp/public | ||||||||||||||||||||
RUN adduser --system --uid 1001 nodejs | ||||||||||||||||||||
USER nodejs | ||||||||||||||||||||
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. 🧹 Nitpick (assertive) Consolidate Combining these Apply this diff: -RUN addgroup --system --gid 1001 nodejs
-RUN adduser --system --uid 1001 nodejs
+RUN addgroup --system --gid 1001 nodejs && \
+ adduser --system --uid 1001 nodejs
🧰 Tools🪛 Hadolint (2.12.0)[info] 45-45: Multiple consecutive (DL3059) |
||||||||||||||||||||
|
||||||||||||||||||||
# Copy package.json files | ||||||||||||||||||||
COPY --from=installer /app/apps/webapp/package.json ./package.json | ||||||||||||||||||||
|
||||||||||||||||||||
# Install only production dependencies | ||||||||||||||||||||
|
||||||||||||||||||||
USER nextjs | ||||||||||||||||||||
WORKDIR /app | ||||||||||||||||||||
COPY --from=builder --chown=nodejs:nodejs /app . | ||||||||||||||||||||
WORKDIR /app/apps/webapp | ||||||||||||||||||||
|
||||||||||||||||||||
ENV NODE_ENV=production | ||||||||||||||||||||
ARG PORT=8080 | ||||||||||||||||||||
ENV PORT=8090 | ||||||||||||||||||||
|
||||||||||||||||||||
ENV NODE_ENV=production | ||||||||||||||||||||
EXPOSE 8090 | ||||||||||||||||||||
|
||||||||||||||||||||
Comment on lines
+52
to
55
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. Ensure Consistent Port Configuration There is a mismatch between the Consider aligning the port configurations: -ARG PORT=8080
-ENV PORT=8090
-ENV NODE_ENV=production
-EXPOSE 8090
+ARG PORT=8080
+ENV PORT=$PORT
+ENV NODE_ENV=production
+EXPOSE $PORT This change ensures that the port can be configured externally and remains consistent throughout the container setup. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||
CMD ["node", "server.js"] | ||||||||||||||||||||
CMD node dist/main | ||||||||||||||||||||
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. 🧹 Nitpick (assertive) Use JSON Array Syntax for Using JSON array syntax ensures that the command and its arguments are passed correctly without invoking a shell, which can prevent potential issues with argument parsing. Apply this diff: -CMD node dist/main
+CMD ["node", "dist/main"] 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Hadolint (2.12.0)[warning] 57-57: Use arguments JSON notation for CMD and ENTRYPOINT arguments (DL3025) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# run directly from the repo root directory | ||
# docker build -f ./packages/api/Dockerfile . | ||
FROM node:20-alpine AS base | ||
FROM node:20-alpine3.21 AS base | ||
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. 🧹 Nitpick (assertive) LGTM! Consistent base image update and package additions. The changes appropriately mirror the webapp Dockerfile changes and include OpenSSL in all stages, including the runner stage. Consider pinning package versions for better reproducibility: -RUN apk add --no-cache libc6-compat openssl
+RUN apk add --no-cache libc6-compat=1.2.4-r2 openssl=3.1.4-r2
# For runner stage
-RUN apk add --no-cache libc6-compat netcat-openbsd curl openssl
+RUN apk add --no-cache libc6-compat=1.2.4-r2 netcat-openbsd=1.130-r4 curl=8.5.0-r0 openssl=3.1.4-r2 Also applies to: 6-6, 22-22, 45-45 |
||
# ======================================================================= | ||
FROM base AS builder | ||
RUN apk add --no-cache libc6-compat | ||
RUN apk add --no-cache libc6-compat openssl | ||
RUN apk update | ||
|
||
# Set pnpm | ||
|
@@ -19,7 +19,7 @@ RUN turbo prune api --docker | |
# ======================================================================= | ||
# Add lockfile and package.json's of isolated subworkspace | ||
FROM base AS installer | ||
RUN apk add --no-cache libc6-compat | ||
RUN apk add --no-cache libc6-compat openssl | ||
RUN apk update | ||
# Set pnpm | ||
ENV PNPM_HOME="/pnpm" | ||
|
@@ -42,7 +42,7 @@ RUN pnpm run build | |
|
||
# ======================================================================== | ||
FROM base AS runner | ||
RUN apk add --no-cache libc6-compat netcat-openbsd curl | ||
RUN apk add --no-cache libc6-compat netcat-openbsd curl openssl | ||
|
||
WORKDIR /app | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# run directly from the repo root directory | ||
# docker build -f ./packages/api/Dockerfile.dev . | ||
FROM node:20-alpine AS base | ||
FROM node:20-alpine3.21 AS base | ||
# ======================================================================= | ||
FROM base AS builder | ||
RUN apk add --no-cache libc6-compat netcat-openbsd curl | ||
RUN apk add --no-cache libc6-compat netcat-openbsd curl openssl | ||
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. 🧹 Nitpick (assertive) Consider Pinning Versions in Pinning package versions enhances build consistency and reproducibility. Example: -RUN apk add --no-cache libc6-compat netcat-openbsd curl openssl
+RUN apk add --no-cache \
+ libc6-compat=1.2.3-r0 \
+ netcat-openbsd=1.130-r0 \
+ curl=7.78.0-r0 \
+ openssl=1.1.1k-r0 Replace the version numbers with the desired versions based on your project's requirements.
🧰 Tools🪛 Hadolint (2.12.0)[warning] 6-6: Pin versions in apk add. Instead of (DL3018) |
||
RUN apk update | ||
|
||
# Set pnpm | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,11 @@ | |
# 3/ run with: docker run -v $(pwd):/app/ package_builder | ||
################################################ | ||
|
||
FROM node:20-alpine AS base | ||
FROM node:20-alpine3.21 AS base | ||
|
||
# ======================================================================= | ||
FROM base AS builder | ||
RUN apk add --no-cache libc6-compat netcat-openbsd curl | ||
RUN apk add --no-cache libc6-compat netcat-openbsd curl openssl | ||
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. 🧹 Nitpick (assertive) Consider pinning package versions for better reproducibility. While adding -RUN apk add --no-cache libc6-compat netcat-openbsd curl openssl
+RUN apk add --no-cache \
+ libc6-compat=1.2.4-r2 \
+ netcat-openbsd=1.130-r5 \
+ curl=8.5.0-r0 \
+ openssl=3.1.4-r5
🧰 Tools🪛 Hadolint (2.12.0)[warning] 11-11: Pin versions in apk add. Instead of (DL3018) |
||
RUN apk update | ||
|
||
# Set pnpm | ||
|
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.
🧹 Nitpick (assertive)
LGTM! Base image update and OpenSSL addition.
The changes appropriately address the OpenSSL dependency issue by:
Consider pinning package versions for better reproducibility:
Also applies to: 7-7, 26-26