|
| 1 | +--- |
| 2 | +# template source: https://github.com/bretfisher/docker-build-workflow/blob/main/templates/call-docker-build.yaml |
| 3 | +name: Docker Build |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + tags: |
| 10 | + - '*' |
| 11 | + # pull_request: |
| 12 | + # branches: |
| 13 | + # - main |
| 14 | + |
| 15 | +env: |
| 16 | + IMAGE_NAME: sonarqube-ecocode-python |
| 17 | + IMAGES: | |
| 18 | + ghcr.io/${{ github.repository_owner }}/sonarqube-ecocode-python |
| 19 | +
|
| 20 | +jobs: |
| 21 | + Build: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository |
| 24 | + permissions: |
| 25 | + contents: read |
| 26 | + packages: write |
| 27 | + # This is used to complete the identity challenge |
| 28 | + # with sigstore/fulcio when running outside of PRs. |
| 29 | + id-token: write |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Login to GitHub Container Registry |
| 33 | + uses: docker/login-action@v2 |
| 34 | + with: |
| 35 | + registry: ghcr.io |
| 36 | + username: ${{ github.actor }} |
| 37 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 38 | + |
| 39 | + - name: Checkout repository |
| 40 | + uses: actions/checkout@v3 |
| 41 | + with: |
| 42 | + fetch-depth: 0 |
| 43 | + |
| 44 | + - name: Set up QEMU |
| 45 | + uses: docker/setup-qemu-action@v2 |
| 46 | + |
| 47 | + - name: Set up Docker Buildx |
| 48 | + uses: docker/setup-buildx-action@v2 |
| 49 | + |
| 50 | + - name: Docker metadata |
| 51 | + id: meta |
| 52 | + uses: docker/metadata-action@v4 |
| 53 | + with: |
| 54 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + images: ${{ env.IMAGES }} |
| 56 | + flavor: | |
| 57 | + latest=auto |
| 58 | + tags: | |
| 59 | + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} |
| 60 | + type=semver,event=tag,pattern={{version}} |
| 61 | + type=semver,event=tag,pattern={{major}}.{{minor}} |
| 62 | + type=semver,event=tag,pattern={{major}} |
| 63 | + type=ref,event=branch |
| 64 | + type=ref,event=pr |
| 65 | + type=sha |
| 66 | +
|
| 67 | + - name: Publish image |
| 68 | + id: push |
| 69 | + uses: docker/build-push-action@v4 |
| 70 | + with: |
| 71 | + push: true |
| 72 | + tags: ${{ steps.meta.outputs.tags }} |
| 73 | + labels: ${{ steps.meta.outputs.labels }} |
| 74 | + pull: true |
| 75 | + cache-to: type=gha,mode=max |
| 76 | + cache-from: type=gha,mode=max |
0 commit comments