Merge pull request #68 from populationgenomics/modify-target-as-x-met… #380
This file contains 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: Docker | |
on: | |
pull_request: | |
branches: | |
- main | |
- alpha | |
push: | |
branches: | |
- main | |
- alpha | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: 'Tag to use (defaults to "test")' | |
default: 'test' | |
permissions: | |
id-token: write | |
contents: read | |
env: | |
VERSION: 0.1.1 | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
environment: production | |
defaults: | |
run: | |
shell: bash -l {0} | |
env: | |
DOCKER_BUILDKIT: 1 | |
BUILDKIT_PROGRESS: plain | |
CLOUDSDK_CORE_DISABLE_PROMPTS: 1 | |
IMAGE_NAME: cpg_flow | |
DOCKER_DEV: australia-southeast1-docker.pkg.dev/cpg-common/images-dev | |
DOCKER_MAIN: australia-southeast1-docker.pkg.dev/cpg-common/images | |
DOCKER_TMP: australia-southeast1-docker.pkg.dev/cpg-common/images-tmp | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Log the PR commit sha | |
if: ${{ github.event_name == 'pull_request' }} | |
run: "echo 'PR commit sha: ${{ github.event.pull_request.head.sha }}'" | |
- id: 'google-cloud-auth' | |
name: 'Authenticate to Google Cloud' | |
uses: google-github-actions/auth@v2 | |
with: | |
workload_identity_provider: 'projects/1051897107465/locations/global/workloadIdentityPools/github-pool/providers/github-provider' | |
service_account: '[email protected]' | |
- name: set up gcloud sdk | |
uses: google-github-actions/setup-gcloud@v2 | |
with: | |
project_id: cpg-common | |
- name: gcloud docker auth | |
run: | | |
gcloud auth configure-docker australia-southeast1-docker.pkg.dev | |
- name: build | |
run: | | |
docker build . -f Dockerfile --tag $IMAGE_NAME:${{ github.sha }} | |
- name: push commit sha tag | |
if: ${{ github.ref_name != 'main' && github.ref_name != 'alpha' }} | |
run: | | |
docker tag $IMAGE_NAME:${{ github.sha }} $DOCKER_TMP/$IMAGE_NAME:${{ github.event.pull_request.head.sha }} | |
docker push $DOCKER_TMP/$IMAGE_NAME:${{ github.event.pull_request.head.sha }} | |
echo "DOCKER_IMAGE=$DOCKER_TMP/$IMAGE_NAME:${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV | |
- name: push production on version bump | |
if: ${{ github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'alpha') && startsWith(github.event.head_commit.message, 'bump:') }} | |
run: | | |
docker tag $IMAGE_NAME:${{ github.sha }} $DOCKER_MAIN/$IMAGE_NAME:$VERSION | |
docker push $DOCKER_MAIN/$IMAGE_NAME:$VERSION | |
echo "DOCKER_IMAGE=$DOCKER_MAIN/$IMAGE_NAME:$VERSION" >> $GITHUB_ENV | |
- name: manually triggered build | |
if: ${{ github.event_name == 'workflow_dispatch' && github.ref_name != 'main' }} | |
run: | | |
docker tag $IMAGE_NAME:${{ github.sha }} $DOCKER_DEV/$IMAGE_NAME:${{ github.event.inputs.tag }} | |
docker push $DOCKER_DEV/$IMAGE_NAME:${{ github.event.inputs.tag }} | |
echo "DOCKER_IMAGE=$DOCKER_DEV/$IMAGE_NAME:${{ github.event.inputs.tag }}" >> $GITHUB_ENV | |
- name: print docker tag | |
run: echo "Pushed Docker Tag ${{ env.DOCKER_IMAGE }}" |