From df4b0330eac93238c7763f461ebb723ad9b318a5 Mon Sep 17 00:00:00 2001 From: Pim van Nierop Date: Fri, 3 May 2024 12:58:16 +0200 Subject: [PATCH] Publish docker images on GitHub and docker hub --- .github/workflows/docker-image.yml | 14 ++++++++++---- .github/workflows/release.yml | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 21a4e0c..1ee6430 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,8 +1,6 @@ #See: https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-github-packages name: Create and publish a Docker image -on: - release: - types: [ published ] +on: push env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} @@ -20,11 +18,19 @@ jobs: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Set environment variables + run: | + # Short name for current branch. For PRs, use target branch (base ref) + GIT_BRANCH=${GITHUB_BASE_REF:-${GITHUB_REF#refs/heads/}} + echo "GIT_BRANCH=$GIT_BRANCH" >> $GITHUB_ENV - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ env.GIT_BRANCH }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} - name: Build and push Docker image uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f2fddaa..0cb936a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,7 +23,7 @@ jobs: id: docker_meta uses: docker/metadata-action@v4 with: - images: ${{ env.DOCKER_IMAGE }} + images: ${{ env.DOCKER_IMAGE }}-${{ env.GIT_BRANCH }} tags: | type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}}