-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmanage.sh
executable file
·225 lines (187 loc) · 5.43 KB
/
manage.sh
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
#!/bin/bash
function log() {
echo "[$0] [$(date -u +%Y-%m-%dT%H:%M:%SZ)] $*"
}
function ask_field() {
local FIELD=$1
local MESSAGE=$2
local DEFAULT_VALUE=$3
local TEMP=
echo "$MESSAGE (or leave empty for default value '$DEFAULT_VALUE'):"
read -r -e TEMP
echo ' '
export "$FIELD"="${TEMP:-$DEFAULT_VALUE}"
}
function generateJavaKeyStore() {
log 'Generate JWT key stores...'
APP_VERIFIER_KEY_ALIAS=${1}
if [ -z "${APP_VERIFIER_KEY_ALIAS}" ]; then
ask_field 'APP_VERIFIER_KEY_ALIAS' ''
fi
APP_VERIFIER_KEY_PASS=${2}
if [ -z "${APP_VERIFIER_KEY_PASS}" ]; then
ask_field 'APP_VERIFIER_KEY_PASS' ''
fi
mkdir -p /srv/app/keys
keytool -genkeypair -alias "$APP_SIGNING_KEYPAIR_ALIAS" -dname "CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, S=Unknown, C=Unknown" -keystore data/keys/.private.jks -keyalg RSA -keypass "$APP_SIGNING_KEYPAIR_PASS" -storepass "$APP_SIGNING_KEYPAIR_PASS"
keytool -importkeystore -srckeystore data/keys/.private.jks -srcstorepass "$APP_SIGNING_KEYPAIR_PASS" -destkeystore data/keys/.private.jks -deststoretype pkcs12
keytool -list -rfc --keystore data/keys/.private.jks -storepass "$APP_SIGNING_KEYPAIR_PASS" | openssl x509 -inform pem -pubkey -noout > data/keys/public.txt
}
function generateRsaKey() {
log 'Generate RSA keys...'
mkdir -p /srv/app/keys
ssh-keygen -b 2048 -m PEM -t rsa -f data/keys/.id_rsa -q -N ""
}
function init_keys() {
if [ ! -f data/keys/public.txt ]; then
generateJavaKeyStore
fi
if [ ! -f data/keys/.id_rsa ]; then
generateRsaKey
fi
}
function build {
mvn clean install
}
function run {
init_keys
mvn spring-boot:run
}
function release {
mvn release:prepare
mvn release:perform -B
}
function init_compose {
if [ ! -f '.env' ]; then
log 'Init docker compose environment variables...'
cp .env_template .env.tmp
ask_field 'APP_PACKAGE_REPO_LOGIN' 'Enter your Private Package Repository login' "${1}"
sed -i -e "s|APP_PACKAGE_REPO_LOGIN=.*|APP_PACKAGE_REPO_LOGIN=${APP_PACKAGE_REPO_LOGIN}|" .env.tmp
APP_PACKAGE_REPO_LOGIN=
ask_field 'APP_PACKAGE_REPO_PASSWORD' 'Enter your Private Package Repository password' "${2}"
sed -i -e "s|APP_PACKAGE_REPO_PASSWORD=.*|APP_PACKAGE_REPO_PASSWORD=${APP_PACKAGE_REPO_PASSWORD}|" .env.tmp
APP_PACKAGE_REPO_PASSWORD=
mv .env.tmp .env
fi
}
function compose {
init_compose
docker-compose \
-f "docker-compose.${DATABASE:-postgres}.test.yml" \
"$@"
}
function compose_config {
init_compose "$@"
docker-compose \
-f "docker-compose.${DATABASE:-postgres}.test.yml" \
config
}
function compose_build {
compose build "$@"
}
function compose_test {
compose up -d osrm_backend nominatim
docker-compose \
-f "docker-compose.${DATABASE:-postgres}.test.yml" \
--build-arg MAVEN_PROFILE=all-tests
build
compose stop osrm_backend nominatim
compose rm -f osrm_backend nominatim
}
function compose_ps {
compose ps "$@"
}
function compose_logs {
compose logs -f "$@"
}
function compose_run {
compose run "$@"
}
function compose_up {
compose up -d "$@"
}
function compose_down {
compose down "$@"
}
function compose_start {
compose start "$@"
}
function compose_stop {
compose stop "$@"
}
function compose_restart {
compose restart "$@"
}
function usage {
echo "Simple tools to help development and release"
echo "USAGE: $0 [ build | keys [alias password] | run | release ]"
echo "USAGE: $0 <command> [arguments]"
echo "
Commands:
keys [alias password] Generate JWT keys for local env
run Run locally
release Make (maven) release locally
compose-config Docker-compose: init env var and check docker-compose file config
compose-ps Docker-compose: list services
compose-logs Docker-compose: follow logs
compose-build Docker-compose: build containers
compose-test Docker-compose: build and test containers (UT + IT)
compose-run Docker-compose: run command
compose-up Docker-compose: Create and start containers
compose-down Docker-compose: Stop and remove containers
compose-start Docker-compose: Start containers
compose-stop Docker-compose: Stop containers
compose-restart Docker-compose: Restart containers
"
}
case $1 in
build)
build
;;
keys)
generateJavaKeyStore "${@:2}"
generateRsaKey
;;
run)
run
;;
release)
release
;;
compose-config)
init_compose "${@:2}"
;;
compose-build)
compose_build "${@:2}"
;;
compose-test)
compose_test "${@:2}"
;;
compose-ps)
compose_ps "${@:2}"
;;
compose-logs)
compose_logs "${@:2}"
;;
compose-run)
compose_run "${@:2}"
;;
compose-up)
compose_up "${@:2}"
;;
compose-down)
compose_down "${@:2}"
;;
compose-start)
compose_start "${@:2}"
;;
compose-stop)
compose_stop "${@:2}"
;;
compose-restart)
compose_restart "${@:2}"
;;
*)
usage
;;
esac