From 53b6f22998caef4e6ded716f5eaa6afa8dc78e67 Mon Sep 17 00:00:00 2001 From: codebien <2103732+codebien@users.noreply.github.com> Date: Mon, 4 Sep 2023 19:42:57 +0200 Subject: [PATCH] docker: build multi platform images --- .github/workflows/build.yml | 120 +++++++++++++++++++++--------------- 1 file changed, 69 insertions(+), 51 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8ab4376129e..cf3160233f9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -140,9 +140,18 @@ jobs: with: fetch-depth: 0 - name: Build - run: docker build --target release -t $DOCKER_IMAGE_ID . + run: | + docker buildx create \ + --name multibuilder \ + --platform linux/amd64,linux/arm64 \ + --bootstrap --use + docker buildx build \ + --platform linux/amd64,linux/arm64 \ + -t $DOCKER_IMAGE_ID . - name: Check run: | + docker buildx build --load -t $DOCKER_IMAGE_ID . + # Assert that simple cases works for the new built image docker run $DOCKER_IMAGE_ID version docker run $DOCKER_IMAGE_ID --help docker run $DOCKER_IMAGE_ID help @@ -154,8 +163,6 @@ jobs: docker run $DOCKER_IMAGE_ID pause --help docker run $DOCKER_IMAGE_ID resume --help - - name: Build browser-enabled image - run: docker build -t $DOCKER_IMAGE_ID:with-browser --target with-browser . - name: Log into ghcr.io if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }} run: | @@ -165,26 +172,35 @@ jobs: if: ${{ github.ref == 'refs/heads/master' }} run: | echo "Publish as ghcr.io/$GHCR_IMAGE_ID:$VERSION" - docker tag "$DOCKER_IMAGE_ID" "ghcr.io/$GHCR_IMAGE_ID:master" - docker push "ghcr.io/$GHCR_IMAGE_ID:master" - docker tag "$DOCKER_IMAGE_ID:with-browser" "ghcr.io/$GHCR_IMAGE_ID:master-with-browser" - docker push "ghcr.io/$GHCR_IMAGE_ID:master-with-browser" + docker buildx build --push \ + --platform linux/amd64,linux/arm64 \ + -t ghcr.io/$GHCR_IMAGE_ID:master . + docker buildx build --push \ + --target with-browser \ + --platform linux/amd64,linux/arm64 \ + -t ghcr.io/$GHCR_IMAGE_ID:master-with-browser . - name: Publish tagged version image to ghcr.io if: ${{ startsWith(github.ref, 'refs/tags/v') }} run: | VERSION="${VERSION#v}" echo "Publish as ghcr.io/$GHCR_IMAGE_ID:$VERSION" - docker tag "$DOCKER_IMAGE_ID" "ghcr.io/$GHCR_IMAGE_ID:$VERSION" - docker push "ghcr.io/$GHCR_IMAGE_ID:$VERSION" - docker tag "$DOCKER_IMAGE_ID:with-browser" "ghcr.io/$GHCR_IMAGE_ID:$VERSION-with-browser" - docker push "ghcr.io/$GHCR_IMAGE_ID:$VERSION-with-browser" + docker buildx build --push \ + --platform linux/amd64,linux/arm64 \ + -t ghcr.io/$GHCR_IMAGE_ID:$VERSION . + docker buildx build --push \ + --target with-browser \ + --platform linux/amd64,linux/arm64 \ + -t ghcr.io/$GHCR_IMAGE_ID:$VERSION-with-browser . # We also want to tag the latest stable version as latest if [[ ! "$VERSION" =~ (RC|rc) ]]; then echo "Publish as ghcr.io/$GHCR_IMAGE_ID:latest" - docker tag "$DOCKER_IMAGE_ID" "ghcr.io/$GHCR_IMAGE_ID:latest" - docker push "ghcr.io/$GHCR_IMAGE_ID:latest" - docker tag "$DOCKER_IMAGE_ID:with-browser" "ghcr.io/$GHCR_IMAGE_ID:latest-with-browser" - docker push "ghcr.io/$GHCR_IMAGE_ID:latest-with-browser" + docker buildx build --push \ + --platform linux/amd64,linux/arm64 \ + -t ghcr.io/$GHCR_IMAGE_ID:latest . + docker buildx build --push \ + --target with-browser \ + --platform linux/amd64,linux/arm64 \ + -t ghcr.io/$GHCR_IMAGE_ID:latest-with-browser . fi - name: Log into Docker Hub @@ -192,51 +208,53 @@ jobs: run: | # Log into Docker Hub Registry echo "${{ secrets.DOCKER_PASS }}" | docker login -u "${{ secrets.DOCKER_USER }}" --password-stdin + - name: Publish k6:master image to Docker Hub if: ${{ github.ref == 'refs/heads/master' }} run: | - echo "Publish to Docker Hub as $DOCKER_IMAGE_ID:master" - docker tag "$DOCKER_IMAGE_ID" "$DOCKER_IMAGE_ID:master" - docker push "$DOCKER_IMAGE_ID:master" - docker tag "$DOCKER_IMAGE_ID:with-browser" "$DOCKER_IMAGE_ID:master-with-browser" - docker push "$DOCKER_IMAGE_ID:master-with-browser" + echo "Publish to Docker Hub as $DOCKER_IMAGE_ID:master and $LI_DOCKER_IMAGE_ID:master" + docker buildx build --push \ + --platform linux/amd64,linux/arm64 \ + -t $DOCKER_IMAGE_ID:master . + docker buildx build --push \ + --target with-browser \ + --platform linux/amd64,linux/arm64 \ + -t $DOCKER_IMAGE_ID:master-with-browser . + # LoadImpact images are deprecated, we don't build arm64 for it. + docker buildx build --push \ + --platform linux/amd64 \ + -t $LI_DOCKER_IMAGE_ID:master . - name: Publish tagged version image to Docker Hub if: ${{ startsWith(github.ref, 'refs/tags/v') }} run: | + # We need to push the same image in both the loadimpact and the grafana docker hub orgs VERSION="${VERSION#v}" - echo "Publish to Docker Hub as $DOCKER_IMAGE_ID:$VERSION" - docker tag "$DOCKER_IMAGE_ID" "$DOCKER_IMAGE_ID:$VERSION" - docker push "$DOCKER_IMAGE_ID:$VERSION" - docker tag "$DOCKER_IMAGE_ID:with-browser" "$DOCKER_IMAGE_ID:$VERSION-with-browser" - docker push "$DOCKER_IMAGE_ID:$VERSION-with-browser" - # We also want to tag the latest stable version as latest - if [[ ! "$VERSION" =~ (RC|rc) ]]; then - echo "Publish to Docker Hub as $DOCKER_IMAGE_ID:latest" - docker tag "$DOCKER_IMAGE_ID" "$DOCKER_IMAGE_ID:latest" - docker push "$DOCKER_IMAGE_ID:latest" - docker tag "$DOCKER_IMAGE_ID:with-browser" "$DOCKER_IMAGE_ID:latest-with-browser" - docker push "$DOCKER_IMAGE_ID:latest-with-browser" - fi - - name: Build loadimpact/k6 - run: docker build -t $LI_DOCKER_IMAGE_ID --target legacy . - - name: Publish loadimpact/k6:master image to Docker Hub - if: ${{ github.ref == 'refs/heads/master' }} - run: | - echo "Publish to Docker Hub as $LI_DOCKER_IMAGE_ID:master" - docker tag "$LI_DOCKER_IMAGE_ID" "$LI_DOCKER_IMAGE_ID:master" - docker push "$LI_DOCKER_IMAGE_ID:master" - - name: Publish loadimpact/k6 tagged version image to Docker Hub - if: ${{ startsWith(github.ref, 'refs/tags/v') }} - run: | - VERSION="${VERSION#v}" - echo "Publish to Docker Hub as $LI_DOCKER_IMAGE_ID:$VERSION" - docker tag "$LI_DOCKER_IMAGE_ID" "$LI_DOCKER_IMAGE_ID:$VERSION" - docker push "$LI_DOCKER_IMAGE_ID:$VERSION" + echo "Publish to Docker Hub as $DOCKER_IMAGE_ID:$VERSION and $LI_DOCKER_IMAGE_ID:$VERSION" + docker buildx build --push \ + --platform linux/amd64,linux/arm64 \ + -t $DOCKER_IMAGE_ID:$VERSION . + docker buildx build --push \ + --target with-browser \ + --platform linux/amd64,linux/arm64 \ + -t $DOCKER_IMAGE_ID:$VERSION-with-browser . + # LoadImpact images are deprecated, we don't build arm64 for it. + docker buildx build --push \ + --platform linux/amd64 \ + -t $LI_DOCKER_IMAGE_ID:$VERSION . # We also want to tag the latest stable version as latest if [[ ! "$VERSION" =~ (RC|rc) ]]; then - echo "Publish to Docker Hub as $LI_DOCKER_IMAGE_ID:latest" - docker tag "$LI_DOCKER_IMAGE_ID" "$LI_DOCKER_IMAGE_ID:latest" - docker push "$LI_DOCKER_IMAGE_ID:latest" + echo "Publish to Docker Hub as $DOCKER_IMAGE_ID:latest and $LI_DOCKER_IMAGE_ID:latest" + docker buildx build --push \ + --platform linux/amd64,linux/arm64 \ + -t $DOCKER_IMAGE_ID:latest . + docker buildx build --push \ + --target with-browser \ + --platform linux/amd64,linux/arm64 \ + -t $DOCKER_IMAGE_ID:latest-with-browser . + # LoadImpact images are deprecated, we don't build arm64 for it. + docker buildx build --push \ + --platform linux/amd64 \ + -t $LI_DOCKER_IMAGE_ID:latest . fi package-windows: