forked from qawolf/qawolf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wolf
executable file
·177 lines (141 loc) · 4.99 KB
/
wolf
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
#!/bin/bash
set -e
showHelp() {
printf "\nUsage: \n\n ./wolf [OPTION] \n"
printf "\nOptions:\n
init Install deps in all projects, build the runner container, and run app migrations
build Build all containers (or specify a container to build with an additional argument)
dev Start postgres and runner containers, then start app in dev mode
dev-all Start postgres, then start app and runner in dev mode (hot reload runner and recorder changes)
start Run production builds in docker containers and tail logs app/runner logs
stop Stop all running containers
clean Clean up all containers, volumes, and node_modules (full reset)
"
}
DOCKER_BASE_VERSION=1.0.0
# if no arg was provided, show help
if [ -z "$1" ] || [ "$1" == "help" ]; then
showHelp
exit 1
fi
# confirm docker
if ! command -v docker &> /dev/null; then
printf "\nDocker must be installed!\n"
printf "More info: https://docs.docker.com/engine/install/\n\n"
exit 1
fi
# confirm node/npm
if ! command -v npm &> /dev/null; then
printf "\nNode and npm must be installed!\n"
printf "More info: https://nodejs.org/en/download/\n\n"
exit 1
fi
# ensure a .env file exists for the app and docker-compose file
ensureDotenv() {
if [ ! -f ./app/.env ]; then
printf "\nCreating .env file...\n\n"
cp ./app/.env.example ./app/.env
fi
}
# install deps in all projects, run migrations, and build the runner container
if [[ $1 == "init" ]]; then
ensureDotenv
# postgres
printf "\nStarting postgres...\n\n"
docker-compose up -d postgres
# app
printf "\nInstalling node_modules for app...\n\n"
cd app
npm i
# qawolf
printf "\nInstalling node_modules for qawolf...\n\n"
cd ../qawolf && npm i
# recorder
printf "\nInstalling node_modules for recorder...\n\n"
cd ../recorder && npm i
# runner
printf "\nInstalling node_modules for runner...\n\n"
cd ../runner && npm i
printf "\nBuilding recorder script for runner container...\n\n"
npm run build:recorder-script
printf "\nBuilding runner image...\n\n"
docker pull qawolf/runner-base:$DOCKER_BASE_VERSION
cd ..
docker-compose build runner
# run migrations
printf "\nRunning migrations...\n\n"
cd app
npm run migrate:run:dev
# seed database on first run
printf "\nSeeding database...\n\n"
npm run seed:dev
exit 0
fi
# build all containers (or specify a container to build with an additional argument)
if [[ $1 == "build" ]]; then
# if we're rebuilding the runner container,
# make sure to build the recorder script first
if [[ -z "$2" ]] || [[ "$2" == "runner" ]]; then
printf "\nBuilding recorder script for runner container...\n\n"
cd runner && npm run build:recorder-script
printf "\nBuilding base image for runner container...\n\n"
docker build -f Dockerfile.base -t qawolf/runner-base:$DOCKER_BASE_VERSION .
fi
printf "\nBuilding docker containers...\n\n"
docker-compose build $2
exit 0
fi
# start postgres and runner containers, then start app in dev mode
if [[ $1 == "dev" ]]; then
ensureDotenv
rm docker-compose.override.yml || true
docker-compose up -d
cd app
npm run dev
exit 0
fi
# start postgres, then start all projects in dev (hot reload) mode
if [[ $1 == "dev-all" ]]; then
ensureDotenv
ln -s docker-compose.runner-dev.yml docker-compose.override.yml || true
docker-compose up -d
# This needs to do 5 things for full hot reload:
# - watch runner TS files and rebuild to /dist as they change
# - watch /dist and copy into running container when it changes
# - watch recorder TS files and rebuild to recorder/build/qawolf.recorder.js when they change
# - watch recorder/build/qawolf.recorder.js and copy to runner/qawolf.recorder.js when it changes
# - watch runner/qawolf.recorder.js and copy into running container when it changes
runner/node_modules/.bin/concurrently --kill-others -n runner-build-watch,recorder-build-watch,docker-recorder-update,app "docker-compose exec -T runner npm run build:tsc:watch -- --onSuccess \"scripts/restart-node.sh\"" "cd recorder && npm run build:watch" "cd runner && npm run watch-and-update-recorder" "cd app && npm run dev"
# cd app
# npm run dev
exit 0
fi
# run production builds in docker containers and tail logs
if [[ $1 == "start" ]]; then
ensureDotenv
docker-compose up -d
docker-compose logs -f runner
exit 0
fi
# kill all running containers
if [[ $1 == "stop" ]]; then
docker-compose stop
exit 0
fi
# clean up all containers, volumes, and node_modules
# this is essentially like a fresh checkout, except it preserves your ./app/.env
if [[ $1 == "clean" ]]; then
printf "\nCleaning up docker containers...\n\n"
docker-compose stop
docker-compose rm -f
printf "\nCleaning up docker volumes...\n"
docker volume rm -f qawolf_pg-data
printf "\nCleaning up node_modules in all projects...\n"
rm -rf ./{app,qawolf,recorder,runner}/node_modules
printf "\nDone!"
exit 0
fi
# if the provided command arg didn't match any of the options above,
# show the help message
showHelp
exit 1