|
| 1 | +name: Build and Push Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v[0-9]+.[0-9]+.[0-9]+' |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + name: Build and push 🚢 |
| 11 | + runs-on: ubuntu-22.04 |
| 12 | + permissions: |
| 13 | + packages: write |
| 14 | + contents: read |
| 15 | + attestations: write |
| 16 | + id-token: write |
| 17 | + env: |
| 18 | + REPO: ${{ github.event.repository.name }} |
| 19 | + |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Prepare environment |
| 24 | + run: | |
| 25 | + TAG=$(echo ${{ github.ref_name }} | sed 's/^v//') |
| 26 | + echo "TAG=$TAG" >> $GITHUB_ENV |
| 27 | + echo "The tag for this build is $TAG" |
| 28 | + echo "The repo name is: $REPO" |
| 29 | +
|
| 30 | + - id: auth-google |
| 31 | + uses: google-github-actions/auth@v2 |
| 32 | + with: |
| 33 | + token_format: access_token |
| 34 | + project_id: 'open-targets-eu-dev' |
| 35 | + workload_identity_provider: projects/426265110888/locations/global/workloadIdentityPools/github-actions/providers/opentargets |
| 36 | + service_account: github-actions@open-targets-eu-dev.iam.gserviceaccount.com |
| 37 | + access_token_lifetime: 300s |
| 38 | + |
| 39 | + - id: auth-gar |
| 40 | + name: Login to Google Artifact Registry |
| 41 | + uses: docker/login-action@v3 |
| 42 | + with: |
| 43 | + registry: europe-west1-docker.pkg.dev |
| 44 | + username: oauth2accesstoken |
| 45 | + password: ${{ steps.auth-google.outputs.access_token }} |
| 46 | + |
| 47 | + - id: auth-ghcr |
| 48 | + name: Log in to GitHub Container Registry |
| 49 | + uses: docker/login-action@v3 |
| 50 | + with: |
| 51 | + registry: ghcr.io |
| 52 | + username: ${{ github.actor }} |
| 53 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + |
| 55 | + - id: push |
| 56 | + name: Build and push Docker image |
| 57 | + uses: docker/build-push-action@v6 |
| 58 | + with: |
| 59 | + context: . |
| 60 | + push: true |
| 61 | + tags: | |
| 62 | + ghcr.io/${{ github.repository }}:latest |
| 63 | + ghcr.io/${{ github.repository }}:${{ env.TAG }} |
| 64 | + europe-west1-docker.pkg.dev/open-targets-eu-dev/${{ env.REPO }}/${{ env.REPO }}:latest |
| 65 | + europe-west1-docker.pkg.dev/open-targets-eu-dev/${{ env.REPO }}/${{ env.REPO }}:${{ env.TAG }} |
| 66 | +
|
| 67 | + - id: generate-attestations |
| 68 | + name: Generate artifact attestation |
| 69 | + uses: actions/attest-build-provenance@v2 |
| 70 | + with: |
| 71 | + subject-name: europe-west1-docker.pkg.dev/open-targets-eu-dev/${{ env.REPO }}/${{ env.REPO }} |
| 72 | + subject-digest: ${{ steps.push.outputs.digest }} |
| 73 | + push-to-registry: true |
0 commit comments