-
Notifications
You must be signed in to change notification settings - Fork 51
346 lines (291 loc) · 9.42 KB
/
nucliadb_node.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
name: nucliadb Node (rust + python)
on:
pull_request:
branches:
- main
paths:
- ".github/workflows/nucliadb_node.yml"
- "charts/nucliadb_node/**"
- "Dockerfile.node"
- "Dockerfile.node_sidecar"
- "Cargo.lock"
- "Cargo.toml"
- "nucliadb_paragraphs/**"
- "nucliadb_texts/**"
- "nucliadb_core/**"
- "nucliadb_telemetry/**"
- "nucliadb_node/**"
- "nucliadb_vectors/**"
- "nucliadb_texts/**"
- "nucliadb_paragraphs/**"
- "nucliadb_core/**"
- "nucliadb_relations/**"
- 'nucliadb_relations2/**'
push:
branches:
- main
paths:
- ".github/workflows/nucliadb_node.yml"
- "charts/nucliadb_node/**"
- "Dockerfile.node"
- "Dockerfile.node_sidecar"
- "Dockerfile.basenode"
- "Cargo.lock"
- "Cargo.toml"
- "nucliadb_paragraphs/**"
- "nucliadb_texts/**"
- "nucliadb_core/**"
- "nucliadb_telemetry/**"
- "nucliadb_node/**"
- "nucliadb_node_binding/**"
- "nucliadb_vectors/**"
- "nucliadb_relations/**"
- 'nucliadb_relations2/**'
- "nucliadb_telemetry/src/**"
- "nucliadb_utils/**"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
env:
RUSTFLAGS: -Dwarnings
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always
COMPONENT: nucliadb-node
CONTAINER_REGISTRY: eu.gcr.io/${{ secrets.PROJECT_ID }}
IMAGE_NAME_BASE_NODE: basenode
IMAGE_NAME_NODE: node
IMAGE_NAME_NODE_SIDECAR: node_sidecar
jobs:
pre-checks-python:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install package
run: make -C nucliadb_node/ install-dev
- name: Run pre-checks
run: make -C nucliadb_node/ lint
licenses:
name: Check Licenses
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1
name: cargo deny
with:
log-level: warn
command: check licenses
format-rust:
name: Rust code Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
components: rustfmt
override: true
- uses: Swatinem/rust-cache@v2
- name: rustfmt
run: make fmt-check-package PACKAGE=nucliadb_node
clippy-rust:
name: Clippy lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check system
run: make -C nucliadb_node/ check-system
- run: rustup component add clippy
- uses: Swatinem/rust-cache@v2
- uses: actions-rs/clippy-check@v1
env:
RUSTFLAGS: --cfg tokio_unstable
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: -p nucliadb_node --tests
tests-rust:
name: Rust tests
runs-on: ubuntu-latest
needs: [clippy-rust, format-rust, licenses]
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
with:
shared-key: "test_prebuild"
- name: Check system
run: make -C nucliadb_node/ check-system
- uses: actions-rs/cargo@v1
env:
DEBUG: 1
RUST_BACKTRACE: 1
RUSTFLAGS: --cfg tokio_unstable
name: cargo test
with:
command: test
args: --workspace --all-features
tests-python:
name: Python tests
runs-on: ubuntu-latest
needs: [pre-checks-python, licenses]
strategy:
matrix:
python-version: ["3.11"]
steps:
- name: Checkout the repository
uses: actions/checkout@v3
# Setup gcloud CLI
- uses: google-github-actions/auth@v1
with:
credentials_json: "${{ secrets.GCP_CREDENTIALS }}"
- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v1"
# setup docker, as we need to pull the node image to run the tests
- name: Configure Docker
run: docker login -u oauth2accesstoken -p "$(gcloud auth application-default print-access-token)" https://eu.gcr.io
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install the package
run: make -C nucliadb_node/ install-dev
- name: Calc git info
id: git
run: |-
BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
- name: Install jq
run: |
sudo apt-get update -y
sudo apt-get install -y jq
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
node_modified:
- 'nucliadb_core/**'
- 'nucliadb_node/src/**'
- 'nucliadb_paragraphs/**'
- 'nucliadb_procs/**'
- 'nucliadb_relations/**'
- 'nucliadb_relations2/**'
- 'nucliadb_telemetry/**'
- 'nucliadb_texts/**'
- 'nucliadb_vectors/**'
- name: Build local Node for testing
if: steps.filter.outputs.node_modified == 'true'
env:
SECRET_KEY: ${{ secrets.RUST_BUILD_SERVER_SECRET }}
COMMIT_HASH: ${{ github.event.pull_request.head.sha || github.sha }}
BRANCH: ${{ steps.git.outputs.branch }}
run: |
make build-node-debug
- name: Run tests
run: |
pytest -rfE --cov=nucliadb_node -s --tb=native -v --cov-report xml --cov-append nucliadb_node/nucliadb_node
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: node-sidecar
dockerfile-changes:
name: Check if dockerfiles have changed
runs-on: ubuntu-latest
outputs:
basenode: ${{ steps.changes.outputs.basenode_dockerfile }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Check if dockerfile have changed
id: changes
uses: dorny/paths-filter@v2
with:
filters: |
basenode_dockerfile:
- 'Dockerfile.basenode'
build-base-rust:
name: Build and push base image
needs: [ dockerfile-changes, tests-rust ]
uses: ./.github/workflows/_build-img-nucliadb.yml
with:
skip: ${{ ! needs.dockerfile-changes.outputs.basenode }}
file: Dockerfile.basenode
image-name: basenode
cache-gha-mode: min
secrets:
inherit
if: github.event_name == 'push'
build-rust:
name: Build and push index node docker image
needs: build-base-rust
uses: ./.github/workflows/_build-img-nucliadb.yml
with:
file: Dockerfile.node
image-name: node
secrets:
inherit
if: github.event_name == 'push'
build-python:
name: Build and push sidecar docker image
needs: tests-python
uses: ./.github/workflows/_build-img-nucliadb.yml
with:
context: .
file: Dockerfile.node_sidecar
image-name: node_sidecar
cache-gha-mode: min
secrets:
inherit
if: github.event_name == 'push'
deploy:
name: Deploy Helm chart and trigger internal CI
runs-on: ubuntu-latest
needs: [build-rust, build-python]
if: github.event_name == 'push'
steps:
- name: Checkout repository
uses: actions/checkout@v3
- 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
run: |-
sed -i.bak "s#IMAGE_TO_REPLACE#$IMAGE_NAME_NODE:${{ steps.env-vars.outputs.short_sha }}#" ./charts/nucliadb_node/values.yaml
sed -i.bak "s#IMAGE_SIDECAR_TO_REPLACE#$IMAGE_NAME_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@v3
with:
version: v3.4.0
- 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@v2
with:
token: ${{ secrets.GH_CICD_PUBLIC }}
repository: nuclia/nucliadb_deploy
event-type: promote
client-payload: '{"component": "nucliadb_node", "chart-version": "${{ steps.version_step.outputs.version_number }}" }'