Skip to content

Commit

Permalink
Build (cross platform) images using 'bake'
Browse files Browse the repository at this point in the history
Locally run `docker buildx bake`
  • Loading branch information
fhoeben committed Nov 13, 2023
1 parent eb287eb commit 2038ce9
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.github
.idea/
.git/
chrome/
Expand All @@ -12,3 +13,4 @@ compose/
*.sh
LICENSE.txt
README.md
docker-bake.hcl
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
169 changes: 169 additions & 0 deletions .github/workflows/publish-cross-platform-images.yml
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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}
8 changes: 5 additions & 3 deletions chrome-with-pdf/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion chrome/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
8 changes: 6 additions & 2 deletions combine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 .
86 changes: 86 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -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}"]
}
4 changes: 3 additions & 1 deletion test-with-pdf/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2038ce9

Please sign in to comment.