diff --git a/Dockerfile b/Dockerfile index c2c6a73..ef9cfd2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ # #FROM debian:bookworm-slim -FROM ubuntu:22.04 +FROM ubuntu:22.04 AS build #ARG TARGET_ARCH=arm-linux-gnueabihf ARG TARGET_ARCH=aarch64-linux-gnu @@ -37,5 +37,6 @@ RUN ./configure --prefix=/usr --host=${TARGET_ARCH} RUN make RUN make binary-dist -#ENTRYPOINT [ "/bin/bash", "-l" ] -CMD [ "/bin/bash", "-l" ] +# Minimal export stage: only copy dist artifacts +FROM scratch AS export +COPY --from=build /opt/dist/ . diff --git a/README.md b/README.md index 7eb5fb8..16a5136 100644 --- a/README.md +++ b/README.md @@ -56,9 +56,25 @@ During development, periodically run `autoscan` to detect if changes should be m ## Cross-platform using Docker -There is a `Dockerfile` that can be used to build for armhf and aarch64 on non-linux hosts that support Docker desktop. See `build-all.sh` for an -automated script that generates build artifacts for both. +There is a `Dockerfile` that can be used to build for armhf and aarch64 on non-linux hosts that support Docker Desktop. A `docker-bake.hcl` file plus the +`build-all.sh` helper script will perform parallel multi-architecture builds using Docker Buildx. +``` +./build-all.sh + +``` +Resulting tarballs are copied to `dist/`. + +To build only one architecture: +``` +docker buildx bake armhf +docker buildx bake arm64 +``` + +Override args example: +``` +docker buildx bake armhf --set armhf.args.TARGET_ARCH=arm-linux-gnueabihf +``` # Supported Platforms diff --git a/build-all.sh b/build-all.sh index 0b184ac..5b6c2ba 100755 --- a/build-all.sh +++ b/build-all.sh @@ -1,20 +1,13 @@ -#!/bin/bash -ueE +#!/usr/bin/env bash +set -ueE main() { - docker build -t bootcount-builder-armv7 \ - --build-arg TARGET_ARCH=arm-linux-gnueabihf . - docker build -t bootcount-builder-armv8 \ - --build-arg TARGET_ARCH=aarch64-linux-gnu . - - for V in v7 v8; do - TARBALL=$(docker run --rm -it bootcount-builder-arm$V ls -1 dist/ | tr -d '\r' | tr -d '\n') - CONTAINER=$(docker create bootcount-builder-arm$V) - docker cp "$CONTAINER:/opt/dist/$TARBALL" . - docker rm "$CONTAINER" - done + mkdir -p dist + docker buildx bake "$@" + ls -lh dist/ } -if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then +if [[ ${BASH_SOURCE[0]} == "$0" ]]; then set -o pipefail main "$@" fi diff --git a/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 0000000..4e4318e --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,22 @@ +group "default" { + targets = ["armhf", "arm64"] +} + +target "arm64" { + context = "." + dockerfile = "Dockerfile" + tags = ["bootcount-builder:arm64"] + args = { + // this is already the default in the Dockerfile: + // TARGET_ARCH = "aarch64-linux-gnu" + } + output = ["type=local,dest=dist/"] +} + +target "armhf" { + inherits = ["arm64"] + args = { + TARGET_ARCH = "arm-linux-gnueabihf" + } + tags = ["bootcount-builder:armhf"] +}