-
Notifications
You must be signed in to change notification settings - Fork 1
177 lines (157 loc) · 6.58 KB
/
build_push_terra.yml
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
name: Build and push Docker image to Terra
on:
push:
# when ready to merge dev branch back into main, change this to main
branches: [dev]
paths:
- "*.py"
- "requirements*.txt"
- "src/**"
- "tests/**"
- "Dockerfile"
- ".github/workflows/build_push_terra.yml"
pull_request:
paths:
- "*.py"
- "requirements*.txt"
- "src/**"
- "tests/**"
- "Dockerfile"
- ".github/workflows/build_push_terra.yml"
schedule:
- cron: "30 12 * * 1"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
# Delete me when ready to merge dev back into main
TARGET_BRANCH: dev
# Google project where artifacts are uploaded.
GOOGLE_PROJECT: dsp-artifact-registry
# Name of the app-specific Docker repository configured in GOOGLE_PROJECT.
REPOSITORY_NAME: sfkit
# Name of the image we'll be uploading into the Docker repository.
# This is often equal to the GitHub repository name, but it might also be the
# name of the Helm Chart if that's different.
IMAGE_NAME: ${{ github.event.repository.name }}
# This is the region-specific top-level Google-managed domain where our
# GOOGLE_PROJECT/REPOSITORY_NAME can be found.
GOOGLE_DOCKER_REPOSITORY: us-central1-docker.pkg.dev
jobs:
generate-tag:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
tag: ${{ steps.tag.outputs.new_tag }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ (github.actor != 'dependabot[bot]' && secrets.BROADBOT_TOKEN) || secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Generate Tag
uses: databiosphere/github-actions/actions/bumper@bumper-0.2.0
id: tag
env:
DEFAULT_BUMP: patch
RELEASE_BRANCHES: ${{ env.TARGET_BRANCH || github.event.repository.default_branch }}
WITH_V: true
GITHUB_TOKEN: ${{ (github.actor != 'dependabot[bot]' && secrets.BROADBOT_TOKEN) || secrets.GITHUB_TOKEN }}
build-and-publish:
needs: [generate-tag]
if: ${{ needs.generate-tag.outputs.tag != '' }}
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Assemble Docker tags
uses: docker/metadata-action@v5
id: meta
with:
# server image for backwards compatibility with old build behavior
images: |
${{ env.GOOGLE_DOCKER_REPOSITORY }}/${{ env.GOOGLE_PROJECT }}/${{ env.REPOSITORY_NAME }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=${{ needs.generate-tag.outputs.tag }}
type=semver,pattern=v{{major}},value=${{ needs.generate-tag.outputs.tag }},enable={{is_default_branch}}
type=semver,pattern=v{{major}}.{{minor}},value=${{ needs.generate-tag.outputs.tag }},enable={{is_default_branch}}
- name: Auth to GCP
id: gcp-auth
uses: google-github-actions/auth@v1
with:
token_format: access_token
workload_identity_provider: "projects/1038484894585/locations/global/workloadIdentityPools/github-wi-pool/providers/github-wi-provider"
service_account: "dsp-artifact-registry-push@dsp-artifact-registry.iam.gserviceaccount.com"
- name: Auth to GAR
uses: docker/login-action@v3
with:
registry: ${{ env.GOOGLE_DOCKER_REPOSITORY }}
username: oauth2accesstoken
password: "${{ steps.gcp-auth.outputs.access_token }}"
- name: Build Docker image
uses: docker/build-push-action@v5
with:
load: true
build-args: |
APP_VERSION=${{ needs.generate-tag.outputs.tag }}
BUILD_VERSION=${{ github.sha }}-${{ github.run_attempt }}
cache-from: type=gha,scope=${{ github.ref_name }}
cache-to: type=gha,scope=${{ github.ref_name }},mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Run Trivy vulnerability scanner
uses: broadinstitute/dsp-appsec-trivy-action@v1
- name: Push Docker image
run: |
docker push ${{ env.GOOGLE_DOCKER_REPOSITORY }}/${{ env.GOOGLE_PROJECT }}/${{ env.REPOSITORY_NAME }}/${{ env.IMAGE_NAME }} --all-tags
# (Optional) Comment pushed image
- name: Comment pushed image
uses: actions/github-script@0.3.0
if: github.event_name == 'pull_request'
with:
github-token: ${{ secrets.BROADBOT_TOKEN }}
script: |
const { issue: { number: issue_number }, repo: { owner, repo } } = context;
github.issues.createComment({ issue_number, owner, repo, body: 'Pushed image: ${{ env.GOOGLE_DOCKER_REPOSITORY }}/${{ env.GOOGLE_PROJECT }}/${{ env.REPOSITORY_NAME }}/${{ env.IMAGE_NAME }}:${{ needs.generate-tag.outputs.tag }}' });
report-to-sherlock:
uses: broadinstitute/sherlock/.github/workflows/client-report-app-version.yaml@main
needs: [build-and-publish, generate-tag]
with:
chart-name: "sfkit"
new-version: ${{ needs.generate-tag.outputs.tag }}
permissions:
contents: "read"
id-token: "write"
set-version-in-terra-dev:
# Put new version in Broad dev environment
uses: broadinstitute/sherlock/.github/workflows/client-set-environment-app-version.yaml@main
needs: [build-and-publish, report-to-sherlock, generate-tag]
if: ${{ github.ref_name == 'dev' }}
with:
new-version: ${{ needs.generate-tag.outputs.tag }}
chart-name: "sfkit"
environment-name: "dev"
secrets:
sync-git-token: ${{ secrets.BROADBOT_TOKEN }}
permissions:
id-token: "write"
# Uncomment this to have success/failure notifications sent to Slack for auto deploys
# report workflow status in slack
# see https://docs.google.com/document/d/1G6-whnNJvON6Qq1b3VvRJFC7M9M-gu2dAVrQHDyp9Us/edit?usp=sharing
# report-workflow:
# uses: broadinstitute/sherlock/.github/workflows/client-report-workflow.yaml@main
# with:
# # Channels to notify upon workflow success or failure
# notify-slack-channels-upon-workflow-completion: '#YOUR_CHANNEL_HERE'
# # Channels to notify upon workflow success only
# # notify-slack-channels-upon-workflow-success: "#channel-here"
# # Channels to notify upon workflow failure only
# # notify-slack-channels-upon-workflow-failure: "#channel-here"
# permissions:
# id-token: 'write'