fix(docker): multi-arch image build (amd64+arm64) -- closes #223#445
fix(docker): multi-arch image build (amd64+arm64) -- closes #223#445TheAuditorTool wants to merge 1 commit intoOWASP-Benchmark:masterfrom
Conversation
…chmark#223 The published Docker image was linux/arm64 only because it was built on an ARM64 host. This caused >60s startup via QEMU emulation on amd64, breaking downstream CI (ZAP scans). Changes: - VMs/buildDockerImage.sh: rewrite to use docker buildx with --platform linux/amd64,linux/arm64 for multi-arch manifest - VMs/Dockerfile: pin ubuntu:22.04, collapse RUN layers, add EXPOSE 8443 and CMD for usability - .github/workflows/docker-publish.yml: add CI workflow for automated multi-arch builds (workflow_dispatch only -- inactive until secrets and triggers are configured) - PR_multi-arch-docker.md: changelog, guide, and activation steps
| @@ -1,44 +1,45 @@ | |||
| # This dockerfile builds a container that pulls down and runs the latest version of BenchmarkJava | |||
| FROM ubuntu:latest | |||
| FROM ubuntu:22.04 | |||
There was a problem hiding this comment.
Shouldn't this simply be latest, like it was previously?
There was a problem hiding this comment.
Shouldn't this simply be latest, like it was previously?
It can be, if you want it to be.
But its not standard.
Using latest is generally considered an anti-pattern for Docker builds, especially for benchmarks where reproducibility is critical. latest is a moving target, when Ubuntu rolls its LTS version forward (like updating latest from 22.04 to 24.04), it silently changes underlying system libraries, apt packages, and default Java/Python versions, which often breaks the build overnight.
Pinning it to 22.04 guarantees the environment builds exactly the same way every time. That said, if you strongly prefer it to track the bleeding edge and don't mind the occasional upstream breakage, I'm happy to change it back to latest! Let me know what you prefer.
The published Docker image was linux/arm64 only because it was built on an ARM64 host. This caused >60s startup via QEMU emulation on amd64, breaking downstream CI (ZAP scans).
Changes:
Summary
The published
owasp/benchmark:latestDocker image was built on an ARM64 host,making it linux/arm64 only. On amd64 machines (the vast majority of CI runners
and developer workstations), Docker falls back to QEMU emulation, causing
startup times over 60 seconds -- long enough to break downstream CI (e.g., ZAP
scans reported in #223).
This PR switches the build tooling from
docker buildtodocker buildx buildwith
--platform linux/amd64,linux/arm64. Docker Hub receives a single manifestlist that serves the native image for each architecture automatically.
What Changed
VMs/DockerfileFROM ubuntu:latest->FROM ubuntu:22.04latestsilently rolls forward and has caused breakage before.RUN apt-getlayers into 1RUNalso ensuresapt-get updateandinstallshare the same cache.rm -rf /var/lib/apt/lists/*RUNRUNuseradd+chpasswdinto 1RUNEXPOSE 8443CMD ["./runBenchmark.sh"]useraddlineVMs/buildDockerImage.shComplete rewrite. The old script ran
docker build -t benchmark .whichproduces a single-architecture image matching the build host.
The new script:
docker buildxbuilder instance namedbenchmark-multiarch.docker buildx build --platform linux/amd64,linux/arm64 --pushwhichbuilds for both architectures and pushes a manifest list to Docker Hub in
one atomic step.
Important:
--pushis required because multi-arch manifest lists cannot beloaded into the local Docker daemon. The build and push happen together.
.github/workflows/docker-publish.yml(NEW -- INACTIVE)A GitHub Actions workflow that automates the multi-arch build and push.
This workflow is set to
workflow_dispatchonly -- it will never runautomatically until you activate it. See the activation section below.
How to Use the Build Script (Manual Build)
Prerequisites: Docker with buildx support (Docker Desktop 19.03+ or Docker
Engine with the buildx plugin). You must be logged in to Docker Hub:
Then, from the
VMs/directory:cd VMs ./buildDockerImage.shThis builds for both amd64 and arm64 and pushes
owasp/benchmark:latesttoDocker Hub. No separate
docker pushstep is needed.How to Activate the GitHub Actions Workflow
The workflow file is already in place at
.github/workflows/docker-publish.yml, but it will only run when manuallytriggered via the GitHub UI. To make it fully automatic:
Step 1: Add Docker Hub Secrets
Go to Settings > Secrets and variables > Actions in your GitHub repository
and add:
DOCKERHUB_USERNAMEDOCKERHUB_TOKENStep 2: Add Automatic Triggers
Open
.github/workflows/docker-publish.ymland uncomment the trigger lines:This will automatically rebuild and push the image whenever:
Step 3: Test with Manual Trigger
Before enabling automatic triggers, test the workflow manually:
You can confirm multi-arch support with:
This should show entries for both
amd64andarm64.What Was NOT Changed
bench:benchuser/passwordtimeout 60 ./runBenchmark.sh; exit 0warm-up trick