|
| 1 | +name: Build and push image |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - .github/workflows/build-image.yml |
| 7 | + - Dockerfile |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + tags: |
| 12 | + - 'v*' |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + packages: write |
| 17 | + |
| 18 | +env: |
| 19 | + REGISTRY: ghcr.io |
| 20 | + IMAGE_NAME: ${{ github.repository }} |
| 21 | + |
| 22 | +jobs: |
| 23 | + docker: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + |
| 31 | + - name: Setup Go |
| 32 | + uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0 |
| 33 | + with: |
| 34 | + go-version: v1.24.11 |
| 35 | + |
| 36 | + - name: Set up QEMU |
| 37 | + uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0 |
| 38 | + |
| 39 | + - name: Set up Docker Buildx |
| 40 | + uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 |
| 41 | + |
| 42 | + - name: Login to GHCR |
| 43 | + if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') |
| 44 | + uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 |
| 45 | + with: |
| 46 | + registry: ${{ env.REGISTRY }} |
| 47 | + username: ${{ github.actor }} |
| 48 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + |
| 50 | + - name: Generate image metadata |
| 51 | + id: meta |
| 52 | + uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0 |
| 53 | + with: |
| 54 | + images: | |
| 55 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 56 | + tags: | |
| 57 | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} |
| 58 | + type=ref,event=tag |
| 59 | + type=sha |
| 60 | +
|
| 61 | + - name: Build and push image |
| 62 | + uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 |
| 63 | + with: |
| 64 | + context: . |
| 65 | + file: ./Dockerfile |
| 66 | + push: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }} |
| 67 | + tags: ${{ steps.meta.outputs.tags }} |
| 68 | + labels: ${{ steps.meta.outputs.labels }} |
| 69 | + platforms: linux/amd64,linux/arm64 |
| 70 | + cache-from: type=gha |
| 71 | + cache-to: type=gha,mode=max |
0 commit comments