From 2038ce95ce2ee7b625d3692215bd83885c64d8eb Mon Sep 17 00:00:00 2001 From: Fried Hoeben Date: Mon, 13 Nov 2023 15:01:59 +0100 Subject: [PATCH] Build (cross platform) images using 'bake' Locally run `docker buildx bake` --- .dockerignore | 2 + .github/dependabot.yml | 11 ++ .../publish-cross-platform-images.yml | 169 ++++++++++++++++++ Dockerfile | 7 +- chrome-with-pdf/Dockerfile | 8 +- chrome/Dockerfile | 4 +- combine/Dockerfile | 8 +- docker-bake.hcl | 86 +++++++++ test-with-pdf/Dockerfile | 4 +- test/Dockerfile | 4 +- 10 files changed, 292 insertions(+), 11 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/publish-cross-platform-images.yml create mode 100644 docker-bake.hcl diff --git a/.dockerignore b/.dockerignore index 236892f..4826926 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ +.github .idea/ .git/ chrome/ @@ -12,3 +13,4 @@ compose/ *.sh LICENSE.txt README.md +docker-bake.hcl diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..501c31c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/publish-cross-platform-images.yml b/.github/workflows/publish-cross-platform-images.yml new file mode 100644 index 0000000..db4b6ae --- /dev/null +++ b/.github/workflows/publish-cross-platform-images.yml @@ -0,0 +1,169 @@ +name: publish-cross-platform-images + +on: + push: + branches: + - '*' + paths-ignore: + - '*.sh' + - 'README.md' + - 'compose' + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + platform: [linux/amd64, linux/arm64] + steps: + - name: Check out Git repository + uses: actions/checkout@v4 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + hsac/fitnesse-fixtures-test-jre11 + hsac/fitnesse-fixtures-combine + hsac/fitnesse-fixtures-test-jre11-chrome + hsac/fitnesse-fixtures-test-jre11-with-pdf + hsac/fitnesse-fixtures-test-jre11-chrome-with-pdf + + - name: Rename meta bake definition file + run: | + mv "${{ steps.meta.outputs.bake-file }}" "/tmp/bake-meta.json" + + - name: Upload meta bake definition + uses: actions/upload-artifact@v3 + with: + name: bake-meta + path: /tmp/bake-meta.json + if-no-files-found: error + retention-days: 1 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build + id: bake + uses: docker/bake-action@v4 + with: + files: | + ./docker-bake.hcl + /tmp/bake-meta.json + targets: | + test + chrome + combine + test-with-pdf + chrome-with-pdf + set: | + *.tags= + *.platform=${{ matrix.platform }} + test.output=type=image,"name=hsac/fitnesse-fixtures-test-jre11",push-by-digest=true,name-canonical=true,push=true + combine.output=type=image,"name=hsac/fitnesse-fixtures-combine",push-by-digest=true,name-canonical=true,push=true + chrome.output=type=image,"name=hsac/fitnesse-fixtures-test-jre11-chrome",push-by-digest=true,name-canonical=true,push=true + test-with-pdf.output=type=image,"name=hsac/fitnesse-fixtures-test-jre11-with-pdf",push-by-digest=true,name-canonical=true,push=true + chrome-with-pdf.output=type=image,"name=hsac/fitnesse-fixtures-test-jre11-chrome-with-pdf",push-by-digest=true,name-canonical=true,push=true + + - name: Export digests + run: | + mkdir -p /tmp/digests/test + test_digest="${{ fromJSON(steps.bake.outputs.metadata)['test']['containerimage.digest'] }}" + touch "/tmp/digests/test/${test_digest#sha256:}" + mkdir -p /tmp/digests/combine + combine_digest="${{ fromJSON(steps.bake.outputs.metadata)['combine']['containerimage.digest'] }}" + touch "/tmp/digests/combine/${combine_digest#sha256:}" + mkdir -p /tmp/digests/chrome + chrome_digest="${{ fromJSON(steps.bake.outputs.metadata)['chrome']['containerimage.digest'] }}" + touch "/tmp/digests/chrome/${chrome_digest#sha256:}" + mkdir -p /tmp/digests/test-with-pdf + test_with_pdf_digest="${{ fromJSON(steps.bake.outputs.metadata)['test-with-pdf']['containerimage.digest'] }}" + touch "/tmp/digests/test-with-pdf/${test_with_pdf_digest#sha256:}" + mkdir -p /tmp/digests/chrome-with-pdf + chrome_with_pdf_digest="${{ fromJSON(steps.bake.outputs.metadata)['chrome-with-pdf']['containerimage.digest'] }}" + touch "/tmp/digests/chrome-with-pdf/${chrome_with_pdf_digest#sha256:}" + + - name: Upload digest + uses: actions/upload-artifact@v3 + with: + name: digests + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + - name: Test test image + if: matrix.platform == 'linux/amd64' + run: | + SHA="sha256:$(cd /tmp/digests/test; ls *)" + IMAGE="hsac/fitnesse-fixtures-test-jre11@${SHA}" + docker run --rm -v "$(pwd)"/src/main/wiki:/fitnesse/wiki/FitNesseRoot -e RE_RUN_FAILED=true ${IMAGE} -DfitnesseSuiteToRun=SampleTests.SlimTests.UtilityFixtures + + - name: Test chrome image + if: matrix.platform == 'linux/amd64' + run: | + SHA="sha256:$(cd /tmp/digests/chrome; ls *)" + IMAGE="hsac/fitnesse-fixtures-test-jre11-chrome@${SHA}" + docker run --rm -v "$(pwd)"/src/main/wiki:/fitnesse/wiki/FitNesseRoot -e RE_RUN_FAILED=true ${IMAGE} -DfitnesseSuiteToRun=SampleTests.SlimTests.BrowserTest + + merge: + runs-on: ubuntu-latest + needs: + - build + strategy: + fail-fast: false + matrix: + target: [test, combine, chrome, test-with-pdf, chrome-with-pdf] + include: + - target: test + image: hsac/fitnesse-fixtures-test-jre11 + - target: combine + image: hsac/fitnesse-fixtures-combine + - target: chrome + image: hsac/fitnesse-fixtures-test-jre11-chrome + - target: test-with-pdf + image: hsac/fitnesse-fixtures-test-jre11-with-pdf + - target: chrome-with-pdf + image: hsac/fitnesse-fixtures-test-jre11-chrome-with-pdf + steps: + - name: Download meta bake definition + uses: actions/download-artifact@v3 + with: + name: bake-meta + path: /tmp + + - name: Download digests + uses: actions/download-artifact@v3 + with: + name: digests + path: /tmp/digests + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Create manifest list and push + working-directory: /tmp/digests/${{ matrix.target }} + run: | + docker buildx imagetools create $(jq -cr '.target."docker-metadata-action".tags | map(select(startswith("${{ matrix.image }}")) | "-t " + .) | join(" ")' /tmp/bake-meta.json) \ + $(printf '${{ matrix.image }}@sha256:%s ' *) + + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ matrix.image }}:$(jq -r '.target."docker-metadata-action".args.DOCKER_META_VERSION' /tmp/bake-meta.json) diff --git a/Dockerfile b/Dockerfile index 3471a3f..d63c9d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,13 @@ -ARG MAVEN_VERSION=3.8-amazoncorretto-11 +ARG MAVEN_VERSION=3.8-amazoncorretto-11 FROM maven:${MAVEN_VERSION} as build +ARG VERSION=5.3.0 RUN mkdir -p /usr/src WORKDIR /usr/src COPY pom.xml . -RUN mvn compile +RUN mvn compile -Dhsac.fixtures.version=${VERSION} COPY src/ ./src -RUN mvn package +RUN mvn package -Dhsac.fixtures.version=${VERSION} diff --git a/chrome-with-pdf/Dockerfile b/chrome-with-pdf/Dockerfile index 30dc664..81aa256 100644 --- a/chrome-with-pdf/Dockerfile +++ b/chrome-with-pdf/Dockerfile @@ -1,7 +1,9 @@ ARG TEST_PDF_IMAGE=hsac/fitnesse-fixtures-test-jre11-with-pdf:latest ARG TEST_CHROME_IMAGE=hsac/fitnesse-fixtures-test-jre11-chrome:latest -FROM ${TEST_PDF_IMAGE} as test +FROM ${TEST_PDF_IMAGE} as test-with-pdf -FROM ${TEST_CHROME_IMAGE} -COPY --from=test /fitnesse/wiki/fixtures /fitnesse/wiki/fixtures +FROM ${TEST_CHROME_IMAGE} as hsac-chrome + +FROM hsac-chrome +COPY --from=test-with-pdf /fitnesse/wiki/fixtures /fitnesse/wiki/fixtures diff --git a/chrome/Dockerfile b/chrome/Dockerfile index e611f95..3d91f07 100644 --- a/chrome/Dockerfile +++ b/chrome/Dockerfile @@ -2,7 +2,9 @@ ARG TEST_IMAGE=hsac/fitnesse-fixtures-test-jre11:latest ARG SELENIUM_IMAGE=seleniarm/standalone-chromium:latest FROM ${TEST_IMAGE} as hsac-fixtures -FROM ${SELENIUM_IMAGE} +FROM ${SELENIUM_IMAGE} as selenium + +FROM selenium RUN sudo mv /etc/supervisor/conf.d/selenium.conf /etc/supervisor/conf.d/selenium.conf.bak && \ sudo mkdir -p /fitnesse/target && \ sudo mkdir -p /fitnesse/wiki/webdrivers && \ diff --git a/combine/Dockerfile b/combine/Dockerfile index 10048b3..1011cf9 100644 --- a/combine/Dockerfile +++ b/combine/Dockerfile @@ -5,6 +5,8 @@ ARG BUSYBOX_IMAGE=busybox:latest FROM ${BASE_IMAGE} as base FROM ${GRAALVM_IMAGE} as graal + +FROM graal as graal-fitnesse RUN mkdir -p /fitnesse/target WORKDIR /fitnesse @@ -13,11 +15,13 @@ COPY --from=base /usr/src/combine/target/hsac-html-report-generator.jar target/ ENV JAVA_TOOL_OPTIONS="-Djdk.lang.Process.launchMechanism=vfork" RUN native-image -jar target/hsac-html-report-generator.jar --static -FROM ${BUSYBOX_IMAGE} +FROM ${BUSYBOX_IMAGE} as busybox + +FROM busybox WORKDIR /fitnesse VOLUME /fitnesse/target ENTRYPOINT ["/fitnesse/hsac-html-report-generator"] CMD [] -COPY --from=graal /fitnesse/hsac-html-report-generator . +COPY --from=graal-fitnesse /fitnesse/hsac-html-report-generator . diff --git a/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 0000000..f50cc45 --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,86 @@ +variable "VERSION" { + default = "5.3.1" +} +variable "SELENIUM_VERSION" { + default = "latest" +} +variable "TAG" { + default = "latest" +} + +// Special target: https://github.com/docker/metadata-action#bake-definition +target "docker-metadata-action" {} + +group "default" { + targets = ["base", "test", "test-with-pdf", "chrome", "chrome-with-pdf", "combine"] +} + +target "base" { + inherits = ["docker-metadata-action"] + context = "." + dockerfile = "Dockerfile" + pull = true + args = { + VERSION = "${VERSION}" + } + tags = ["hsac/fitnesse-fixtures-test-jre11:base-${TAG}"] +} + +target "test" { + inherits = ["docker-metadata-action"] + context = "test" + dockerfile = "Dockerfile" + pull = true + contexts = { + base = "target:base" + jre = "docker-image://eclipse-temurin:11-jre" + } + tags = ["hsac/fitnesse-fixtures-test-jre11:${TAG}"] +} + +target "test-with-pdf" { + inherits = ["docker-metadata-action"] + context = "test-with-pdf" + dockerfile = "Dockerfile" + contexts = { + base = "target:base" + hsac-fixtures = "target:test" + } + tags = ["hsac/fitnesse-fixtures-test-jre11-with-pdf:${TAG}"] +} + +target "chrome" { + inherits = ["docker-metadata-action"] + context = "chrome" + dockerfile = "Dockerfile" + pull = true + contexts = { + selenium = "docker-image://seleniarm/standalone-chromium:${SELENIUM_VERSION}" + hsac-fixtures = "target:test" + } + tags = ["hsac/fitnesse-fixtures-test-jre11-chrome:${TAG}"] +} + +target "chrome-with-pdf" { + inherits = ["docker-metadata-action"] + context = "chrome-with-pdf" + dockerfile = "Dockerfile" + contexts = { + test-with-pdf = "target:test-with-pdf" + hsac-chrome = "target:chrome" + } + tags = ["hsac/fitnesse-fixtures-test-jre11-chrome-with-pdf:${TAG}"] +} + +target "combine" { + inherits = ["docker-metadata-action"] + context = "combine" + dockerfile = "Dockerfile" + pull = true + contexts = { + base = "target:base" + graal = "docker-image://ghcr.io/graalvm/native-image:latest" + busybox = "docker-image://busybox:latest" + } + tags = ["hsac/fitnesse-fixtures-combine:${TAG}"] +} diff --git a/test-with-pdf/Dockerfile b/test-with-pdf/Dockerfile index 5dfe538..1ba35f1 100644 --- a/test-with-pdf/Dockerfile +++ b/test-with-pdf/Dockerfile @@ -4,5 +4,7 @@ ARG TEST_IMAGE=hsac/fitnesse-fixtures-test-jre11:latest FROM ${BASE_IMAGE} as base RUN mvn compile -P withPdf -FROM ${TEST_IMAGE} +FROM ${TEST_IMAGE} as hsac-fixtures + +FROM hsac-fixtures COPY --from=base /usr/src/test/wiki/fixtures wiki/fixtures diff --git a/test/Dockerfile b/test/Dockerfile index 739ebb5..a671ab4 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -3,7 +3,9 @@ ARG JRE_IMAGE=eclipse-temurin:11-jre FROM ${BASE_IMAGE} as base -FROM ${JRE_IMAGE} +FROM ${JRE_IMAGE} as jre + +FROM jre RUN mkdir -p /fitnesse/wiki/fixtures/nl/hsac/fitnesse WORKDIR /fitnesse