forked from alerta/docker-alerta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-entrypoint.sh
executable file
·71 lines (61 loc) · 1.81 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
set -e
ADMIN_USER=${ADMIN_USERS%%,*}
ADMIN_PASSWORD=${ADMIN_PASSWORD:-alerta}
MAXAGE=${ADMIN_KEY_MAXAGE:-315360000} # default=10 years
# Generate minimal server config, if not supplied
if [ ! -f "${ALERTA_SVR_CONF_FILE}" ]; then
echo "# Create server configuration file."
cat >"${ALERTA_SVR_CONF_FILE}" << EOF
SECRET_KEY = '$(< /dev/urandom tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= | head -c 32)'
EOF
fi
# Init admin users and API keys
if [ -n "${ADMIN_USERS}" ]; then
echo "# Create admin users."
alertad user --all --password "${ADMIN_PASSWORD}" || true
echo "# Create admin API keys."
alertad key --all
# Create user-defined API key, if required
if [ -n "${ADMIN_KEY}" ]; then
echo "# Create user-defined admin API key."
alertad key --username "${ADMIN_USER}" --key "${ADMIN_KEY}" --duration "${MAXAGE}"
fi
fi
# Generate minimal client config, if not supplied
if [ ! -f "${ALERTA_CONF_FILE}" ]; then
echo "# Create client configuration file."
cat >${ALERTA_CONF_FILE} << EOF
[DEFAULT]
endpoint = http://localhost:8080/api
EOF
# Add API key to client config, if required
if [ "${AUTH_REQUIRED,,}" == "true" ]; then
echo "# Auth enabled; add admin API key to client configuration."
API_KEY=$(alertad key \
--username "${ADMIN_USER}" \
--scope "read" \
--scope "write:alerts" \
--scope "admin:management" \
--duration "${MAXAGE}" \
--text "Housekeeping")
cat >>${ALERTA_CONF_FILE} << EOF
key = ${API_KEY}
EOF
fi
fi
echo
echo '# Checking versions.'
echo Alerta Server ${SERVER_VERSION}
echo Alerta Client ${CLIENT_VERSION}
echo Alerta WebUI ${WEBUI_VERSION}
nginx -v
echo uwsgi $(uwsgi --version)
mongo --version | grep MongoDB
psql --version
python3 --version
/venv/bin/pip list
echo
echo 'Alerta init process complete; ready for start up.'
echo
exec "$@"