1111# Based on: cybertec-postgresql/pgwatch v3.7.0
1212
1313# ---- Stage 1: build WebUI ----
14- FROM node:22 AS uibuilder
14+ # Pin to BUILDPLATFORM so the WebUI build (yarn install + react-scripts build)
15+ # runs on the runner's native arch. The output is static JS/CSS/HTML — fully
16+ # arch-independent — so a single build serves both linux/amd64 and linux/arm64
17+ # final images. Without this, `docker buildx --platform linux/amd64,linux/arm64`
18+ # would run the WebUI build under QEMU emulation for arm64, taking 30+ min and
19+ # overrunning the GitLab runner's 1h job timeout.
20+ FROM --platform=$BUILDPLATFORM node:22 AS uibuilder
1521
1622# Pin to the exact commit SHA of the v3.7.0 tag in upstream. Tags are
1723# mutable (force-push etc.), so we verify the checkout resolves to this SHA
@@ -28,7 +34,13 @@ RUN git clone --depth 1 --branch "${PGWATCH_VERSION}" \
2834RUN cd /src/internal/webui && yarn install --network-timeout 100000 && yarn build
2935
3036# ---- Stage 2: patch & build Go binary ----
31- FROM golang:1.24 AS builder
37+ # Pin to BUILDPLATFORM and use Go's native cross-compilation via GOOS/GOARCH
38+ # (BuildKit injects TARGETOS/TARGETARCH from the --platform flag). Cgo is
39+ # already disabled below, so cross-compile produces a working static binary
40+ # in seconds for any target arch — no QEMU, no toolchain setup.
41+ FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
42+ ARG TARGETOS
43+ ARG TARGETARCH
3244
3345COPY --from=uibuilder /src /pgwatch
3446COPY --from=uibuilder /src/internal/webui/build /pgwatch/internal/webui/build
@@ -44,7 +56,7 @@ RUN grep -q 'return fmt.Errorf("unexpected extension %s version input: %s", ext,
4456RUN sed -i 's|return fmt.Errorf("unexpected extension %s version input: %s", ext, ver)|return nil /* skip unparseable extension version */|' \
4557 /pgwatch/internal/sources/conn.go
4658
47- RUN cd /pgwatch && CGO_ENABLED=0 go build \
59+ RUN cd /pgwatch && CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build \
4860 -ldflags "-X 'main.version=3.7.0-patched'" \
4961 ./cmd/pgwatch
5062
0 commit comments