-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-entrypoint.sh
50 lines (44 loc) · 1.53 KB
/
docker-entrypoint.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
#!/bin/bash
# Exit the script in case of errors
set -e
# Some constants
DEV_KW_CONFIG='server/target/classes/keywhiz-development.yaml'
DEFAULT_COOKIEKEY_PATH='server/target/classes/dev_and_test_cookiekey.base64'
# Some runtime useful variables
COOKIEKEY_PATH="${COOKIEKEY_PATH:-server/target/classes/cookiekey.base64}"
KEYSTORE_PASS="${KEYSTORE_PASS:-$(pwgen -s 12 1)}"
KW_POPULATE_DEV_DATA="${KW_POPULATE_DEV_DATA:-true}"
# Generate base derivation key in derivation.jceks
echo 'Generating derivation key in derivation.jceks.'
rm server/target/classes/derivation.jceks
$ENTRYPOINT gen-aes --storepass "${KEYSTORE_PASS}"
sed -i "s/password: CHANGE$/password: ${KEYSTORE_PASS}/" "${DEV_KW_CONFIG}"*
echo 'Derivation key generated.'
# Generata key used to encrypt cookie content in cookiekey.base64
if ! [ -e "${COOKIEKEY_PATH}" ]
then
echo "Generating random cookie key in ${COOKIEKEY_PATH}."
head -c 32 /dev/random | base64 > "${COOKIEKEY_PATH}"
sed -i "s@${DEFAULT_COOKIEKEY_PATH}@${COOKIEKEY_PATH}@" "${DEV_KW_CONFIG}"*
echo 'Cookie key generated.'
fi
if [ x"${*}" = x ]
then
# Test mode
echo 'Initializing the DB.'
$ENTRYPOINT migrate "${DEV_KW_CONFIG}"
if [ x"${KW_POPULATE_DEV_DATA}" = x'true' ]
then
echo 'Populating database with development data.'
$ENTRYPOINT db-seed "${DEV_KW_CONFIG}"
fi
echo 'Starting server.'
exec $ENTRYPOINT server "${DEV_KW_CONFIG}"
else
if [ x"${1}" = x'server' ]
then
echo 'Initializing the DB.'
java $JAVA_ARGS -jar $JAR migrate "${2}"
fi
exec java $JAVA_ARGS -jar $JAR "${@}"
fi