diff options
| author | Linnea Gräf <nea@nea.moe> | 2025-04-11 23:05:06 +0200 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2025-04-11 23:35:00 +0200 |
| commit | b3aafaac67f1a728e3aeb5c5d8ba18f997ea4d19 (patch) | |
| tree | 8ad1c306b05cee87e2ab27e16401923dcacfd956 | |
| parent | 63f5d412cd1e1921e7ae375945f278267d542c5b (diff) | |
| download | containerspy-b3aafaac67f1a728e3aeb5c5d8ba18f997ea4d19.tar.gz containerspy-b3aafaac67f1a728e3aeb5c5d8ba18f997ea4d19.tar.bz2 containerspy-b3aafaac67f1a728e3aeb5c5d8ba18f997ea4d19.zip | |
ci: Build multiple docker using multiple runners
| -rw-r--r-- | .github/workflows/publish.yml | 114 |
1 files changed, 90 insertions, 24 deletions
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4367c8b..956170d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,47 +4,52 @@ on: push: branches: - master + - multi-runner-docker tags: - v** workflow_dispatch: +env: + REGISTRY: ghcr.io + IMAGE: ${{ github.repository }} + jobs: - publish: - name: Publish Docker Image to ghcr.io - runs-on: ubuntu-latest + publish-base: + name: Publish ${{ matrix.arch }} image + strategy: + matrix: + include: + - arch: arm64 + os: ubuntu-24.04-arm + - arch: amd64 + os: ubuntu-24.04 + + runs-on: ${{ matrix.os }} + env: + ARCH: ${{matrix.arch}} permissions: packages: write - steps: - name: Check out the repo uses: actions/checkout@v4 - name: Setup variables + id: variables run: | + # TODO: share this code with the actual multi arch publisher # docker/build-push-action supports comma separated tags - DOCKER_IMAGE_TAG_BASE="ghcr.io/${{ github.repository }}" - DOCKER_IMAGE_TAGS="$DOCKER_IMAGE_TAG_BASE:dev" + DOCKER_IMAGE_TAG_BASE="$REGISTRY/$IMAGE" + DOCKER_IMAGE_TAGS="$DOCKER_IMAGE_TAG_BASE:dev-$ARCH" # if this is a versioned release, github.ref will start with 'refs/tags/v' GH_REF="${{ github.ref }}" # cut off 'refs/tags/v' if [[ $GH_REF == "refs/tags/v"* ]]; then VERSION=$(echo $GH_REF | cut -c 12-) - DOCKER_IMAGE_TAGS="$DOCKER_IMAGE_TAGS,$DOCKER_IMAGE_TAG_BASE:latest,$DOCKER_IMAGE_TAG_BASE:$VERSION" + DOCKER_IMAGE_TAGS="$DOCKER_IMAGE_TAGS,$DOCKER_IMAGE_TAG_BASE:latest-$ARCH,$DOCKER_IMAGE_TAG_BASE:$VERSION-$ARCH" fi - echo "DOCKER_IMAGE_TAGS=\"$DOCKER_IMAGE_TAGS\"" >> $GITHUB_ENV - # this is dumb - echo "VERSION=$VERSION" >> $GITHUB_ENV - - - name: Check if version already exists in registry - run: | - # this is still dumb - VERSION=${{ env.VERSION }} - if docker manifest inspect ghcr.io/${{ github.repository }}:$VERSION > /dev/null 2>&1; then - echo "Image with version $VERSION already exists in registry" - exit 1 - fi + echo "DOCKER_IMAGE_TAGS=$DOCKER_IMAGE_TAGS" >> "$GITHUB_OUTPUT" - name: Log in to ghcr.io uses: docker/login-action@v3 @@ -53,16 +58,77 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Set up Docker Buildx + - name: Set up Docker Buildx # Even if we don't directly invoke buildx it should set up github action caches, which is nice uses: docker/setup-buildx-action@v3 - - name: Build and push Docker Image uses: docker/build-push-action@v6 + id: upload-docker-image with: context: . - file: ./Dockerfile push: true - tags: ${{ env.DOCKER_IMAGE_TAGS }} - platforms: linux/amd64 + tags: ${{ steps.variables.outputs.DOCKER_IMAGE_TAGS }} cache-from: type=gha cache-to: type=gha,mode=max + - name: Write digest + run: | + digest="${{ steps.upload-docker-image.outputs.digest }}" + mkdir -p digests + touch "digests/${digest#sha256:}" + + - name: Upload docker image digest + uses: actions/upload-artifact@v4 + with: + if-no-files-found: error + name: digests-${{ matrix.arch }} + path: digests/* + + publish-multiarch: + name: Publish multi-arch image + needs: publish-base + runs-on: ubuntu-24.04 + permissions: + packages: write + steps: + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: digests + pattern: digests-* + merge-multiple: true + + - name: Setup variables + id: variables + run: | + # docker/build-push-action supports comma separated tags + DOCKER_IMAGE_TAG_BASE="$REGISTRY/$IMAGE" + DOCKER_IMAGE_TAGS="$DOCKER_IMAGE_TAG_BASE:dev" + + # if this is a versioned release, github.ref will start with 'refs/tags/v' + GH_REF="${{ github.ref }}" + # cut off 'refs/tags/v' + if [[ $GH_REF == "refs/tags/v"* ]]; then + VERSION=$(echo $GH_REF | cut -c 12-) + DOCKER_IMAGE_TAGS="$DOCKER_IMAGE_TAGS,$DOCKER_IMAGE_TAG_BASE:latest,$DOCKER_IMAGE_TAG_BASE:$VERSION" + fi + + echo "DOCKER_IMAGE_TAGS=$DOCKER_IMAGE_TAGS" >> "$GITHUB_OUTPUT" + + - name: Log in to ghcr.io + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Create manifest list + run: | + cd digests + docker buildx imagetools create \ + `# A -t {tag} for each tag in DOCKER_IMAGE_TAGS` \ + $(echo '${{ steps.variables.outputs.DOCKER_IMAGE_TAGS }}'| tr ',' '\n' | sed -e 's|.*|-t \0|') \ + `# Then a reference for each of the arches. This uses the fact that printf repeats its format string if it has too many arguments.` \ + $(printf '${{env.REGISTRY}}/${{ env.IMAGE }}@sha256:%s ' *) |
