|
| 1 | +name: Docker Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["main"] |
| 6 | + tags: ["v*.*.*"] |
| 7 | + pull_request: |
| 8 | + branches: ["main"] |
| 9 | + |
| 10 | +env: |
| 11 | + REGISTRY: registry.flashcat.cloud |
| 12 | + IMAGE_NAME: public/flashduty-runner |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + contents: read |
| 19 | + packages: write |
| 20 | + id-token: write |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout repository |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Install cosign |
| 27 | + if: github.event_name != 'pull_request' |
| 28 | + uses: sigstore/cosign-installer@v3 |
| 29 | + with: |
| 30 | + cosign-release: "v2.2.4" |
| 31 | + |
| 32 | + - name: Set up Docker Buildx |
| 33 | + uses: docker/setup-buildx-action@v3 |
| 34 | + |
| 35 | + - name: Log into registry ${{ env.REGISTRY }} |
| 36 | + if: github.event_name != 'pull_request' |
| 37 | + uses: docker/login-action@v3 |
| 38 | + with: |
| 39 | + registry: ${{ env.REGISTRY }} |
| 40 | + username: ${{ secrets.TCR_USERNAME }} |
| 41 | + password: ${{ secrets.TCR_PASSWORD }} |
| 42 | + |
| 43 | + - name: Extract Docker metadata |
| 44 | + id: meta |
| 45 | + uses: docker/metadata-action@v5 |
| 46 | + with: |
| 47 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 48 | + tags: | |
| 49 | + type=ref,event=branch |
| 50 | + type=ref,event=tag |
| 51 | + type=ref,event=pr |
| 52 | + type=semver,pattern={{version}} |
| 53 | + type=semver,pattern={{major}}.{{minor}} |
| 54 | + type=semver,pattern={{major}} |
| 55 | + type=sha |
| 56 | + type=raw,value=latest,enable=${{ github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-') }} |
| 57 | +
|
| 58 | + - name: Go Build Cache for Docker |
| 59 | + uses: actions/cache@v4 |
| 60 | + with: |
| 61 | + path: go-build-cache |
| 62 | + key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }} |
| 63 | + |
| 64 | + - name: Inject go-build-cache |
| 65 | + uses: reproducible-containers/buildkit-cache-dance@v3 |
| 66 | + with: |
| 67 | + cache-source: go-build-cache |
| 68 | + |
| 69 | + - name: Build and push Docker image |
| 70 | + id: build-and-push |
| 71 | + uses: docker/build-push-action@v6 |
| 72 | + with: |
| 73 | + context: . |
| 74 | + push: ${{ github.event_name != 'pull_request' }} |
| 75 | + tags: ${{ steps.meta.outputs.tags }} |
| 76 | + labels: ${{ steps.meta.outputs.labels }} |
| 77 | + cache-from: type=gha |
| 78 | + cache-to: type=gha,mode=max |
| 79 | + platforms: linux/amd64,linux/arm64 |
| 80 | + build-args: | |
| 81 | + VERSION=${{ github.ref_name }} |
| 82 | +
|
| 83 | + - name: Sign the published Docker image |
| 84 | + if: ${{ github.event_name != 'pull_request' }} |
| 85 | + env: |
| 86 | + TAGS: ${{ steps.meta.outputs.tags }} |
| 87 | + DIGEST: ${{ steps.build-and-push.outputs.digest }} |
| 88 | + run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} |
0 commit comments