Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions api.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ EXPOSE 3001

WORKDIR /app/apps/api

COPY healthcheck.ts /app/healthcheck.ts
ENV HEALTHCHECK_PORT=3001

HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD ["bun", "/app/healthcheck.ts"]

CMD ["bun", "run", "src/index.ts"]
8 changes: 7 additions & 1 deletion basket.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,20 @@ RUN bun build \
--bytecode \
./src/index.ts

FROM gcr.io/distroless/cc
FROM oven/bun:1.3.4-distroless

WORKDIR /app

COPY --from=build /app/server server
COPY healthcheck.ts healthcheck.ts

ENV NODE_ENV=production
ENV HEALTHCHECK_PORT=4000

HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD ["bun", "/app/healthcheck.ts"]

ENTRYPOINT []
CMD ["./server"]
Comment on lines +40 to 44
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 ENTRYPOINT [] placed after HEALTHCHECK

Convention is to declare ENTRYPOINT before HEALTHCHECK (and CMD) so the intended runtime contract is clear before the health probe is defined. Docker processes these as a final metadata set so this doesn't break anything, but the ordering is slightly unexpected for readers.

The same ordering applies to links.Dockerfile and uptime.Dockerfile.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


EXPOSE 4000
3 changes: 3 additions & 0 deletions healthcheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const port = process.env.HEALTHCHECK_PORT ?? process.env.PORT ?? "3000";
const r = await fetch(`http://localhost:${port}/health`);
process.exit(r.ok ? 0 : 1);
Comment on lines +2 to +3
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Missing error handling on fetch

fetch() can throw a network-level error (e.g., ECONNREFUSED) if the service is not yet listening. In Bun, an unhandled promise rejection does cause a non-zero exit code so the healthcheck will still be marked unhealthy — but this relies on runtime implementation details rather than explicit intent, and the error won't be surfaced in Docker logs.

A try/catch makes the failure mode explicit:

Suggested change
const r = await fetch(`http://localhost:${port}/health`);
process.exit(r.ok ? 0 : 1);
try {
const r = await fetch(`http://localhost:${port}/health`);
process.exit(r.ok ? 0 : 1);
} catch {
process.exit(1);
}

8 changes: 7 additions & 1 deletion links.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@ RUN bun build \
--bytecode \
./src/index.ts

FROM gcr.io/distroless/base
FROM oven/bun:1.3.4-distroless

WORKDIR /app

COPY --from=build /app/server server
COPY healthcheck.ts healthcheck.ts

ENV NODE_ENV=production
ENV HEALTHCHECK_PORT=2500

HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD ["bun", "/app/healthcheck.ts"]

ENTRYPOINT []
CMD ["./server"]

EXPOSE 2500
8 changes: 7 additions & 1 deletion uptime.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ RUN bun build \
--bytecode \
./apps/uptime/src/index.ts

FROM gcr.io/distroless/base
FROM oven/bun:1.3.4-distroless

WORKDIR /app

COPY --from=build /app/server server
COPY healthcheck.ts healthcheck.ts

ENV NODE_ENV=production
ENV HEALTHCHECK_PORT=4000

HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD ["bun", "/app/healthcheck.ts"]

ENTRYPOINT []
CMD ["./server"]

EXPOSE 4000
Loading