generated from populationgenomics/cpg-python-template-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (76 loc) · 2.98 KB
/
docker.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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.0-alpha.18
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
if: ${{ github.ref_name == 'main' || github.ref_name == 'alpha' }}
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 }}"