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 4 commits into
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.
|
I'd prefer latest, but when it breaks, people can manually fix it by setting it to a previous version that works, and lets us know, so we can fix it again. Thanks |
Revert base image from pinned ubuntu:22.04 back to ubuntu:latest as requested by @davewichers in PR review.
|
Hello. Sorry for my slow reply, have a hell week this week, traveling the entire country, sadly quite literally :( |
|
@TheAuditorTool - No worries. Thanks for the change. @darkspirit510 - Can you test this on your Mac to see if it works for you? And if you happen to have access to a Windows machine or VM test it there too? And let me know if it's all good (or not). |
| @@ -0,0 +1,66 @@ | |||
| # ------------------------------------------------------------------ | |||
There was a problem hiding this comment.
@davewichers (how) do you publish docker images? https://hub.docker.com/r/owasp/benchmark this one is some months old. This workflow could help automating this, but if you prefer manual publish, we do not need it.
|
@TheAuditorTool does not work on my test server: |
Fixes two issues reported on PR OWASP-Benchmark#445: - VMs/buildDockerImage.sh used `.` as build context with no --file, so running the script from the repo root made buildx look for ./Dockerfile (which does not exist). Switch to explicit --file VMs/Dockerfile and context VMs, matching the paths used by .github/workflows/docker-publish.yml. - VMs/runDockerImage.sh still referenced the old `benchmark` image tag, but the buildx rewrite in c68a62b publishes `owasp/benchmark:latest`. Update the tag so `docker run` finds the freshly-built image. Reported-by: @darkspirit510
Document the manual build flow, GitHub Actions workflow activation, and Docker Hub publishing steps in PR_multi-arch-docker.md. This file was referenced in c68a62b's commit message but accidentally omitted from that commit.
|
Thanks for catching this, and sorry for the slow turnaround. Reproduced: from the repo root, I also noticed On your separate question to @davewichers about Docker Hub publish cadence: the workflow this PR adds ( If you have a moment to try it again from the repo root after |
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:
benchmarktoowasp/benchmarkto match the new build script's outputSummary
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/DockerfileRUN apt-getlayers into 1RUNalso ensuresapt-get updateandinstallshare the same cache.rm -rf /var/lib/apt/lists/*RUNRUNuseradd+chpasswdinto 1RUNEXPOSE 8443CMD ["./runBenchmark.sh"]useraddlineBase image remains
ubuntu:latestper maintainer preference.VMs/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 --pushwithexplicit
--file VMs/Dockerfileand contextVMs(matching the pathsused by
.github/workflows/docker-publish.yml), which builds for botharchitectures 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.
VMs/runDockerImage.shSingle-token update: image tag changed from
benchmarktoowasp/benchmarkso
docker runpulls the image that the new build script publishes..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 repository root:
This builds for both amd64 and arm64 and pushes
owasp/benchmark:latesttoDocker Hub. No separate
docker pushstep is needed.Running the Published Image
After publishing, run the image with:
This pulls
owasp/benchmark:latestfrom Docker Hub and starts the benchmarkinside the container.
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