build-artifacts #16
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: build-artifacts | |
| on: | |
| workflow_dispatch: | |
| env: | |
| GCP_PROJECT_ID: "open-targets-genetics-dev" | |
| GCP_REGION: "europe-west1" | |
| TAG: "${{ github.ref_name }}" | |
| REPO: "${{ github.event.repository.name }}" | |
| jobs: | |
| push-to-ghcr-and-gar: | |
| if: startsWith(github.ref, 'refs/tags/') | |
| name: Build docker image and push to GHCR and GAR | |
| runs-on: ubuntu-22.04 | |
| permissions: | |
| packages: write | |
| contents: read | |
| attestations: write | |
| id-token: write | |
| steps: | |
| - id: prepare | |
| name: Prepare the action and log details | |
| shell: bash | |
| env: | |
| GITHUB_CONTEXT: ${{ toJson(github) }} | |
| run: | | |
| TAG=$(echo $TAG | sed 's/^v//') | |
| echo "TAG=$TAG" >> $GITHUB_ENV | |
| echo "The tag for this build is $TAG" | |
| echo "The repo name is: $REPO" | |
| echo "Github context:\n$GITHUB_CONTEXT" | |
| - id: checkout | |
| name: Check out repo | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - id: auth-ghcr | |
| name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - id: auth-google | |
| name: Authenticate to Google Cloud | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| token_format: access_token | |
| project_id: ${{ env.GCP_PROJECT_ID }} | |
| service_account: github-actions@open-targets-genetics-dev.iam.gserviceaccount.com | |
| workload_identity_provider: projects/234703259993/locations/global/workloadIdentityPools/github/providers/opentargets | |
| access_token_lifetime: 300s | |
| - id: auth-gar | |
| name: Login to Google Artifact Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.GCP_REGION }}-docker.pkg.dev | |
| username: oauth2accesstoken | |
| password: ${{ steps.auth-google.outputs.access_token }} | |
| - id: push | |
| name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: | | |
| ghcr.io/${{ github.repository }}:latest | |
| ghcr.io/${{ github.repository }}:${{ env.TAG }} | |
| ${{ env.GCP_REGION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/opentargets/${{ env.REPO }}:latest | |
| ${{ env.GCP_REGION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/opentargets/${{ env.REPO }}:${{ env.TAG }} | |
| - id: generate-attestations | |
| name: Generate artifact attestation | |
| uses: actions/attest-build-provenance@v1 | |
| with: | |
| subject-name: ${{ env.GCP_REGION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/opentargets/${{ env.REPO }} | |
| subject-digest: ${{ steps.push.outputs.digest }} | |
| push-to-registry: true |