Skip to content

build: cross-compile multi-arch image and run as non-root - #94

Merged
raeperd merged 7 commits into
mainfrom
fix/dockerfile-review
Nov 9, 2026
Merged

raeperd merged 7 commits into
mainfrom
fix/dockerfile-review

Conversation

@raeperd

@raeperd raeperd commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Part 2 of 3 of the repository review. This PR only touches Dockerfile and the build flags in Makefile. Go sources and .github workflows are handled in separate PRs.

Net change: Dockerfile +2 lines, Makefile one flag. No new stages, ENV, or files.

Changes

  • Match AS casing with FROM – removes the BuildKit FromAsCasing warning on line 1.
  • Run as non-root – USER 65534:65534 on the scratch stage. A numeric uid:gid needs no /etc/passwd, so the image stays at scratch size and the .git copy that feeds lastCommitHash / dirtyBuild via VCS stamping is unchanged.
  • Cross-compile instead of emulating – the builder runs on $BUILDPLATFORM and sets GOARCH=$TARGETARCH. GOOS is left alone: the builder is always a Linux image, so TARGETOS would be redundant. Multi-arch builds no longer compile Go under QEMU.
  • -ldflags '-s -w' – also strips the symbol table. -X main.Version is a link-time string injection and is unaffected; /health still reports version.

A .dockerignore was added and then removed in this branch. With a stale local app and coverage.txt in the build context (7.06MB), the image is identical in size, dirtyBuild stays false (both files are gitignored), and make build overwrites app in the builder. CI builds from a fresh checkout that has neither file.

Measurements (OrbStack, Docker 29.4, buildx 0.33)

main this branch
docker build warnings 1 (FromAsCasing) 0
Image size (arm64) 15.6MB 14.9MB
Container user root 65534:65534 (nobody)
buildx --platform linux/arm64,linux/amd64 --no-cache 27.97s 8.84s
Local binary (-w → -s -w) 7,555,122 B 7,040,146 B
  • /health on the arm64 image: {"version":"local","lastCommitHash":"4f302b85…","dirtyBuild":false}
  • amd64 image run with --platform linux/amd64 returns the same /health shape; file on the extracted binary: ELF 64-bit x86-64, statically linked, stripped.
  • make build, make test, make lint pass locally.

@coveralls

coveralls commented Nov 4, 2026 •

Copy link
Copy Markdown

Coverage Status

Coverage is 88.608% — fix/dockerfile-review into main. No base build found for main.

@raeperd raeperd changed the title build: harden Dockerfile and cross-compile multi-arch image build: cross-compile multi-arch image and run as non-root Nov 4, 2026
@raeperd
raeperd marked this pull request as ready for review November 9, 2026 14:59
@raeperd
raeperd merged commit 3653552 into main Nov 9, 2026
3 checks passed
@raeperd
raeperd deleted the fix/dockerfile-review branch November 9, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants