name: Publish Docker Image on: push: branches: - master tags: - v** workflow_dispatch: jobs: publish: name: Publish Docker Image to ghcr.io runs-on: ubuntu-latest strategy: fail-fast: false matrix: platform: [linux/amd64, linux/arm64] permissions: packages: write steps: - name: Check out the repo uses: actions/checkout@v4 - name: Setup version number run: | # docker/build-push-action supports comma separated tags DOCKER_IMAGE_TAG_BASE="ghcr.io/${{ github.repository }}" 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_ENV - name: Check if version already exists in registry run: | 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 - 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: Build and push Docker Image uses: docker/build-push-action@v6 with: context: . file: ./Dockerfile push: true tags: ${{ env.DOCKER_IMAGE_TAGS }} platforms: ${{ matrix.platform }} cache-from: type=gha cache-to: type=gha,mode=max