-
Notifications
You must be signed in to change notification settings - Fork 0
288 lines (245 loc) · 10.5 KB
/
ci-build.yml
File metadata and controls
288 lines (245 loc) · 10.5 KB
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
name: CI Build
on:
workflow_dispatch:
inputs:
push-docker-image-to-harbor:
description: 'Push Docker Image to Harbor'
type: boolean
default: false
pull_request:
push:
branches:
- main
- develop
jobs:
lint-and-unit-test:
name: Lint & Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version: 24.13.1
cache: 'yarn'
- name: Install dependencies
run: |
yarn --immutable
- name: Run linting
run: yarn lint
- name: Run unit tests
run: yarn test
- name: Upload coverage reports to Codecov
if: success()
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
report-type: test_results
e2e-tests:
name: End-to-End (with mock data) Tests
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version: 24.13.1
cache: 'yarn'
- name: Install dependencies
run: |
yarn --immutable
- name: Run e2e tests
run: yarn e2e
- name: Upload Cypress screenshots
if: failure()
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: Inventory management system Screenshots
path: cypress/screenshots
e2e-tests-api:
name: End-to-End (with api) Tests
runs-on: ubuntu-latest
steps:
- name: Clone IMS api repo
uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98
with:
repository: ral-facilities/inventory-management-system-api
ref: develop
# This is required as need to setup api in a different directory as checkout will attempt delete
# all existing files which in this case will include a data directory created by docker causing
# a permission error (checkout action also can't specify a different directory to clone into)
- name: Move IMS api repo
run: |
cd ..
mkdir inventory-management-system-api
mv -v inventory-management-system/* inventory-management-system-api/
cd inventory-management-system-api/
- name: Start MongoDB (For inventory-management-system-api)
working-directory: ../inventory-management-system-api
run: |
docker compose up --detach mongo-db
# Use docker run here to test the actual built image
# Use same network as the MongoDB instance (which is generated by docker compose based on the folder
# name)
- name: Start inventory-management-system-api
run: |
docker run -d --network=host \
--name inventory_management_system_api_container \
--env AUTHENTICATION__ENABLED=false \
--env API__TITLE="Inventory Management System API" \
--env API__DESCRIPTION="This is the API for the Inventory Management System" \
--env DATABASE__PROTOCOL="mongodb" \
--env DATABASE__USERNAME="root" \
--env DATABASE__PASSWORD="example" \
--env DATABASE__HOST_AND_OPTIONS="localhost:27017/?authMechanism=SCRAM-SHA-256&authSource=admin" \
--env DATABASE__NAME="ims" \
--env API__ALLOWED_CORS_HEADERS='["*"]' \
--env API__ALLOWED_CORS_ORIGINS='["*"]' \
--env API__ALLOWED_CORS_METHODS='["*"]' \
--env OBJECT_STORAGE__ENABLED=true \
--env OBJECT_STORAGE__API_REQUEST_TIMEOUT_SECONDS=10 \
--env OBJECT_STORAGE__API_URL=http://localhost:8002 \
--volume /home/runner/work/inventory-management-system/inventory-management-system-api/logging.example.ini:/app/logging.ini \
harbor.stfc.ac.uk/inventory-management-system/ims-api:develop
- name: Clone Object Storage api repo
uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98
with:
repository: ral-facilities/object-storage-api
ref: develop
path: object-storage-api
- name: Move Object Storage api repo
run: |
cd ..
mkdir object-storage-api
mv -v inventory-management-system/* .
cd object-storage-api/
- name: Start MongoDB and MinIO (For object-storage-api)
working-directory: ../object-storage-api
run: |
docker compose up --detach mongo-db minio
sleep 10
- name: Create MinIO buckets (For object-storage-api)
working-directory: ../object-storage-api
run: |
docker compose up minio-create-buckets
- name: Start object-storage-api
run: |
docker run -d -p 8002:8000 \
--name object_storage_api_container \
--network object-storage-api_default \
--env AUTHENTICATION__ENABLED=false \
--env API__TITLE="Object Storage Service API" \
--env API__DESCRIPTION="This is the API for the Object Storage Service" \
--env DATABASE__PROTOCOL="mongodb" \
--env DATABASE__USERNAME="root" \
--env DATABASE__PASSWORD="example" \
--env DATABASE__HOST_AND_OPTIONS="object-storage-api-mongodb:27017" \
--env DATABASE__NAME="object-storage" \
--env API__ALLOWED_CORS_HEADERS='["*"]' \
--env API__ALLOWED_CORS_ORIGINS='["*"]' \
--env API__ALLOWED_CORS_METHODS='["*"]' \
--env OBJECT_STORAGE__ENDPOINT_URL="http://localhost:9000" \
--env OBJECT_STORAGE__ACCESS_KEY="root" \
--env OBJECT_STORAGE__SECRET_ACCESS_KEY="example_password" \
--env OBJECT_STORAGE__BUCKET_NAME="object-storage" \
--env OBJECT_STORAGE__PRESIGNED_URL_EXPIRY_SECONDS=1800 \
--env ATTACHMENT__MAX_SIZE_BYTES=104857600 \
--env IMAGE__THUMBNAIL_MAX_SIZE_PIXELS=300 \
--env ATTACHMENT__ALLOWED_FILE_EXTENSIONS='[".csv", ".doc", ".docx", ".ods", ".odt", ".rtf", ".pdf", ".txt", ".xls", ".xlsx"]' \
--env ATTACHMENT__UPLOAD_LIMIT=50 \
--env IMAGE__ALLOWED_FILE_EXTENSIONS='[".bmp", ".jpe", ".jpeg", ".jpg", ".png", ".tif", ".tiff", ".webp"]' \
--env IMAGE__UPLOAD_LIMIT=100 \
--add-host "localhost:host-gateway" \
--volume /home/runner/work/inventory-management-system/object-storage-api/logging.example.ini:/app/logging.ini \
harbor.stfc.ac.uk/scd-object-storage-api/object-storage-api:develop
- name: Checkout repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version: 24.13.1
cache: 'yarn'
- name: Install dependencies
run: |
yarn --immutable
- name: Run e2e tests
run: yarn e2e:api
- name: Output docker logs (ims mongodb)
if: failure()
run: docker logs ims-api-mongodb
- name: Output docker logs (ims api)
if: failure()
run: docker logs inventory_management_system_api_container
- name: Output docker logs (object-storage mongodb)
if: failure()
run: docker logs object-storage-api-mongodb
- name: Output docker logs (object-storage minio)
if: failure()
run: docker logs object-storage-minio
- name: Output docker logs (object-storage api)
if: failure()
run: docker logs object_storage_api_container
- name: Upload Cypress screenshots
if: failure()
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: Inventory management system (with api) Screenshots
path: cypress/screenshots
bundle_analysis:
# This job triggers only if all the other jobs succeed.
needs: [lint-and-unit-test, e2e-tests, e2e-tests-api]
name: Bundle Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version: 24.13.1
cache: 'yarn'
- name: Install dependencies
run: |
yarn --immutable
- name: Build app for production
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
# Override the value used in the .env.production
run: VITE_INCLUDE_CODECOV=true yarn build
docker:
# This job triggers only if all the other jobs succeed. It builds the Docker image and if successful,
# it pushes it to Harbor.
needs: [lint-and-unit-test, e2e-tests, e2e-tests-api]
name: Docker
runs-on: ubuntu-latest
env:
PUSH_DOCKER_IMAGE_TO_HARBOR: ${{ inputs.push-docker-image-to-harbor != null && inputs.push-docker-image-to-harbor || 'false' }}
steps:
- name: Check out repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Login to Harbor
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ${{ secrets.HARBOR_URL }}
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
with:
images: ${{ secrets.HARBOR_URL }}/ims
- name: ${{ fromJSON(env.PUSH_DOCKER_IMAGE_TO_HARBOR) && 'Build and push Docker image to Harbor' || 'Build Docker image' }}
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
context: .
file: ./Dockerfile.prod
push: ${{ fromJSON(env.PUSH_DOCKER_IMAGE_TO_HARBOR) }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}