-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
run
executable file
·286 lines (236 loc) · 8.59 KB
/
run
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
#!/usr/bin/env bash
#
# A script to make working with docker/compose to have
# less typing.
#
# For local development only.
UI_PATH="source/SIL.AppBuilder.Portal.Frontend"
API_PATH="source/OptimaJet.DWKit.StarterApplication"
COMPOSE="docker compose -f deployment/development/docker-compose.yml --project-directory . -p appbuilder-portal"
COMPOSE_SERVICES="db adminer api ui"
CI_COMPOSE="docker compose -f deployment/ci/docker-compose.yml --project-directory . -p appbuilder-portal-ci"
PSQL="PGPASSWORD=\$POSTGRES_PASSWORD psql -h localhost -U \$POSTGRES_USER"
function runstuff {
# First arg
given_command=$1
# The rest of the args
arguments=${@:2}
case $given_command in
# docker compose proxy
dc) ${COMPOSE} $arguments;;
up:build) ${COMPOSE} up --build $arguments ${COMPOSE_SERVICES} ;;
up) ${COMPOSE} up $arguments ${COMPOSE_SERVICES} ;;
up:local:start)
runstuff dc up -d db adminer
echo "db and adminer have been started. please make sure you have /etc/hosts entries"
echo ""
echo " 127.0.0.1 db.docker"
echo " 127.0.0.1 api"
echo " 127.0.0.1 adminer"
echo ""
echo "if you need to connect to these services from locally run api and ui"
echo ""
echo "also make sure any environment variables present in docker-compose.yml"
echo "for the non-running services are present when booting up the services"
echo "on the host environment (use .env.dev files to make this simpler)"
echo ""
echo "why?"
echo "because currently, docker compose doesn't have a way to omit files / folders"
echo "from volume mounts, so whenever dotnet watch would do a rebuild inside the"
echo "docker environment, it would blow away all the host-dependencies that the"
echo "editor was using for intellisense..."
runstuff dc ps
runstuff dc logs --follow --tail="2"
;;
bash) ${COMPOSE} run --rm $arguments bash;;
restart) ${COMPOSE} stop $arguments && ${COMPOSE} start $arguments;;
api:ef)
${COMPOSE} exec api bash -c "\
dotnet ef ${arguments} \
--startup-project /app/OptimaJet.DWKit.StarterApplication/OptimaJet.DWKit.StarterApplication.csproj \
--project /app/OptimaJet.DWKit.StarterApplication/OptimaJet.DWKit.StarterApplication.csproj \
--msbuildprojectextensionspath /app/out/OptimaJet.DWKit.StarterApplication/obj/ \
";;
db:update) runstuff api:ef database update ${arguments};;
db:migrations) runstuff api:ef migrations ${arguments};;
bootstrap)
set -e
runstuff bootstrap:dwkit
runstuff bootstrap:api
runstuff bootstrap:sample
runstuff bootstrap:dev
runstuff bootstrap:ui-static
set +e
;;
bootstrap:alpha)
set -e
runstuff bootstrap:dwkit
runstuff bootstrap:api
runstuff bootstrap:orgs
runstuff bootstrap:dev
runstuff bootstrap:ui-static
set +e
;;
bootstrap:dwkit)
echo "api must not be running in order to run the initial db scripts ..."
runstuff dc stop api
# Setup Database
${COMPOSE} exec db bash -c "\
${PSQL} -d postgres -tc \
\"SELECT 1 FROM pg_database \
WHERE datname = '\$POSTGRES_DB'\" \
| grep -q 1 \
&& ${PSQL} -d postgres -c \"DROP DATABASE \$POSTGRES_DB\""
${COMPOSE} exec db bash -c "${PSQL} -d postgres -c \"CREATE DATABASE \$POSTGRES_DB WITH ENCODING 'UTF8'\""
echo "Setting up DWKit..."
${COMPOSE} exec db bash -c "${PSQL} -d \$POSTGRES_DB -f /scripts/PostgreSQL/DWKitScript.sql" \
&& ${COMPOSE} exec db bash -c "${PSQL} -d \$POSTGRES_DB -f /scripts/PostgreSQL/Workflow_CreatePersistenceObjects.sql" \
&& ${COMPOSE} exec db bash -c "${PSQL} -d \$POSTGRES_DB -f /scripts/PostgreSQL/DWKitUpdate_2.6.sql" \
&& echo "DB setup with DWKit Scripts"
;;
bootstrap:api)
echo "api must be running in order to run the db migration scripts ..."
runstuff dc start api
echo "Running migrations..."
runstuff db:update \
&& ${COMPOSE} exec db bash -c "${PSQL} -d \$POSTGRES_DB -f /scripts/bootstrap.sql" \
&& ${COMPOSE} exec db bash -c "${PSQL} -d \$POSTGRES_DB -f /scripts/default_workflow.sql" \
&& echo "DB setup for json:api"
;;
bootstrap:workflow)
${COMPOSE} exec db bash -c "${PSQL} -d \$POSTGRES_DB -f /scripts/default_workflow.sql"
;;
bootstrap:sample)
echo "Adding sample data..."
${COMPOSE} exec db bash -c "${PSQL} -d \$POSTGRES_DB -f /scripts/sample_data.sql" \
&& echo "DB setup with sample data"
;;
bootstrap:ui-static)
echo "Building Static Data for the UI"
( cd $UI_PATH && ./scripts/refresh-languages.sh )
;;
bootstrap:orgs)
echo "Adding sample data..."
${COMPOSE} exec db bash -c "${PSQL} -d \$POSTGRES_DB -f /scripts/default_organizations.sql" \
&& echo "DB setup with default organizations data"
;;
bootstrap:dev)
# add something like the following to scripts/DB/dev.sql
# UPDATE "Users"
# SET "PublishingKey" = 'ssh-rsa ...'
# WHERE
# "Id" = X;
${COMPOSE} exec db bash -c "if [ -f /scripts/dev.sql ]; then ${PSQL} -d \$POSTGRES_DB -f /scripts/dev.sql; fi" \
&& echo "DB setup with dev data"
;;
##################
# Testing
ci:build)
${CI_COMPOSE} build
;;
ci:ui)
${CI_COMPOSE} run --rm ui \
bash -c "yarn && yarn lint && yarn test:ci"
;;
ci:api)
${CI_COMPOSE} run --rm api \
bash -c "dotnet test /app/SIL.AppBuilder.Portal.Backend.Tests/"
;;
ci)
${CI_COMPOSE} $arguments
;;
prod:nginx:run)
runstuff dc start adminer
runstuff dc start db
runstuff dc start api
# 1. Remove existing docker container with tag
# 2. Rebuild
# 3. Run
CURRENT_VERSION=$(git rev-parse HEAD)
# 1. Remove existing
docker image rm nginx-$CURRENT_VERSION -f
# 2. Rebuild
docker build . -f Dockerfile.nginx \
--tag "nginx-$CURRENT_VERSION" --target release
# 3. Run
docker run -it \
-p 9091:80 \
-e "API_URL=http://api.docker:7081" \
-e "AUTH0_DOMAIN=sil-appbuilder.auth0.com" \
-e "AUTH0_CLIENT_ID=n8IAE2O17FBrlQ667x5mydhpqelCBUWG" \
-e "DWKIT_UI_HOST=172.18.0.1" \
--network appbuilder-portal_default \
--link appbuilder-portal_api_1:api.docker nginx-$CURRENT_VERSION
;;
################
# Host-Machine Utils
# frontend things
yarn) ( cd $UI_PATH && yarn $arguments );;
refresh-languages) ( cd $UI_PATH && ./scripts/refresh-languages.sh );;
# backend / api things
dotnet:api) ( cd $API_PATH && dotnet $arguments );;
dotnet) ( cd source && dotnet ${arguments} );;
dotnet:ef)
runstuff dotnet ef \
${arguments} \
--startup-project ./OptimaJet.DWKit.StarterApplication/OptimaJet.DWKit.StarterApplication.csproj \
--project ./OptimaJet.DWKit.StarterApplication/OptimaJet.DWKit.StarterApplication.csproj \
--msbuildprojectextensionspath ./out/OptimaJet.DWKit.StarterApplication/obj/
;;
# dotnet:api)
# Don't name any folders bin, obj, tmp, dist, or node_modules
clean:all)
echo "Cleaning..."
runstuff clean:api
runstuff clean:frontend
;;
clean:api)
shopt -s globstar
rm -rf **/out/ &&
# rm -rf source//bin && \
rm -rf **/obj
;;
clean:frontend)
shopt -s globstar
runstuff yarn cache clean && \
rm -rf **/dist && \
rm -rf **/node_modules && \
rm -rf **/tmp
;;
*) print_help;;
esac
}
function print_help {
echo ""
echo "Available Commands:"
echo ""
echo "dc : short for docker compose"
echo "up:build"
echo "up"
echo "up:local:start : starts non-essential services in docker, and the api and ui services natively on the host machine"
echo ""
echo "bash : drop into a bash shell in a temporary docker compose service"
echo "restart : restart a specific docker compose service"
echo ""
echo "bootstrap : runs initial scripts for project setup"
echo "bootstrap:dwkit"
echo "bootstrap:alpha"
echo "bootstrap:orgs"
echo "bootstrap:api"
echo "bootstrap:sample"
echo "db:migrations : run Entity Framework migrations command"
echo "db:update : run Entity Framework database command"
echo ""
echo "yarn"
echo ""
echo "dotnet"
echo ""
echo "clean:all : recursively removes dist, node_modules, and tmp directories"
echo "clean:api"
echo "clean:frontend"
}
if [ $1 ]; then
runstuff $*
else
print_help
fi