-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskfile.yml
268 lines (245 loc) · 9.72 KB
/
Taskfile.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
version: "3"
vars:
COMPOSE_PROJECT_NAME: moderateapi
TESTS_COMPOSE_PROJECT_NAME: moderateapi_tests
TESTS_POSTGRES_USER: postgres
TESTS_POSTGRES_PASSWORD: postgres
TESTS_POSTGRES_DB: testsmoderateapi
TESTS_POSTGRES_PUBLIC_PORT: 15432
TESTS_POSTGRES_URL: postgresql+asyncpg://{{.TESTS_POSTGRES_USER}}:{{.TESTS_POSTGRES_PASSWORD}}@localhost:{{.TESTS_POSTGRES_PUBLIC_PORT}}/{{.TESTS_POSTGRES_DB}}
TESTS_MINIO_PUBLIC_PORT: 19000
TESTS_MINIO_PUBLIC_PORT_CONSOLE: 19001
TESTS_MINIO_ROOT_USER: minio
TESTS_MINIO_ROOT_PASSWORD: minio123
TESTS_MINIO_REGION: eu-central-1
TESTS_MINIO_BUCKET_NAME: moderateapi-tests
TESTS_MINIO_ENDPOINT_URL: http://localhost:{{.TESTS_MINIO_PUBLIC_PORT}}
TESTS_RABBIT_DEFAULT_USER: guest
TESTS_RABBIT_DEFAULT_PASS: guest
TESTS_RABBIT_PUBLIC_PORT: 35672
TESTS_RABBIT_PUBLIC_PORT_MANAGEMENT: 45672
TESTS_RABBIT_URL: amqp://{{.TESTS_RABBIT_DEFAULT_USER}}:{{.TESTS_RABBIT_DEFAULT_PASS}}@localhost:{{.TESTS_RABBIT_PUBLIC_PORT}}/
DEV_KEYCLOAK_PORT: '{{default "8989" .DEV_KEYCLOAK_PORT}}'
DEV_POSTGRES_PORT: '{{default "5433" .DEV_POSTGRES_PORT}}'
MAIN_IP_ADDRESS:
sh: ip route get 1.2.3.4 | awk '{print $7}'
TRUST_COMPOSE_PROJECT_NAME: moderate-trust
TRUST_MONGO_PORT: 27117
TRUST_API_PORT: 8081
TRUST_API_URL: http://{{.MAIN_IP_ADDRESS}}:{{.TRUST_API_PORT}}
KC_HOSTNAME_URL: http://localhost:{{.DEV_KEYCLOAK_PORT}}
env:
COMPOSE_PROJECT_NAME: "{{.COMPOSE_PROJECT_NAME}}"
TESTS_POSTGRES_USER: "{{.TESTS_POSTGRES_USER}}"
TESTS_POSTGRES_PASSWORD: "{{.TESTS_POSTGRES_PASSWORD}}"
TESTS_POSTGRES_DB: "{{.TESTS_POSTGRES_DB}}"
TESTS_POSTGRES_PUBLIC_PORT: "{{.TESTS_POSTGRES_PUBLIC_PORT}}"
TESTS_POSTGRES_URL: "{{.TESTS_POSTGRES_URL}}"
TESTS_MINIO_PUBLIC_PORT: "{{.TESTS_MINIO_PUBLIC_PORT}}"
TESTS_MINIO_PUBLIC_PORT_CONSOLE: "{{.TESTS_MINIO_PUBLIC_PORT_CONSOLE}}"
TESTS_MINIO_ROOT_USER: "{{.TESTS_MINIO_ROOT_USER}}"
TESTS_MINIO_ROOT_PASSWORD: "{{.TESTS_MINIO_ROOT_PASSWORD}}"
TESTS_MINIO_REGION: "{{.TESTS_MINIO_REGION}}"
TESTS_MINIO_BUCKET_NAME: "{{.TESTS_MINIO_BUCKET_NAME}}"
TESTS_MINIO_ENDPOINT_URL: "{{.TESTS_MINIO_ENDPOINT_URL}}"
TESTS_RABBIT_DEFAULT_USER: "{{.TESTS_RABBIT_DEFAULT_USER}}"
TESTS_RABBIT_DEFAULT_PASS: "{{.TESTS_RABBIT_DEFAULT_PASS}}"
TESTS_RABBIT_PUBLIC_PORT: "{{.TESTS_RABBIT_PUBLIC_PORT}}"
TESTS_RABBIT_PUBLIC_PORT_MANAGEMENT: "{{.TESTS_RABBIT_PUBLIC_PORT_MANAGEMENT}}"
TESTS_RABBIT_URL: "{{.TESTS_RABBIT_URL}}"
DEV_KEYCLOAK_PORT: "{{.DEV_KEYCLOAK_PORT}}"
DEV_POSTGRES_PORT: "{{.DEV_POSTGRES_PORT}}"
MODERATE_API_S3__ACCESS_KEY: "{{.MINIO_ROOT_USER}}"
MODERATE_API_S3__SECRET_KEY: "{{.MINIO_ROOT_PASSWORD}}"
MODERATE_API_S3__ENDPOINT_URL: http://minio:9000
MODERATE_API_S3__REGION: "{{.MINIO_REGION}}"
MODERATE_API_S3__BUCKET: "{{.MINIO_BUCKET_NAME}}"
MODERATE_API_TRUST_SERVICE__ENDPOINT_URL: "{{.TRUST_API_URL}}"
KC_HOSTNAME_URL: "{{.KC_HOSTNAME_URL}}"
dotenv: [.env.dev, .env.dev.default]
tasks:
dev-up:
desc: Start the development stack
cmds:
- task: trust-up
- docker compose -f {{.ROOT_DIR}}/docker-compose-dev.yml up -d --build
dev-up-gcs:
desc: Start the development stack using GCS instead of the local MinIO
requires:
vars: [ACCESS_KEY, SECRET_KEY]
env:
MODERATE_API_S3__ACCESS_KEY: "{{.ACCESS_KEY}}"
MODERATE_API_S3__SECRET_KEY: "{{.SECRET_KEY}}"
MODERATE_API_S3__ENDPOINT_URL: https://storage.googleapis.com
MODERATE_API_S3__REGION: '{{default "europe-west1" .GCS_REGION}}'
MODERATE_API_S3__BUCKET: '{{default "moderateapi-tests" .GCS_BUCKET}}'
cmds:
- task: trust-up
- docker compose -f {{.ROOT_DIR}}/docker-compose-dev.yml up -d --build
dev-down:
desc: Stop and remove all traces of the development stack
cmds:
- docker compose -f {{.ROOT_DIR}}/docker-compose-dev.yml down -v
- task: trust-down
test-deps-up:
desc: Start the services needed for testing
cmds:
- >
docker compose
-p {{.TESTS_COMPOSE_PROJECT_NAME}}
-f {{.ROOT_DIR}}/docker-compose-tests.yml
up -d --build --wait
test-deps-down:
desc: Stop the services needed for testing
cmds:
- >
docker compose
-p {{.TESTS_COMPOSE_PROJECT_NAME}}
-f {{.ROOT_DIR}}/docker-compose-tests.yml
down -v
export-test-env:
silent: true
desc: Export the environment variables to run the tests
cmds:
- >
echo "
export TESTS_POSTGRES_URL={{.TESTS_POSTGRES_URL}} &&
export TESTS_MINIO_PUBLIC_PORT={{.TESTS_MINIO_PUBLIC_PORT}} &&
export TESTS_MINIO_PUBLIC_PORT_CONSOLE={{.TESTS_MINIO_PUBLIC_PORT_CONSOLE}} &&
export TESTS_MINIO_ROOT_USER={{.TESTS_MINIO_ROOT_USER}} &&
export TESTS_MINIO_ROOT_PASSWORD={{.TESTS_MINIO_ROOT_PASSWORD}} &&
export TESTS_MINIO_REGION={{.TESTS_MINIO_REGION}} &&
export TESTS_MINIO_BUCKET_NAME={{.TESTS_MINIO_BUCKET_NAME}} &&
export TESTS_MINIO_ENDPOINT_URL={{.TESTS_MINIO_ENDPOINT_URL}} &&
export TESTS_RABBIT_URL={{.TESTS_RABBIT_URL}}"
test:
desc: Run the test suite
cmds:
- task: test-deps-up
- poetry run pytest -v
- task: test-deps-down
push-minio-image:
desc: Push a MinIO image tailored for GitHub Actions
cmds:
- >
docker build --platform linux/amd64
-f {{.ROOT_DIR}}/Dockerfile.minio
-t {{.ACTIONS_MINIO_IMAGE_LOCAL}}
{{.ROOT_DIR}}
- docker tag {{.ACTIONS_MINIO_IMAGE_LOCAL}} {{.ACTIONS_MINIO_IMAGE_REMOTE}}:{{.ACTIONS_MINIO_IMAGE_REMOTE_TAG}}
- docker push {{.ACTIONS_MINIO_IMAGE_REMOTE}}:{{.ACTIONS_MINIO_IMAGE_REMOTE_TAG}}
trust-up:
desc: Start the Trust Services Compose stack
env:
COMPOSE_PROJECT_NAME: "{{.TRUST_COMPOSE_PROJECT_NAME}}"
MONGO_PORT: "{{.TRUST_MONGO_PORT}}"
TRUST_PORT: "{{.TRUST_API_PORT}}"
cmds:
- echo "📣 You need to be logged in to Artifact Registry to pull the Trust Services images"
- echo "💻 gcloud auth configure-docker europe-west1-docker.pkg.dev"
- cmd: docker compose -f {{.ROOT_DIR}}/docker-compose-trust.yml up -d --build --wait
ignore_error: true
trust-down:
desc: Stop and remove all traces of the Trust Services stack
env:
COMPOSE_PROJECT_NAME: "{{.TRUST_COMPOSE_PROJECT_NAME}}"
MONGO_PORT: "{{.TRUST_MONGO_PORT}}"
TRUST_PORT: "{{.TRUST_API_PORT}}"
cmds:
- docker compose -f {{.ROOT_DIR}}/docker-compose-trust.yml down -v
ui-run-dev:
desc: Run the UI in development mode
dir: "{{.ROOT_DIR}}/moderate_ui"
vars:
VITE_KEYCLOAK_URL: "{{.KC_HOSTNAME_URL}}"
env:
VITE_KEYCLOAK_URL: "{{.VITE_KEYCLOAK_URL}}"
cmds:
- echo "📣 Ensure that Keycloak is on {{.VITE_KEYCLOAK_URL}}"
- npm run dev
alembic-revision:
desc: Create a new Alembic revision
vars:
GIT_REV_PARSE:
sh: git rev-parse HEAD
DEFAULT_MSG: "Revision based on commit {{.GIT_REV_PARSE}}"
MSG: "{{default .DEFAULT_MSG .MSG}}"
cmds:
- poetry run alembic revision --autogenerate -m "{{.MSG}}"
alembic-upgrade:
desc: Upgrade the database to the head revision
requires:
vars: [MIGRATIONS_SQLALCHEMY_URL]
cmds:
- poetry run alembic upgrade head
run-cloud-sql-proxy:
desc: Run Cloud SQL Proxy to enable connections to the cloud database
requires:
vars: [INSTANCE_CONNECTION_NAME]
cmds:
- cloud-sql-proxy {{.INSTANCE_CONNECTION_NAME}}
swagger-codegen-docs:
desc: Generate the API documentation static site
vars:
OPENAPI_PATH: "{{.ROOT_DIR}}/openapi.json"
OPENAPI_VERSION: 3.0.3
GENERATED_OPENAPI_DOCS_PATH: "{{.ROOT_DIR}}/api-docs-dist"
cmds:
- poetry run write-openapi --openapi-version {{.OPENAPI_VERSION}} --path {{.OPENAPI_PATH}}
- echo "📣 Note that you need to install swagger-codegen version 3 (https://github.com/swagger-api/swagger-codegen)"
- mkdir -p {{.GENERATED_OPENAPI_DOCS_PATH}}
- swagger-codegen generate -i {{.OPENAPI_PATH}} -l html -o {{.GENERATED_OPENAPI_DOCS_PATH}}
bump-api:
desc: Bump the API version
requires:
vars: [VERSION]
cmds:
- poetry version {{.VERSION}}
bump-ui:
desc: Bump the UI version
requires:
vars: [VERSION]
cmds:
- cd {{.ROOT_DIR}}/moderate_ui && npm version {{.VERSION}}
bump:
desc: Bump the API and UI versions
requires:
vars: [VERSION_API]
vars:
VERSION_UI: "{{default .VERSION_API .VERSION_UI}}"
cmds:
- task: bump-api
vars:
VERSION: "{{.VERSION_API}}"
- task: bump-ui
vars:
VERSION: "{{.VERSION_UI}}"
preconditions:
- sh: '[ -z "$(git status --porcelain)" ]'
msg: "Output of git status --porcelain is not clean"
commit-tag:
desc: Commit the version changes and tag the current commit
cmds:
- git add .
- >
VERSION_API=$(poetry version --short) &&
VERSION_UI=$(cd {{.ROOT_DIR}}/moderate_ui && grep '"version"' package.json | awk -F '"' '{print $4}') &&
TAG_NAME="v$VERSION_API-api-v$VERSION_UI-ui" &&
git commit -m "Bump versions to ${TAG_NAME}" &&
git tag -a ${TAG_NAME} -m "Release ${TAG_NAME} for API version ${VERSION_API} and UI version ${VERSION_UI}"
preconditions:
- sh: '[ -n "$(git diff --name-only HEAD | grep -E "pyproject.toml|moderate_ui/package.json")" ]'
msg: "The version files do not seem to have been updated"
bump-commit-tag:
desc: Bump the API and UI versions, commit and tag the current commit
requires:
vars: [VERSION_API]
vars:
VERSION_UI: "{{default .VERSION_API .VERSION_UI}}"
cmds:
- task: bump
vars:
VERSION_API: "{{.VERSION_API}}"
VERSION_UI: "{{.VERSION_UI}}"
- task: commit-tag
- echo "📣 Remember to push the changes and tags to the repository"