From 50e636693c51c01792b8b59aad053d873c9d393d Mon Sep 17 00:00:00 2001 From: Sudo-Ivan Date: Sat, 27 Dec 2025 11:27:23 -0600 Subject: [PATCH] Add Dockerfile for multi-stage build process - Introduced a Dockerfile that implements a multi-stage build process for the application. - The first stage builds the frontend using Node.js and pnpm. - The second stage compiles the Go binary with embedded frontend assets. - The final stage creates a minimal runtime image, setting up necessary environment variables and exposing the application on port 8080. --- Dockerfile | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..183a905 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,48 @@ +# Stage 1: Build the frontend +FROM cgr.dev/chainguard/node:latest-dev AS node-builder +WORKDIR /app + +USER root +RUN npm install -g pnpm +USER node + +COPY --chown=node:node frontend/package.json frontend/pnpm-lock.yaml ./frontend/ +WORKDIR /app/frontend +RUN pnpm install --frozen-lockfile + +COPY --chown=node:node frontend/ ./ +RUN pnpm run build + +# Stage 2: Build the Go binary with embedded assets +FROM cgr.dev/chainguard/go:latest-dev AS go-builder +WORKDIR /app +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +COPY --from=node-builder /app/frontend/build ./frontend/build +RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o software-station main.go + +# Stage 3: Minimal runtime image +FROM cgr.dev/chainguard/wolfi-base:latest +WORKDIR /app + +RUN apk add --no-cache ca-certificates + +COPY --from=go-builder /app/software-station . + +COPY legal/ ./legal/ + +COPY software.txt /app/data/software.txt +COPY ua-blocklist.txt /app/data/ua-blocklist.txt + +RUN mkdir -p /app/data /app/.cache && chown -R 65532:65532 /app/data /app/.cache + +EXPOSE 8080 +ENV PORT=8080 +ENV NODE_ENV=production +ENV CONFIG_PATH=/app/data/software.txt +ENV UA_BLOCKLIST_PATH=/app/data/ua-blocklist.txt + +USER 65532 + +CMD ["sh", "-c", "./software-station -c ${CONFIG_PATH} -ua-blocklist ${UA_BLOCKLIST_PATH}"]