-
Notifications
You must be signed in to change notification settings - Fork 9
364 lines (317 loc) · 13.9 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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
name: Deploy
on:
push:
branches:
- main
- dev
env:
APP_IMAGE_NAME: app
ARTIFACT_REGISTRY_URL: oci://europe-west4-docker.pkg.dev/nuclia-internal/charts
MANAGER_IMAGE_NAME: manager
CDN_STORAGE: ${{ github.ref == 'refs/heads/main' && secrets.CDN_STORAGE || secrets.CDN_STORAGE_DEV }}
DOCS_STORAGE: ${{ github.ref == 'refs/heads/main' && secrets.DOCS_STORAGE || secrets.DOCS_STORAGE_DEV }}
GCP_WORKLOAD_IDENTITY_PROVIDER: 'projects/224545243904/locations/global/workloadIdentityPools/gh-nuclia/providers/gh-nuclia-provider'
GCP_SERVICE_ACCOUNT: '[email protected]'
DEPLOYMENT_ENVIRONMENT: ${{ github.ref == 'refs/heads/main' && 'stage' || 'dev' }}
PROMO_PRODUCTION: false
permissions:
id-token: write
contents: write
jobs:
build:
runs-on: ubuntu-latest
outputs:
deploy-widget: ${{ steps.check-deploy.outputs.deploy-widget }}
deploy-app: ${{ steps.check-deploy.outputs.deploy-app }}
deploy-nucliadb-admin: ${{ steps.check-deploy.outputs.deploy-nucliadb-admin }}
deploy-manager: ${{ steps.check-deploy.outputs.deploy-manager }}
deploy-sistema: ${{ steps.check-deploy.outputs.deploy-sistema }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Authenticate to Google Cloud
id: gcp-auth
uses: google-github-actions/auth@v2
with:
workload_identity_provider: '${{ env.GCP_WORKLOAD_IDENTITY_PROVIDER }}'
service_account: '${{ env.GCP_SERVICE_ACCOUNT }}'
token_format: access_token
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v2'
- name: Login to Google Artifact Registry
uses: docker/login-action@v3
with:
registry: europe-west4-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.gcp-auth.outputs.access_token }}
- uses: nrwl/nx-set-shas@v3
- uses: actions/setup-node@v3
with:
node-version: 20
cache: 'yarn'
- name: Calculate short sha
run: echo "SHORT_SHA=`echo hash${GITHUB_SHA} | cut -c1-12`" >> $GITHUB_ENV
- name: Install project dependencies
run: |-
yarn
yarn missdev
- name: Unit tests
run: npx nx affected --target=test --parallel=3 --exclude=sdk-demo,search-widget-demo,core,sistema-demo
- name: Build affected apps
run: npx nx affected --target=build --parallel=3 --configuration production --exclude=sdk-demo,search-widget-demo
- name: Get package version
run: node -p -e '`PACKAGE_VERSION=${require("./package.json").version}`' >> $GITHUB_ENV
- name: Tag if new version
uses: pkgdeps/[email protected]
if: github.ref == 'refs/heads/main'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
github_repo: ${{ github.repository }}
version: ${{ env.PACKAGE_VERSION }}
git_commit_sha: ${{ github.sha }}
git_tag_prefix: 'v'
- name: Check apps to deploy
id: check-deploy
run: |-
(test -d dist/libs/search-widget && echo "deploy-widget=yes" >> $GITHUB_OUTPUT) || echo "Widget unchanged"
(test -d dist/apps/dashboard && echo "deploy-app=yes" >> $GITHUB_OUTPUT) || echo "Dashboard unchanged"
(test -d dist/apps/nucliadb-admin && echo "deploy-nucliadb-admin=yes" >> $GITHUB_OUTPUT) || echo "NucliaDB admin unchanged"
(test -d dist/apps/manager-v2 && echo "deploy-manager=yes" >> $GITHUB_OUTPUT) || echo "Manager unchanged"
(test -d dist/apps/sistema-demo && echo "deploy-sistema=yes" >> $GITHUB_OUTPUT) || echo "Sistema demo unchanged"
(test -d dist/sdk-core && echo "deploy-sdk=yes" >> $GITHUB_OUTPUT) || echo "SDK unchanged"
- name: Publish widget
if: steps.check-deploy.outputs.deploy-widget == 'yes'
run: |-
find dist/libs/search-widget -type f -name *.umd.js -exec sed -i.bak "s,__NUCLIA_DEV_VERSION__,$GITHUB_SHA,g" {} \;
gsutil copy dist/libs/search-widget/*.umd.js gs://$CDN_STORAGE
gsutil copy dist/libs/search-widget/*.css gs://$CDN_STORAGE
gsutil copy -r libs/search-widget/public/* gs://$CDN_STORAGE
- name: Publish SDK
if: steps.check-deploy.outputs.deploy-sdk == 'yes' && github.ref == 'refs/heads/main'
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
package: ./dist/sdk-core/package.json
- name: Generate and push SDK docs
if: steps.check-deploy.outputs.deploy-sdk == 'yes' && github.ref == 'refs/heads/main'
run: |-
sh ./tools/build-sdk-docs.sh
gsutil -m rsync -r ./libs/sdk-core/docs gs://$DOCS_STORAGE/js-sdk
- name: Build dashboard image for Artifact Repository
if: steps.check-deploy.outputs.deploy-app == 'yes'
env:
CONTAINER_REGISTRY: europe-west4-docker.pkg.dev/nuclia-internal/private
run: |-
docker build -t $CONTAINER_REGISTRY/$APP_IMAGE_NAME:${SHORT_SHA} -f docker/Dockerfile --build-arg appId=app --build-arg appFolder=dashboard --build-arg noRelativeCss=true .
docker tag $CONTAINER_REGISTRY/$APP_IMAGE_NAME:${SHORT_SHA} $CONTAINER_REGISTRY/$APP_IMAGE_NAME:main
docker push $CONTAINER_REGISTRY/$APP_IMAGE_NAME:${SHORT_SHA}
docker push $CONTAINER_REGISTRY/$APP_IMAGE_NAME:main
- name: Publish NucliaDB admin app
if: steps.check-deploy.outputs.deploy-nucliadb-admin == 'yes' && github.ref == 'refs/heads/main'
run: |-
sed -i.bak "s,STF_DOCKER_CONFIG_VERSION,$GITHUB_SHA,g" dist/apps/nucliadb-admin/assets/deployment/app-config.json
cp -r dist/apps/nucliadb-admin/* tools/python-nucliadb-admin-dist/nucliadb_admin_assets/
make -C tools/python-nucliadb-admin-dist/ publish ARGS="--build=${{github.run_number}}"
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
- name: Build manager image for Artifact Repository
if: steps.check-deploy.outputs.deploy-manager == 'yes'
env:
CONTAINER_REGISTRY: europe-west4-docker.pkg.dev/nuclia-internal/private
run: |-
docker build -t $CONTAINER_REGISTRY/$MANAGER_IMAGE_NAME:${SHORT_SHA} -f docker/Dockerfile --build-arg appId=manager --build-arg appFolder=manager-v2 --build-arg noRelativeCss=true .
docker tag $CONTAINER_REGISTRY/$MANAGER_IMAGE_NAME:${SHORT_SHA} $CONTAINER_REGISTRY/$MANAGER_IMAGE_NAME:main
docker push $CONTAINER_REGISTRY/$MANAGER_IMAGE_NAME:${SHORT_SHA}
docker push $CONTAINER_REGISTRY/$MANAGER_IMAGE_NAME:main
- name: Create 404 page for gh-pages
if: steps.check-deploy.outputs.deploy-sistema == 'yes' && github.ref == 'refs/heads/main'
run: |-
cp dist/apps/sistema-demo/index.html dist/apps/sistema-demo/404.html
- name: Deploy sistema-demo to GH pages
if: steps.check-deploy.outputs.deploy-sistema == 'yes' && github.ref == 'refs/heads/main'
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: dist/apps/sistema-demo
- name: Upload sourcemaps to Sentry
uses: getsentry/[email protected]
if: github.ref == 'refs/heads/main'
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: nuclia
SENTRY_PROJECT: application
deploy-app:
name: Deploy dashboard
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.deploy-app == 'yes'
outputs:
json-summary: |
{
"components": [
{
"component": "app",
"chart-version": "${{ steps.version_step.outputs.version_number }}",
"component-type": "global"
}
]
}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Authenticate to Google Cloud
id: gcp-auth
uses: google-github-actions/auth@v2
with:
workload_identity_provider: "${{ env.GCP_WORKLOAD_IDENTITY_PROVIDER }}"
service_account: "${{ env.GCP_SERVICE_ACCOUNT }}"
token_format: access_token
- name: Login to Google Artifact Registry
uses: docker/login-action@v3
with:
registry: europe-west4-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.gcp-auth.outputs.access_token }}
- name: Calculate short sha
run: echo "SHORT_SHA=`echo hash${GITHUB_SHA} | cut -c1-12`" >> $GITHUB_ENV
- 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#$APP_IMAGE_NAME:${SHORT_SHA}#" ./charts/app/values.yaml
sed -i.bak "s#CONTAINER_REGISTRY_TO_REPLACE#$CONTAINER_REGISTRY#" ./charts/app/values.yaml
VERSION=`cat apps/dashboard/VERSION`
VERSION_SHA=$VERSION-${SHORT_SHA}
sed -i.bak "s#99999.99999.99999#$VERSION_SHA#" ./charts/app/Chart.yaml
echo "version_number=$VERSION_SHA" >> $GITHUB_OUTPUT
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: v3.15.3
- name: Push helm package
run: |-
helm lint charts/app
helm package charts/app
helm push app-${{ steps.version_step.outputs.version_number }}.tgz ${{ env.ARTIFACT_REGISTRY_URL }}
deploy-manager:
name: Deploy manager
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.deploy-manager == 'yes'
outputs:
json-summary: |
{
"components": [
{
"component": "manager",
"chart-version": "${{ steps.version_step.outputs.version_number }}",
"component-type": "global"
}
]
}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Authenticate to Google Cloud
id: gcp-auth
uses: google-github-actions/auth@v2
with:
workload_identity_provider: "${{ env.GCP_WORKLOAD_IDENTITY_PROVIDER }}"
service_account: "${{ env.GCP_SERVICE_ACCOUNT }}"
token_format: access_token
- name: Login to Google Artifact Registry
uses: docker/login-action@v3
with:
registry: europe-west4-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.gcp-auth.outputs.access_token }}
- name: Calculate short sha
run: echo "SHORT_SHA=`echo hash${GITHUB_SHA} | cut -c1-12`" >> $GITHUB_ENV
- 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#$MANAGER_IMAGE_NAME:${SHORT_SHA}#" ./charts/manager/values.yaml
sed -i.bak "s#CONTAINER_REGISTRY_TO_REPLACE#$CONTAINER_REGISTRY#" ./charts/manager/values.yaml
VERSION=`cat apps/manager-v2/VERSION`
VERSION_SHA=$VERSION-$SHORT_SHA
sed -i.bak "s#99999.99999.99999#$VERSION_SHA#" ./charts/manager/Chart.yaml
echo "version_number=$VERSION_SHA" >> $GITHUB_OUTPUT
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: v3.15.3
- name: Push helm package
run: |-
helm lint charts/manager
helm package charts/manager
helm push manager-${{ steps.version_step.outputs.version_number }}.tgz ${{ env.ARTIFACT_REGISTRY_URL }}
send-to-promotion:
runs-on: ubuntu-latest
needs: [deploy-manager, deploy-app]
if: |
!failure() && !cancelled() && github.event_name == 'push' &&
( needs.deploy-manager.result != 'skipped' ||
needs.deploy-app.result != 'skipped' )
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: Create components promotion summary. Trigger1
env:
SKIP_QUEUE: ${{ contains(github.event.pull_request.labels.*.name, 'skip-promo-queue') }}
SKIP_ARGO_HEALTH: false
ENVIRONMENT: ${{ github.ref == 'refs/heads/main' && 'stage' || 'dev' }}
PROMO_PRODUCTION: ${{ env.PROMO_PRODUCTION }}
TEAM: ${{ secrets.TEAM_NAME }}
SLACK_TEAM: ${{ secrets.SLACK_TEAM }}
run: |
MERGED_JSON=$(jq -cs \
--arg environment "$ENVIRONMENT" \
--arg skip_queue "$SKIP_QUEUE" \
--arg promo_production "$PROMO_PRODUCTION" \
--arg team "$TEAM" \
--arg slack_team "$SLACK_TEAM" \
--arg skip_argo_health "$SKIP_ARGO_HEALTH" \
--arg commit_sha "${{ github.sha }}" \
'{
components: map(.components) | add
} + {
skip_promo_queue: ($skip_queue == "true")
} + {
skip_argo_health: ($skip_argo_health == "true")
} + {
environment: $environment
} + {
promo_production: ($promo_production == "true")
} + {
team: $team
} + {
slack_team: $slack_team
} + {
tests: {
"run-e2e": true,
"run-nua-e2e": false
}
} + {
"commit-sha": $commit_sha
}' \
<(echo '${{ needs.deploy-manager.outputs.json-summary }}') \
<(echo '${{ needs.deploy-app.outputs.json-summary }}')
)
echo "JSON_PROMO_SUMMARY=$MERGED_JSON" >> $GITHUB_ENV
- name: Send to promotion queue
id: send-to-promo
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ steps.app-token.outputs.token }}
repository: nuclia/core-apps
event-type: promotions
client-payload: '${{ env.JSON_PROMO_SUMMARY }}'