|
| 1 | +name: Docker build |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: [ "master", "main", "maint/*", "gha-docker-build" ] |
| 7 | + tags: "*" |
| 8 | + pull_request: |
| 9 | + branches: [ "master", "main", "maint/*" ] |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | +env: |
| 16 | + REGISTRY: ghcr.io |
| 17 | + IMAGE_NAME: ${{ github.repository }} |
| 18 | + FORCE_COLOR: true |
| 19 | + |
| 20 | +jobs: |
| 21 | + build-container: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + permissions: |
| 24 | + contents: read |
| 25 | + packages: write |
| 26 | + steps: |
| 27 | + - name: Checkout repository |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Setup Docker buildx |
| 31 | + uses: docker/setup-buildx-action@v3 |
| 32 | + |
| 33 | + - name: Log into registry ${{ env.REGISTRY }} |
| 34 | + if: github.event_name != 'pull_request' |
| 35 | + uses: docker/login-action@v3 |
| 36 | + with: |
| 37 | + registry: ${{ env.REGISTRY }} |
| 38 | + username: ${{ github.actor }} |
| 39 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 40 | + |
| 41 | + - name: Extract Docker metadata |
| 42 | + id: meta |
| 43 | + uses: docker/metadata-action@v5 |
| 44 | + with: |
| 45 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 46 | + |
| 47 | + - name: Build and push Docker image |
| 48 | + uses: docker/build-push-action@v6 |
| 49 | + with: |
| 50 | + context: . |
| 51 | + push: ${{ github.event_name != 'pull_request' }} |
| 52 | + tags: ${{ steps.meta.outputs.tags }} |
| 53 | + labels: ${{ steps.meta.outputs.labels }} |
| 54 | + cache-from: | |
| 55 | + type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:master |
| 56 | + type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TARGET_BRANCH }} |
| 57 | + type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tags[0] }} |
| 58 | + cache-to: type=inline |
| 59 | + env: |
| 60 | + TARGET_BRANCH: ${{ github.base_ref || github.ref_name }} |
0 commit comments