aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows
diff options
context:
space:
mode:
Diffstat (limited to '.github/workflows')
-rw-r--r--.github/workflows/publish.yml79
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 ' *)