Skip to content

Commit 13f0ac3

Browse files
authored
feat: add healthchecks to Dockerfiles for api, basket, links, and uptime services (#380)
1 parent 594f922 commit 13f0ac3

5 files changed

Lines changed: 30 additions & 3 deletions

File tree

api.Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,10 @@ EXPOSE 3001
3232

3333
WORKDIR /app/apps/api
3434

35+
COPY healthcheck.ts /app/healthcheck.ts
36+
ENV HEALTHCHECK_PORT=3001
37+
38+
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
39+
CMD ["bun", "/app/healthcheck.ts"]
40+
3541
CMD ["bun", "run", "src/index.ts"]

basket.Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@ RUN bun build \
2727
--bytecode \
2828
./src/index.ts
2929

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

3232
WORKDIR /app
3333

3434
COPY --from=build /app/server server
35+
COPY healthcheck.ts healthcheck.ts
3536

3637
ENV NODE_ENV=production
38+
ENV HEALTHCHECK_PORT=4000
3739

40+
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
41+
CMD ["bun", "/app/healthcheck.ts"]
42+
43+
ENTRYPOINT []
3844
CMD ["./server"]
3945

4046
EXPOSE 4000

healthcheck.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const port = process.env.HEALTHCHECK_PORT ?? process.env.PORT ?? "3000";
2+
const r = await fetch(`http://localhost:${port}/health`);
3+
process.exit(r.ok ? 0 : 1);

links.Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,20 @@ RUN bun build \
2828
--bytecode \
2929
./src/index.ts
3030

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

3333
WORKDIR /app
3434

3535
COPY --from=build /app/server server
36+
COPY healthcheck.ts healthcheck.ts
3637

3738
ENV NODE_ENV=production
39+
ENV HEALTHCHECK_PORT=2500
3840

41+
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
42+
CMD ["bun", "/app/healthcheck.ts"]
43+
44+
ENTRYPOINT []
3945
CMD ["./server"]
4046

4147
EXPOSE 2500

uptime.Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,20 @@ RUN bun build \
2323
--bytecode \
2424
./apps/uptime/src/index.ts
2525

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

2828
WORKDIR /app
2929

3030
COPY --from=build /app/server server
31+
COPY healthcheck.ts healthcheck.ts
3132

3233
ENV NODE_ENV=production
34+
ENV HEALTHCHECK_PORT=4000
3335

36+
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
37+
CMD ["bun", "/app/healthcheck.ts"]
38+
39+
ENTRYPOINT []
3440
CMD ["./server"]
3541

3642
EXPOSE 4000

0 commit comments

Comments
 (0)