diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 824a652..1bac1c7 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -25,8 +25,13 @@ jobs: uses: actions/checkout@v4 - name: Build & push image + # The runner builds on the Pi5 next to live services. BUILD_CPUS caps the + # CPU-heavy build tools (Go compiler + esbuild) to 2 of 4 cores so the box + # stays responsive; nice/ionice further deprioritise the client-side work. + # Slower build, but nginx/NPM and the other containers keep serving. run: | - docker build --progress=plain \ + nice -n 19 ionice -c 3 docker build --progress=plain \ + --build-arg BUILD_CPUS=2 \ -f docker/Dockerfile \ -t localhost:5000/archivum:latest \ -t "localhost:5000/archivum:${GITHUB_SHA::12}" \ diff --git a/docker/Dockerfile b/docker/Dockerfile index 3b832f6..52d49c1 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,14 @@ +# CPU budget for the build. The self-hosted runner builds on the Raspberry Pi 5 +# (4 cores) alongside live services, so we cap the CPU-heavy tools (the Go +# compiler and esbuild — both honour GOMAXPROCS) to leave cores for nginx/NPM +# and the other containers. Lower = gentler but slower; raise for a faster box. +ARG BUILD_CPUS=2 + # ── Stage 1: Build frontend ─────────────────────────────────────────────────── FROM node:20-alpine AS frontend-builder +ARG BUILD_CPUS +# esbuild (used by Vite) is a Go program and respects GOMAXPROCS. +ENV GOMAXPROCS=${BUILD_CPUS} WORKDIR /app/frontend COPY frontend/package*.json ./ @@ -10,6 +19,9 @@ RUN npm run build # ── Stage 2: Build backend ──────────────────────────────────────────────────── # Go 1.25 required by the OIDC dependency chain (go-oidc/v3, go-jose/v4). FROM golang:1.25-alpine AS backend-builder +ARG BUILD_CPUS +# Cap the Go compiler's parallelism to keep the Pi responsive during CI. +ENV GOMAXPROCS=${BUILD_CPUS} WORKDIR /app/backend # Copy go.mod first for layer caching. go.sum is written by go mod download @@ -18,8 +30,8 @@ COPY backend/go.mod ./ COPY backend/go.su[m] ./ RUN go mod download -x COPY backend/ ./ -# CGO disabled — pure Go SQLite (modernc.org/sqlite). -RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /archivum ./cmd/server +# CGO disabled — pure Go SQLite (modernc.org/sqlite). -p limits parallel builds. +RUN CGO_ENABLED=0 go build -p ${BUILD_CPUS} -ldflags="-s -w" -o /archivum ./cmd/server # ── Stage 3: Runtime image ──────────────────────────────────────────────────── FROM alpine:3.20