aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/publish.yml
blob: 04a874253736b3f0dd368e84170bfd10731055dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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