-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-service
executable file
·175 lines (152 loc) · 3.49 KB
/
docker-service
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
#!/bin/bash
set -o nounset
set -o errexit
OPTIND=1
env=''
# Get cli options
while getopts "he:" opt; do
case $opt in
h)
show_help
exit 0
;;
e)
env=".$OPTARG"
;;
*)
show_help >&2
exit 1
;;
esac
done
# Shift off the options and optional --.
shift "$((OPTIND-1))"
if [ "$env" == '' ]; then
[ ! -f .env ] && cp .env.dist .env;
else
[ ! -f .env ] && cp .env"$env" .env;
fi
[ ! -f .env ] && cp .env.sample .env;
source .env
# Common operations
initialize() {
down
start
}
start() {
docker-compose -f docker-compose"$env".yml up -d --remove-orphans
sleep 1
docker-compose -f docker-compose"$env".yml ps
}
stop() {
docker-compose -f docker-compose"$env".yml stop
docker-compose -f docker-compose"$env".yml ps
}
down() {
docker-compose -f docker-compose"$env".yml down --remove-orphans
}
install() {
docker-compose -f docker-compose"$env".yml exec opendata-api bash -c "npm install"
}
initTables() {
docker-compose -f docker-compose"$env".yml exec opendata-api bash -c "npm run initTables"
}
importData() {
datasetName="$1"
docker-compose -f docker-compose"$env".yml exec opendata-api bash -c "npm run importData $datasetName"
}
indexTable() {
datasetName="$1"
docker-compose -f docker-compose"$env".yml exec opendata-api bash -c "npm run indexTable $datasetName"
}
downloadAssets() {
datasetName="$1"
docker-compose -f docker-compose"$env".yml exec opendata-api bash -c "npm run downloadAssets $datasetName"
}
serve() {
docker-compose -f docker-compose"$env".yml exec opendata-api bash -c "npm run start"
}
# Test
tests() {
qualityTests
unitTests
}
unitTests() {
docker-compose -f docker-compose"$env".yml exec opendata-api bash -c "npm run test:unit:ci"
}
qualityTests() {
docker-compose -f docker-compose"$env".yml exec opendata-api bash -c "npm run lint"
}
# Usage info
show_help() {
cat << EOF
Usage: ${0##*/} [-e] [COMMAND]
Options:
-e string Specify env ("test"|"dev"|"demo"|"staging") (default "dev")
Commands:
initialize Start the project no matter what state it is in
start Start docker containers
stop Stop NodeJS server
down Remove docker containers
install Run app installation scripts
initTables Run Postgres tables installation scripts
importData Run dataset import into a Postgres table
indexTable Creates the index on given table
downloadAssets Download the given data set from configured source
serve Serve NodeJS server for local dev
tests Run unit and quality tests
unitTests Run unit tests
qualityTests Run quality tests
EOF
}
# Show help if no argument was supplied
if [ $# -eq 0 ]
then
show_help >&2
exit 1
fi
case "$1" in
initialize)
initialize
;;
start)
start
;;
stop)
stop
;;
down)
down
;;
install)
install
;;
initTables)
initTables
;;
importData)
importData $2
;;
indexTable)
indexTable $2
;;
downloadAssets)
downloadAssets $2
;;
serve)
serve
;;
tests)
tests
;;
unitTests)
unitTests
;;
qualityTests)
qualityTests
;;
*)
show_help >&2
exit 1
esac
exit 0