feat: build a debug-shell and distroless container

This commit is contained in:
Aarnav Tale
2025-06-24 10:56:43 -04:00
parent 5a254b746b
commit eed12d348e
5 changed files with 73 additions and 9 deletions
+23 -5
View File
@@ -1,5 +1,5 @@
FROM --platform=$BUILDPLATFORM jdxcode/mise:latest AS mise-context
COPY mise.toml .
COPY mise.toml .tool-versions ./
RUN mise install
FROM --platform=$BUILDPLATFORM mise-context AS go-build
@@ -13,11 +13,13 @@ COPY internal/ ./internal/
ARG TARGETOS
ARG TARGETARCH
ARG IMAGE_TAG
RUN mkdir -p /build/app/ && \
GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 \
mise run wasm ::: agent
GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 IMAGE_TAG=$IMAGE_TAG \
mise run wasm ::: agent ::: fake-shell
RUN chmod +x /build/build/hp_agent
RUN chmod +x /build/build/sh
FROM --platform=$BUILDPLATFORM mise-context AS js-build
WORKDIR /build
@@ -32,7 +34,23 @@ COPY --from=go-build /build/app/wasm_exec.js /build/app/wasm_exec.js
RUN pnpm run build
RUN mkdir -p /var/lib/headplane/agent
FROM gcr.io/distroless/nodejs22-debian12:nonroot
FROM gcr.io/distroless/nodejs22-debian12:nonroot AS final
COPY --from=js-build --chown=nonroot:nonroot /build/build/ /app/build/
COPY --from=js-build --chown=nonroot:nonroot /build/drizzle /app/drizzle/
COPY --from=js-build --chown=nonroot:nonroot /var/lib/headplane /var/lib/headplane
COPY --from=js-build --chown=nonroot:nonroot /build/node_modules/ /app/node_modules/
COPY --from=go-build --chown=nonroot:nonroot /build/build/hp_agent /usr/libexec/headplane/agent
# Fake shell to inform the user that they should use the debug image
COPY --from=go-build --chown=nonroot:nonroot /build/build/sh /bin/sh
COPY --from=go-build --chown=nonroot:nonroot /build/build/sh /bin/bash
WORKDIR /app
CMD [ "/app/build/server/index.js" ]
FROM node:22-alpine AS debug-shell
RUN apk add --no-cache bash curl git
COPY --from=js-build --chown=nonroot:nonroot /build/build/ /app/build/
COPY --from=js-build --chown=nonroot:nonroot /build/drizzle /app/drizzle/
COPY --from=js-build --chown=nonroot:nonroot /var/lib/headplane /var/lib/headplane
@@ -40,4 +58,4 @@ COPY --from=js-build --chown=nonroot:nonroot /build/node_modules/ /app/node_modu
COPY --from=go-build --chown=nonroot:nonroot /build/build/hp_agent /usr/libexec/headplane/agent
WORKDIR /app
CMD [ "/app/build/server/index.js" ]
CMD [ "node", "/app/build/server/index.js" ]