forked from Sefaria/Sefaria-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
170 lines (168 loc) · 6.13 KB
/
continuous.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
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
name: Continuous
on:
push:
pull_request:
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
duplication-check:
runs-on: ubuntu-latest
outputs:
inPR: ${{ steps.check.outputs.number != '' }}
steps:
- name: Check if push is in PR
id: check
uses: 8BitJonny/[email protected]
with:
filterOutClosed: true
github-token: ${{ secrets.GITHUB_TOKEN }}
build-generic:
permissions:
contents: 'read'
id-token: 'write'
runs-on: ubuntu-latest
needs: duplication-check
if: ${{ github.event_name == 'pull_request' || ( github.event_name == 'push' && needs.duplication-check.outputs.inPR == 'false' ) }}
strategy:
matrix:
app: [ web, node ]
steps:
- uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- id: auth
name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
token_format: 'access_token'
workload_identity_provider: 'projects/${{ secrets.CONTEXTUS_GKE_PROJECT_ID}}/locations/global/workloadIdentityPools/github/providers/github'
service_account: '${{ secrets.CONTEXTUS_GKE_SA }}'
- name: Login to GCR
uses: docker/login-action@v1
with:
registry: gcr.io
username: oauth2accesstoken
password: '${{ steps.auth.outputs.access_token }}'
- name: Login to GAR
uses: docker/login-action@v1
with:
registry: us-east1-docker.pkg.dev
username: oauth2accesstoken
password: '${{ steps.auth.outputs.access_token }}'
- name: Get branch name
id: branch-raw
uses: tj-actions/[email protected]
- name: Format branch name
id: branch-name
run: >-
echo "current_branch="$(echo ${{ steps.branch-raw.outputs.current_branch }}
| awk '{print tolower($0)}'
| sed 's|.*/\([^/]*\)/.*|\1|; t; s|.*|\0|'
| sed 's/[^a-z0-9\.\-]//g')
>> $GITHUB_OUTPUT
- name: Get current date
id: date
run: echo "date=$(date +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT
- name: Generate image metadata
id: meta
uses: docker/metadata-action@v3
with:
images: |
us-east1-docker.pkg.dev/${{ secrets.PROD_GKE_PROJECT }}/containers/contextus-${{ matrix.app }}-${{ steps.branch-name.outputs.current_branch }}
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=sha,enable=true,priority=100,prefix=sha-,suffix=-${{ steps.date.outputs.date }},format=short
type=sha
flavor: |
latest=true
- name: build and push
uses: docker/build-push-action@v3
with:
context: .
push: true
build-args: |
TYPE=build
file: ./build/${{ matrix.app }}/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-derived:
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
needs:
- duplication-check
- build-generic
strategy:
matrix:
app: [ asset, linker ]
if: ${{ github.event_name == 'pull_request' || ( github.event_name == 'push' && needs.duplication-check.outputs.inPR == 'false' ) }}
steps:
- uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- id: auth
name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
token_format: 'access_token'
workload_identity_provider: 'projects/${{ secrets.CONTEXTUS_GKE_PROJECT_ID}}/locations/global/workloadIdentityPools/github/providers/github'
service_account: '${{ secrets.CONTEXTUS_GKE_SA }}'
- name: Login to GCR
uses: docker/login-action@v1
with:
registry: gcr.io
username: oauth2accesstoken
password: '${{ steps.auth.outputs.access_token }}'
- name: Login to GAR
uses: docker/login-action@v1
with:
registry: us-east1-docker.pkg.dev
username: oauth2accesstoken
password: '${{ steps.auth.outputs.access_token }}'
- name: Get branch name
id: branch-raw
uses: tj-actions/[email protected]
- name: Format branch name
id: branch-name
run: >-
echo "current_branch="$(echo ${{ steps.branch-raw.outputs.current_branch }}
| awk '{print tolower($0)}'
| sed 's|.*/\([^/]*\)/.*|\1|; t; s|.*|\0|'
| sed 's/[^a-z0-9\.\-]//g')
>> $GITHUB_OUTPUT
- name: Get current date
id: date
run: echo "date=$(date +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT
- name: Generate image metadata
id: meta
uses: docker/metadata-action@v3
with:
images: |
us-east1-docker.pkg.dev/${{ secrets.PROD_GKE_PROJECT }}/containers/contextus-${{ matrix.app }}-${{ steps.branch-name.outputs.current_branch }}
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=sha,enable=true,priority=100,prefix=sha-,suffix=-${{ steps.date.outputs.date }},format=short
type=sha
flavor: |
latest=true
- name: Set outputs
id: get-sha
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: build and push
uses: docker/build-push-action@v3
with:
context: .
push: true
build-args: |
SRC_IMG=us-east1-docker.pkg.dev/${{ secrets.PROD_GKE_PROJECT }}/containers/contextus-web-${{ steps.branch-name.outputs.current_branch }}:sha-${{ steps.get-sha.outputs.sha_short }}
file: ./build/${{ matrix.app }}/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}