-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile
executable file
·240 lines (202 loc) · 7.11 KB
/
Taskfile
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
#!/bin/bash
#
# PRIVATE
#
#
# _run-dc name command...
#
# Runs docker compose with the given docker compose filename suffix with the given command arguments
#
function _dc-run {
docker compose -f "tools/docker-compose-${1}.yml" --project-directory "${PWD}" --project-name orcidlink run --remove-orphans --rm orcidlink "${@:2}"
}
function _dc-up {
docker compose -f "tools/docker-compose-${1}.yml" --project-directory "${PWD}" --project-name orcidlink up
docker compose -f "tools/docker-compose-${1}.yml" --project-directory "${PWD}" --project-name orcidlink rm -f
}
#function _run-tool {
# echo "Running: "
# echo "${@:1}"
# docker compose -f "tools/runner/docker-compose-tool-runner.yml" --project-directory "${PWD}" --project-name tools run --rm runner "${@:1}"
# echo "done"
#}
function _run {
echo "Running: "
echo "${@:1}"
docker compose -f "tools/runner/docker-compose-tool-${1}.yml" --project-directory "${PWD}" --project-name tools run --remove-orphans --rm "${1}" "${@:2}"
docker compose -f "tools/runner/docker-compose-tool-${1}.yml" --project-directory "${PWD}" --project-name tools down
}
#
# COMMANDS
#
function pyright {
_run runner tools/scripts/run-pyright.sh
}
function autoflake {
_run runner tools/scripts/run-autoflake.sh
}
function isort {
_run runner tools/scripts/run-isort.sh "${1}" "${2}"
}
function black {
_run runner tools/scripts/run-black.sh "${1}" "${2}"
}
function git-info {
_run runner poetry --quiet run python src/misc/git-info.py
}
function lock {
_run runner poetry lock
}
#
# Generates the openapi spec in memory, and compares it to the one already existing in docs/api/openapi.json.
# Returns a success if identical, error (1) if there are any differences.
#
function check-openapi {
_run runner poetry --quiet run python src/misc/check-openapi.py /app
}
#
# Generates the openapi.json spec file at docs/api/openapi.json
#
function generate-openapi {
_run runner poetry --quiet run python src/misc/generate-openapi.py /app
}
#
# Generates markdown + html api docs from a given openapi.json spec file, placing the resulting document
# at docs/api/index.md. A development-time preview which utilizes an approximation of GitHub styles, is
# also generated at docs/api/index.html.
#
function generate-docs {
rm -rf docs/api/openapi/*
_run runner poetry --quiet run python src/misc/generate-docs.py /app
}
function extract-schema {
_run runner poetry --quiet run python src/misc/extract-schema.py /app "${1}"
}
function shell {
_run runner bash
}
#function server {
# docker compose -f tools/docker-compose-prod-like.yml
#}
function test {
# Testing only touches locally controlled services, either mock
# mock (kbase auth, orcid) or locally running (mongodb), so
# all such values are controlled within the test environment.
export PROJECT_ROOT=/app
_run testing tools/scripts/run-tests.sh "${1}"
}
function viewcov {
open "${PWD}/htmlcov/index.html"
}
function dev-server {
export KBASE_ENDPOINT=https://ci.kbase.us/services/
export ORCID_OAUTH_BASE_URL=https://sandbox.orcid.org/oauth
export ORCID_API_BASE_URL=https://api.sandbox.orcid.org/v3.0
export ORCID_SITE_BASE_URL=https://sandbox.orcid.org
export ORCID_CLIENT_ID=${ORCID_CLIENT_ID:?Required environment variable 'ORCID_CLIENT_ID' not provided}
export ORCID_CLIENT_SECRET=${ORCID_CLIENT_SECRET?Required environment variable 'ORCID_CLIENT_SECRET' not provided}
export MONGO_HOST=mongo
export MONGO_PORT=27017
export MONGO_DATABASE=orcidlink
export MONGO_USERNAME=dev
export MONGO_PASSWORD=d3v
_dc-up dev
}
function set-orcid-sandbox-env {
export ORCID_OAUTH_BASE_URL=https://sandbox.orcid.org/oauth
export ORCID_API_BASE_URL=https://api.sandbox.orcid.org/v3.0
export ORCID_SITE_BASE_URL=https://sandbox.orcid.org
export ORCID_CLIENT_ID=${1:?Required environment variable 'ORCID_CLIENT_ID' not provided}
export ORCID_CLIENT_SECRET=${2?Required environment variable 'ORCID_CLIENT_SECRET' not provided}
}
function set-orcid-production-env {
export ORCID_OAUTH_BASE_URL=https://orcid.org/oauth
export ORCID_API_BASE_URL=https://api.orcid.org/v3.0
export ORCID_SITE_BASE_URL=https://orcid.org
export ORCID_CLIENT_ID=${1:?Required environment variable 'ORCID_CLIENT_ID' not provided}
export ORCID_CLIENT_SECRET=${2?Required environment variable 'ORCID_CLIENT_SECRET' not provided}
}
function set-mongo-dev-env {
export MONGO_HOST=mongo
export MONGO_PORT=27017
export MONGO_DATABASE=orcidlink
export MONGO_USERNAME=dev
export MONGO_PASSWORD=d3v
}
function server {
# export SERVICE_DIRECTORY="/kb/module"
export KBASE_ENDPOINT=${KBASE_ENDPOINT:?Required environment variable 'KBASE_ENDPOINT' not provided}
echo
echo "required environment variables check"
echo "KBASE_ENDPOINT=${KBASE_ENDPOINT}"
echo "SERVICE_DIRECTORY="
echo " (will use default)"
echo "ORCID_API_BASE_URL=${ORCID_API_BASE_URL}"
echo "ORCID_OAUTH_BASE_URL=${ORCID_OAUTH_BASE_URL}"
echo "ORCID_SITE_BASE_URL=${ORCID_SITE_BASE_URL}"
echo "ORCID_CLIENT_ID=${ORCID_CLIENT_ID}"
echo "ORCID_CLIENT_SECRET=${ORCID_CLIENT_SECRET}"
echo "MONGO_HOST=${MONGO_HOST}"
echo "MONGO_PORT=${MONGO_PORT}"
echo "MONGO_DATABASE=${MONGO_DATABASE}"
echo "MONGO_USERNAME=${MONGO_USERNAME}"
echo "MONGO_PASSWORD=${MONGO_PASSWORD}"
_dc-up prod-like
}
export DEFAULT_LOCAL_IMAGE="kbase/orcidlink:dev"
# For building a prod-like image locally
function build-image {
docker build -t "${DEFAULT_LOCAL_IMAGE}" .
}
#
# This was the first attempt at generating API docs, but was not suitable for generation of
# docs which could be viewed at GitHub. Left here for posterity, and because maybe we can get
# it to work better.
#
#function generate-apidocs {
# rm -rf docs/api/openapi/*
# docker run --rm \
# -v "${PWD}:/kb/module" openapitools/openapi-generator-cli generate \
# -i /kb/module/docs/api/openapi.json \
# -g markdown \
# -o /kb/module/docs/api/openapi
#}
# For running a prod-like image locally
function run-image {
# NB There should be a mongo db running at the indicated
# host and port with the indicated auth
IMAGE_NAME="${1:-$DEFAULT_LOCAL_IMAGE}"
echo
echo "Running orcidlink image"
echo "Image name: ${IMAGE_NAME}"
echo
docker run \
-e KBASE_ENDPOINT=https://ci.kbase.us/services/ \
-e ORCID_OAUTH_BASE_URL=https://sandbox.orcid.org/oauth \
-e ORCID_API_BASE_URL=https://api.sandbox.orcid.org/v3.0 \
-e ORCID_CLIENT_ID=${ORCID_CLIENT_ID} \
-e ORCID_CLIENT_SECRET=${ORCID_CLIENT_SECRET} \
-e MONGO_HOST=mongo \
-e MONGO_PORT=27017 \
-e MONGO_DATABASE=orcidlink \
-e MONGO_USERNAME=dev \
-e MONGO_PASSWORD=d3v \
--stop-signal SIGINT \
--dns 8.8.8.8 \
--network kbase-dev \
--name orcidlink \
--hostname orcidlink \
--rm \
"${IMAGE_NAME}"
}
function help {
echo "$0 <task> <args>"
echo "Runs the tasks listed below."
echo "To find out more about them, either read the source"
echo "for ${0} or the docs located in 'docs/tasks.md'."
echo "Tasks:"
# Note that this omits private functions - those prefixed with an _
compgen -A function | grep -e '^[^_]' | cat -n
}
TIMEFORMAT="Task completed in %3lR"
time "${@:-help}"