-
Notifications
You must be signed in to change notification settings - Fork 51
283 lines (250 loc) · 10 KB
/
deploy.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
name: Deploy
on:
workflow_call:
inputs:
environment:
required: true
type: string
default: "stage"
concurrency:
group: deploy_workflow
cancel-in-progress: false
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
build-node-image:
name: Build node image
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Restore binaries
uses: actions/cache/restore@v4
with:
path: "target/release/node_*er"
key: node-bin-${{ github.sha }}
fail-on-cache-miss: true
- name: Build docker images for node
id: build-image
run: mkdir builds && mv target/release/node_* builds && docker build -f Dockerfile.node_prebuilt . --iidfile imageid && echo imageid=$(cat imageid) >> $GITHUB_OUTPUT
- name: Push image
id: push-image
uses: ./.github/actions/push-img-nucliadb
env:
GCP_WORKLOAD_IDENTITY_PROVIDER: "projects/224545243904/locations/global/workloadIdentityPools/gh-nuclia/providers/gh-nuclia-provider"
GCP_SERVICE_ACCOUNT: "[email protected]"
with:
imageid: ${{ steps.build-image.outputs.imageid }}
image-name: node
aws-ecr-role: ${{ secrets.AWS_ECR_ROLE }}
build-python-images:
name: Build Python images
strategy:
matrix:
include:
- file: Dockerfile
image-name: nucliadb_hosted
- file: Dockerfile.node_sidecar
image-name: node_sidecar
uses: ./.github/workflows/_build-img-nucliadb.yml
with:
file: ${{ matrix.file }}
image-name: ${{ matrix.image-name }}
secrets:
inherit
deploy-nucliadb-shared:
name: Deploy nucliadb shared
runs-on: ubuntu-latest
steps:
- name: Generate a token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.GHAPP_ID_NUCLIABOT }}
private-key: ${{ secrets.PK_GHAPP_NUCLIABOT }}
owner: nuclia
- name: Checkout repository
uses: actions/checkout@v4
- name: Set helm package image
id: version_step
run: |-
VERSION=`cat VERSION`
VERSION_SHA=$VERSION-$(echo $GITHUB_SHA | cut -c1-6)
sed -i.bak "s#99999.99999.99999#$VERSION_SHA#" ./charts/nucliadb_shared/Chart.yaml
echo "version_number=$VERSION_SHA" >> $GITHUB_OUTPUT
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Install Helm
uses: azure/setup-helm@v4
with:
version: v3.15.3
- name: Push helm package
run: |-
helm lint charts/nucliadb_shared
helm package charts/nucliadb_shared
curl --data-binary "@nucliadb_shared-${{ steps.version_step.outputs.version_number }}.tgz" ${{ secrets.HELM_CHART_URL }}/api/charts
# - name: Repository Dispatch
# uses: peter-evans/repository-dispatch@v3
# with:
# token: ${{ steps.app-token.outputs.token }}
# repository: nuclia/nucliadb_deploy
# event-type: promote
# client-payload: '{"component": "nucliadb_shared", "chart-version": "${{ steps.version_step.outputs.version_number }}" }'
- name: Checkout tooling repository
uses: actions/checkout@v4
with:
repository: nuclia/tooling
ref: main
token: ${{ steps.app-token.outputs.token }}
path: /tmp
- name: Debug
run: |
ls -larth
ls -larth /tmp
- name: Promote to Nuclia
uses: /tmp/tooling/.github/actions/promote
with:
component: nucliadb_shared
chart-version: ${{ needs.param.outputs.chart-version }}
environment: ${{ inputs.environment }}
ghapp-nuclia-service-bot-id: ${{ secrets.GHAPP_ID_NUCLIABOT }}
ghapp-nuclia-service-bot-pk: ${{ secrets.PK_GHAPP_NUCLIABOT }}
argocd-appset-file: "./repo-core-apps/apps/nucliadb_shared.applicationSet.yaml"
deploy-nucliadb-node:
name: Deploy Node
runs-on: ubuntu-latest
needs:
- build-python-images
- build-node-image
- deploy-nucliadb-shared
steps:
- name: Generate a token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.GHAPP_ID_NUCLIABOT }}
private-key: ${{ secrets.PK_GHAPP_NUCLIABOT }}
owner: nuclia
- name: Checkout repository
uses: actions/checkout@v4
- name: Calculate short sha
id: env-vars
run: |-
HASH=`git rev-parse --short HEAD`
echo "short_sha=$HASH" >> $GITHUB_OUTPUT
- name: Set helm package image
id: version_step
env:
CONTAINER_REGISTRY: europe-west4-docker.pkg.dev/nuclia-internal/nuclia
run: |-
sed -i.bak "s#IMAGE_TO_REPLACE#node:${{ steps.env-vars.outputs.short_sha }}#" ./charts/nucliadb_node/values.yaml
sed -i.bak "s#IMAGE_SIDECAR_TO_REPLACE#node_sidecar:${{ steps.env-vars.outputs.short_sha }}#" ./charts/nucliadb_node/values.yaml
sed -i.bak "s#CONTAINER_REGISTRY_TO_REPLACE#$CONTAINER_REGISTRY#" ./charts/nucliadb_node/values.yaml
VERSION=`cat VERSION`
VERSION_SHA=$VERSION-${{ steps.env-vars.outputs.short_sha }}
sed -i.bak "s#99999.99999.99999#$VERSION_SHA#" ./charts/nucliadb_node/Chart.yaml
echo "version_number=$VERSION_SHA" >> $GITHUB_OUTPUT
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Install Helm
uses: azure/setup-helm@v4
with:
version: v3.15.3
- name: Push helm package
run: |-
helm lint charts/nucliadb_node
helm package charts/nucliadb_node
curl --data-binary "@nucliadb_node-${{ steps.version_step.outputs.version_number }}.tgz" ${{ secrets.HELM_CHART_URL }}/api/charts
# - name: Repository Dispatch
# uses: peter-evans/repository-dispatch@v3
# with:
# token: ${{ steps.app-token.outputs.token }}
# repository: nuclia/nucliadb_deploy
# event-type: promote
# client-payload: '{"component": "nucliadb_node", "chart-version": "${{ steps.version_step.outputs.version_number }}" }'
# - name: Promote to Nuclia
# uses: nuclia/tooling/.github/actions/promote@main
# with:
# component: nucliadb_node
# chart-version: ${{ needs.param.outputs.chart-version }}
# environment: ${{ inputs.environment }}
# ghapp-nuclia-service-bot-id: ${{ secrets.GHAPP_ID_NUCLIABOT }}
# ghapp-nuclia-service-bot-pk: ${{ secrets.PK_GHAPP_NUCLIABOT }}
# argocd-appset-file: "./repo-core-apps/apps/nucliadb_node.applicationSet.yaml"
deploy-nucliadb-component:
name: Deploy NucliaDB component
runs-on: ubuntu-latest
needs:
- build-python-images
- deploy-nucliadb-shared
strategy:
# nucliadb_deploy pipeline has issues with too many parallel invocations
max-parallel: 1
fail-fast: false
matrix:
component:
- ingest
- reader
- search
- train
- writer
steps:
- name: Generate a token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.GHAPP_ID_NUCLIABOT }}
private-key: ${{ secrets.PK_GHAPP_NUCLIABOT }}
owner: nuclia
- name: Checkout repository
uses: actions/checkout@v4
- name: Calculate short sha
id: env-vars
run: |-
HASH=`git rev-parse --short HEAD`
echo "short_sha=$HASH" >> $GITHUB_OUTPUT
- name: Set helm package image
id: version_step
env:
CONTAINER_REGISTRY: europe-west4-docker.pkg.dev/nuclia-internal/nuclia
run: |-
sed -i.bak "s#IMAGE_TO_REPLACE#nucliadb_hosted:${{ steps.env-vars.outputs.short_sha }}#" ./charts/nucliadb_${{ matrix.component }}/values.yaml
sed -i.bak "s#CONTAINER_REGISTRY_TO_REPLACE#$CONTAINER_REGISTRY#" ./charts/nucliadb_${{ matrix.component }}/values.yaml
VERSION=`cat VERSION`
VERSION_SHA=$VERSION-${{ steps.env-vars.outputs.short_sha }}
sed -i.bak "s#99999.99999.99999#$VERSION_SHA#" ./charts/nucliadb_${{ matrix.component }}/Chart.yaml
echo "version_number=$VERSION_SHA" >> $GITHUB_OUTPUT
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Install Helm
uses: azure/setup-helm@v4
with:
version: v3.15.3
- name: Push helm package
run: |-
helm lint charts/nucliadb_${{ matrix.component }}
helm package charts/nucliadb_${{ matrix.component }}
curl --data-binary "@nucliadb_${{ matrix.component }}-${{ steps.version_step.outputs.version_number }}.tgz" ${{ secrets.HELM_CHART_URL }}/api/charts
# - name: Repository Dispatch
# uses: peter-evans/repository-dispatch@v3
# with:
# token: ${{ steps.app-token.outputs.token }}
# repository: nuclia/nucliadb_deploy
# event-type: promote
# client-payload: '{"component": "nucliadb_${{ matrix.component }}", "chart-version": "${{ steps.version_step.outputs.version_number }}" }'
# - name: Promote to Nuclia
# uses: nuclia/tooling/.github/actions/promote@main
# with:
# component: nucliadb_${{ matrix.component }}
# chart-version: ${{ needs.param.outputs.chart-version }}
# environment: ${{ inputs.environment }}
# ghapp-nuclia-service-bot-id: ${{ secrets.GHAPP_ID_NUCLIABOT }}
# ghapp-nuclia-service-bot-pk: ${{ secrets.PK_GHAPP_NUCLIABOT }}
# argocd-appset-file: "./repo-core-apps/apps/nucliadb_${{ matrix.component }}.applicationSet.yaml"