|
| 1 | +name: Build Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - "v[0-9]+.[0-9]+.[0-9]+" |
| 8 | + branches-ignore: |
| 9 | + - "*" |
| 10 | + |
| 11 | +jobs: |
| 12 | + create-runner-amd: |
| 13 | + name: Create Hetzner Cloud AMD runner |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + label: ${{ steps.create-hcloud-runner.outputs.label }} |
| 17 | + server_id: ${{ steps.create-hcloud-runner.outputs.server_id }} |
| 18 | + steps: |
| 19 | + - name: Create runner |
| 20 | + id: create-hcloud-runner |
| 21 | + uses: Cyclenerd/hcloud-github-runner@v1 |
| 22 | + with: |
| 23 | + mode: create |
| 24 | + github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
| 25 | + hcloud_token: ${{ secrets.HCLOUD_TOKEN }} |
| 26 | + server_type: cx32 |
| 27 | + location: hel1 # Helsinki, Finland |
| 28 | + image: docker-ce # Docker CE |
| 29 | + |
| 30 | + create-runner-arm: |
| 31 | + name: Create Hetzner Cloud ARM runner |
| 32 | + runs-on: ubuntu-latest |
| 33 | + outputs: |
| 34 | + label: ${{ steps.create-hcloud-runner.outputs.label }} |
| 35 | + server_id: ${{ steps.create-hcloud-runner.outputs.server_id }} |
| 36 | + steps: |
| 37 | + - name: Create runner |
| 38 | + id: create-hcloud-runner |
| 39 | + uses: Cyclenerd/hcloud-github-runner@v1 |
| 40 | + with: |
| 41 | + mode: create |
| 42 | + github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
| 43 | + hcloud_token: ${{ secrets.HCLOUD_TOKEN }} |
| 44 | + server_type: cax21 |
| 45 | + location: hel1 # Helsinki, Finland |
| 46 | + image: docker-ce # Docker CE |
| 47 | + |
| 48 | + build-and-push-amd: |
| 49 | + if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' |
| 50 | + environment: production |
| 51 | + needs: create-runner-amd # required to start the main job when the runner is ready |
| 52 | + runs-on: ${{ needs.create-runner-amd.outputs.label }} # run the job on the newly created runner |
| 53 | + permissions: |
| 54 | + contents: read |
| 55 | + packages: write |
| 56 | + steps: |
| 57 | + - uses: actions/checkout@v4 |
| 58 | + - name: Login GitHub Container Registry |
| 59 | + uses: docker/login-action@v3 |
| 60 | + with: |
| 61 | + registry: ghcr.io |
| 62 | + username: ${{ github.actor }} |
| 63 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 64 | + - name: Set up Docker Buildx |
| 65 | + uses: docker/setup-buildx-action@v3 |
| 66 | + - name: Extract version parts |
| 67 | + id: version |
| 68 | + if: startsWith(github.ref, 'refs/tags/v') |
| 69 | + run: | |
| 70 | + VERSION=${{ github.ref_name }} |
| 71 | + echo "full=$VERSION" >> $GITHUB_OUTPUT |
| 72 | + echo "major=$(echo $VERSION | cut -d. -f1)" >> $GITHUB_OUTPUT |
| 73 | + echo "minor=$(echo $VERSION | cut -d. -f1-2)" >> $GITHUB_OUTPUT |
| 74 | + - name: Build and push |
| 75 | + uses: docker/build-push-action@v5 |
| 76 | + with: |
| 77 | + push: true |
| 78 | + context: . |
| 79 | + file: ./Dockerfile |
| 80 | + tags: | |
| 81 | + ghcr.io/${{ github.repository }}:${{ github.ref_name }}-amd |
| 82 | +
|
| 83 | + build-and-push-arm: |
| 84 | + if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' |
| 85 | + environment: production |
| 86 | + needs: create-runner-arm # required to start the main job when the runner is ready |
| 87 | + runs-on: ${{ needs.create-runner-arm.outputs.label }} # run the job on the newly created runner |
| 88 | + permissions: |
| 89 | + contents: read |
| 90 | + packages: write |
| 91 | + steps: |
| 92 | + - uses: actions/checkout@v4 |
| 93 | + - name: Login GitHub Container Registry |
| 94 | + uses: docker/login-action@v3 |
| 95 | + with: |
| 96 | + registry: ghcr.io |
| 97 | + username: ${{ github.actor }} |
| 98 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 99 | + - name: Set up Docker Buildx |
| 100 | + uses: docker/setup-buildx-action@v3 |
| 101 | + - name: Extract version parts |
| 102 | + id: version |
| 103 | + if: startsWith(github.ref, 'refs/tags/v') |
| 104 | + run: | |
| 105 | + VERSION=${{ github.ref_name }} |
| 106 | + echo "full=$VERSION" >> $GITHUB_OUTPUT |
| 107 | + echo "major=$(echo $VERSION | cut -d. -f1)" >> $GITHUB_OUTPUT |
| 108 | + echo "minor=$(echo $VERSION | cut -d. -f1-2)" >> $GITHUB_OUTPUT |
| 109 | + - name: Build and push |
| 110 | + uses: docker/build-push-action@v5 |
| 111 | + with: |
| 112 | + push: true |
| 113 | + context: . |
| 114 | + file: ./Dockerfile |
| 115 | + tags: | |
| 116 | + ghcr.io/${{ github.repository }}:${{ github.ref_name }}-arm |
| 117 | +
|
| 118 | + merge-manifest: |
| 119 | + if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' |
| 120 | + runs-on: ubuntu-latest |
| 121 | + needs: [build-and-push-amd, build-and-push-arm] |
| 122 | + permissions: |
| 123 | + contents: read |
| 124 | + packages: write |
| 125 | + steps: |
| 126 | + - name: Login GitHub Container Registry |
| 127 | + uses: docker/login-action@v3 |
| 128 | + with: |
| 129 | + registry: ghcr.io |
| 130 | + username: ${{ github.actor }} |
| 131 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 132 | + - name: Set up Docker Buildx |
| 133 | + uses: docker/setup-buildx-action@v3 |
| 134 | + - name: Extract version parts |
| 135 | + id: version |
| 136 | + if: startsWith(github.ref, 'refs/tags/v') |
| 137 | + run: | |
| 138 | + VERSION=${{ github.ref_name }} |
| 139 | + echo "full=$VERSION" >> $GITHUB_OUTPUT |
| 140 | + echo "major=$(echo $VERSION | cut -d. -f1)" >> $GITHUB_OUTPUT |
| 141 | + echo "minor=$(echo $VERSION | cut -d. -f1-2)" >> $GITHUB_OUTPUT |
| 142 | + - name: Create Versioned Manifest (GHCR) (${{ github.ref_name }}) |
| 143 | + run: | |
| 144 | + docker buildx imagetools create -t ghcr.io/${{ github.repository }}:${{ github.ref_name }} \ |
| 145 | + ghcr.io/${{ github.repository }}:${{ github.ref_name }}-amd \ |
| 146 | + ghcr.io/${{ github.repository }}:${{ github.ref_name }}-arm |
| 147 | + - name: Create Major Version Manifest (GHCR) |
| 148 | + if: startsWith(github.ref, 'refs/tags/v') |
| 149 | + run: | |
| 150 | + docker buildx imagetools create -t ghcr.io/${{ github.repository }}:${{ steps.version.outputs.major }} \ |
| 151 | + ghcr.io/${{ github.repository }}:${{ github.ref_name }}-amd \ |
| 152 | + ghcr.io/${{ github.repository }}:${{ github.ref_name }}-arm |
| 153 | + - name: Create Minor Version Manifest (GHCR) |
| 154 | + if: startsWith(github.ref, 'refs/tags/v') |
| 155 | + run: | |
| 156 | + docker buildx imagetools create -t ghcr.io/${{ github.repository }}:${{ steps.version.outputs.minor }} \ |
| 157 | + ghcr.io/${{ github.repository }}:${{ github.ref_name }}-amd \ |
| 158 | + ghcr.io/${{ github.repository }}:${{ github.ref_name }}-arm |
| 159 | +
|
| 160 | + delete-runner-amd: |
| 161 | + name: Delete Hetzner Cloud AMD runner |
| 162 | + needs: |
| 163 | + - create-runner-amd # required to get output from the create-runner-amd job |
| 164 | + - build-and-push-amd # required to wait when the main job is done |
| 165 | + runs-on: ubuntu-latest |
| 166 | + if: ${{ always() }} # required to stop the runner even if the error happened in the previous jobs |
| 167 | + steps: |
| 168 | + - name: Delete runner |
| 169 | + uses: Cyclenerd/hcloud-github-runner@v1 |
| 170 | + with: |
| 171 | + mode: delete |
| 172 | + github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
| 173 | + hcloud_token: ${{ secrets.HCLOUD_TOKEN }} |
| 174 | + name: ${{ needs.create-runner-amd.outputs.label }} |
| 175 | + server_id: ${{ needs.create-runner-amd.outputs.server_id }} |
| 176 | + |
| 177 | + delete-runner-arm: |
| 178 | + name: Delete Hetzner Cloud ARM runner |
| 179 | + needs: |
| 180 | + - create-runner-arm # required to get output from the create-runner-arm job |
| 181 | + - build-and-push-arm # required to wait when the main job is done |
| 182 | + runs-on: ubuntu-latest |
| 183 | + if: ${{ always() }} # required to stop the runner even if the error happened in the previous jobs |
| 184 | + steps: |
| 185 | + - name: Delete runner |
| 186 | + uses: Cyclenerd/hcloud-github-runner@v1 |
| 187 | + with: |
| 188 | + mode: delete |
| 189 | + github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
| 190 | + hcloud_token: ${{ secrets.HCLOUD_TOKEN }} |
| 191 | + name: ${{ needs.create-runner-arm.outputs.label }} |
| 192 | + server_id: ${{ needs.create-runner-arm.outputs.server_id }} |
0 commit comments