From ba1427e9ea0772c5fdd5835c0cf6e0d1b4266ca2 Mon Sep 17 00:00:00 2001 From: sekhar08 Date: Sat, 4 Apr 2026 02:11:48 +0530 Subject: [PATCH] feat: add healthchecks to Dockerfiles for api, basket, links, and uptime services --- api.Dockerfile | 6 ++++++ basket.Dockerfile | 8 +++++++- healthcheck.ts | 3 +++ links.Dockerfile | 8 +++++++- uptime.Dockerfile | 8 +++++++- 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 healthcheck.ts diff --git a/api.Dockerfile b/api.Dockerfile index a38edc742..934c7adc2 100644 --- a/api.Dockerfile +++ b/api.Dockerfile @@ -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"] diff --git a/basket.Dockerfile b/basket.Dockerfile index a0d91c00e..474dfa578 100644 --- a/basket.Dockerfile +++ b/basket.Dockerfile @@ -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"] EXPOSE 4000 \ No newline at end of file diff --git a/healthcheck.ts b/healthcheck.ts new file mode 100644 index 000000000..75b6b8600 --- /dev/null +++ b/healthcheck.ts @@ -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); diff --git a/links.Dockerfile b/links.Dockerfile index 9c3f527c0..ed8a8fa28 100644 --- a/links.Dockerfile +++ b/links.Dockerfile @@ -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 diff --git a/uptime.Dockerfile b/uptime.Dockerfile index 74926f7a5..d6e46437d 100644 --- a/uptime.Dockerfile +++ b/uptime.Dockerfile @@ -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 \ No newline at end of file