Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
FROM oven/bun AS build
FROM oven/bun:alpine AS build

WORKDIR /app

# Cache packages installation
COPY package.json package.json
COPY bun.lock bun.lock
COPY package.json bun.lock ./

RUN bun install
# Install dependencies
RUN bun install --frozen-lockfile

# Copy source files
COPY ./src ./src
COPY ./prisma ./prisma
COPY ./tsconfig.json tsconfig.json
COPY ./tsconfig.json ./

ENV NODE_ENV=production

Expand All @@ -25,14 +26,26 @@ RUN bun build \
--outfile server \
./src/index.ts

FROM alpine AS curl-downloader
RUN apk add --no-cache curl

FROM gcr.io/distroless/base

WORKDIR /app

# Copy the compiled binaries
COPY --from=build /app/server server
COPY --from=curl-downloader /usr/bin/curl /usr/bin/curl

Comment on lines +29 to +39

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Alpine-built curl is very likely to seg-fault in the Debian-based distroless image

apk add --no-cache curl produces a musl-linked binary /usr/bin/curl.
The final stage (gcr.io/distroless/base) is glibc-based and does not ship the musl
loader (/lib/ld-musl-x86_64.so.1) or any musl libraries, so the copied binary
will fail at runtime and the HEALTHCHECK will be reported as unhealthy.

Diff-style fix (one option):

-FROM alpine AS curl-downloader
-RUN apk add --no-cache curl
+FROM debian:stable-slim AS curl-downloader
+RUN apt-get update \
+    && apt-get install -y --no-install-recommends curl ca-certificates \
+    && rm -rf /var/lib/apt/lists/*

or simply switch the runtime image to oven/bun:alpine and drop the extra
stage altogether.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
FROM alpine AS curl-downloader
RUN apk add --no-cache curl
FROM gcr.io/distroless/base
WORKDIR /app
# Copy the compiled binaries
COPY --from=build /app/server server
COPY --from=curl-downloader /usr/bin/curl /usr/bin/curl
FROM debian:stable-slim AS curl-downloader
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl ca-certificates \
&& rm -rf /var/lib/apt/lists/*
FROM gcr.io/distroless/base
WORKDIR /app
# Copy the compiled binaries
COPY --from=build /app/server server
COPY --from=curl-downloader /usr/bin/curl /usr/bin/curl
🤖 Prompt for AI Agents
In Dockerfile lines 29 to 39, the curl binary built with Alpine's musl libc is
copied into a glibc-based distroless image, causing runtime segfaults due to
missing musl libraries. To fix this, either build curl in a Debian-based image
compatible with the distroless base or switch the final runtime image to an
Alpine-based image like oven/bun:alpine to ensure libc compatibility and remove
the need for the extra curl-downloader stage.

# Ensure the binary is executable
USER nonroot:nonroot

ENV NODE_ENV=production

CMD ["./server"]
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD ["/usr/bin/curl", "-f", "http://localhost:3000/health"]

EXPOSE 3000

EXPOSE 3000
CMD ["./server"]