diff options
| author | Linnea Gräf <nea@nea.moe> | 2025-04-11 23:59:35 +0200 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2025-04-12 00:05:54 +0200 |
| commit | b38b92dc18d20576fc6e2a237d4763da56afcf36 (patch) | |
| tree | b8d4eb0314d83d5fac9ea993134a0be7a60ea5a8 | |
| parent | b3aafaac67f1a728e3aeb5c5d8ba18f997ea4d19 (diff) | |
| download | containerspy-multi-runner-docker.tar.gz containerspy-multi-runner-docker.tar.bz2 containerspy-multi-runner-docker.zip | |
ci: Compute versions oncemulti-runner-docker
| -rw-r--r-- | .github/workflows/publish.yml | 79 |
1 files changed, 41 insertions, 38 deletions
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 956170d..0e10cca 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,6 +14,34 @@ env: IMAGE: ${{ github.repository }} jobs: + gen-versions: + name: Generate tags + runs-on: ubuntu-24.04 + outputs: + DOCKER_IMAGE_TAG_JSON: ${{ steps.variables.outputs.DOCKER_IMAGE_TAG_JSON }} + DOCKER_IMAGE_TAG: ${{ steps.variables.outputs.DOCKER_IMAGE_TAG }} + steps: + - name: Setup variables + id: variables + run: | + # docker/build-push-action supports comma separated tags + DOCKER_IMAGE_TAG_BASE="$REGISTRY/$IMAGE" + DOCKER_IMAGE_TAG_JSON="$( + ( # Every line echoed inside of these parenthesis will result in a version + echo dev + GH_REF="${{ github.ref }}" + # if this is a versioned release, github.ref will start with 'refs/tags/v' + # cut off 'refs/tags/v' + if [[ $GH_REF == "refs/tags/v"* ]]; then + VERSION=$(echo $GH_REF | cut -c 12-) + echo latest + echo $VERSION + fi + ) | sed -e 's|.*|'"$DOCKER_IMAGE_TAG_BASE"':\0|' | jq -R -s -c 'split("\n") | map(select (. != "" ))')" + + echo "DOCKER_IMAGE_TAG_JSON=$DOCKER_IMAGE_TAG_JSON" >> "$GITHUB_OUTPUT" + echo "DOCKER_IMAGE_TAG=$(echo "$DOCKER_IMAGE_TAG_JSON" | jq -r 'join(",")')" >> "$GITHUB_OUTPUT" + publish-base: name: Publish ${{ matrix.arch }} image strategy: @@ -25,6 +53,8 @@ jobs: os: ubuntu-24.04 runs-on: ${{ matrix.os }} + needs: + - gen-versions env: ARCH: ${{matrix.arch}} permissions: @@ -33,24 +63,6 @@ jobs: - 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="$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-$ARCH,$DOCKER_IMAGE_TAG_BASE:$VERSION-$ARCH" - fi - - echo "DOCKER_IMAGE_TAGS=$DOCKER_IMAGE_TAGS" >> "$GITHUB_OUTPUT" - - name: Log in to ghcr.io uses: docker/login-action@v3 with: @@ -58,6 +70,12 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Enhance tags + id: variables + run: | + echo "DOCKER_IMAGE_TAG=$(echo "$TAG" | jq -r 'map(. + "-${{ matrix.arch }}") | join(",")')" >>"$GITHUB_OUTPUT" + env: + TAG: ${{ needs.gen-versions.outputs.DOCKER_IMAGE_TAG_JSON }} - 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 @@ -66,7 +84,7 @@ jobs: with: context: . push: true - tags: ${{ steps.variables.outputs.DOCKER_IMAGE_TAGS }} + tags: ${{ steps.variables.outputs.DOCKER_IMAGE_TAG }} cache-from: type=gha cache-to: type=gha,mode=max - name: Write digest @@ -84,7 +102,9 @@ jobs: publish-multiarch: name: Publish multi-arch image - needs: publish-base + needs: + - publish-base + - gen-versions runs-on: ubuntu-24.04 permissions: packages: write @@ -96,23 +116,6 @@ jobs: 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: @@ -129,6 +132,6 @@ jobs: 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|') \ + $(echo '${{ needs.gen-versions.outputs.DOCKER_IMAGE_TAG }}'| 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 ' *) |
