Skip to content

Commit de42b03

Browse files
Merge pull request #278 from IdentityPython/refactor-docker-start
Refactor docker start script - Cleanup code and formatting - Allow to specify a configuration file for gunicorn - Allow to specify a chain link for the https certificate
2 parents c867efe + a7173d7 commit de42b03

File tree

1 file changed

+46
-27
lines changed

1 file changed

+46
-27
lines changed

docker/start.sh

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,65 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env sh
2+
3+
set -e
24

35
# for Click library to work in satosa-saml-metadata
4-
export LC_ALL=C.UTF-8
5-
export LANG=C.UTF-8
6+
export LC_ALL="C.UTF-8"
7+
export LANG="C.UTF-8"
68

7-
# exit immediately on failure
8-
set -e
9+
if [ -z "${DATA_DIR}" ]
10+
then DATA_DIR=/opt/satosa/etc
11+
fi
912

10-
if [ -z "${DATA_DIR}" ]; then
11-
DATA_DIR=/opt/satosa/etc
13+
if [ ! -d "${DATA_DIR}" ]
14+
then mkdir -p "${DATA_DIR}"
1215
fi
1316

14-
if [ ! -d "${DATA_DIR}" ]; then
15-
mkdir -p "${DATA_DIR}"
17+
if [ -z "${PROXY_PORT}" ]
18+
then PROXY_PORT="8000"
1619
fi
1720

18-
if [ -z "${PROXY_PORT}" ]; then
19-
PROXY_PORT="8000"
21+
if [ -z "${METADATA_DIR}" ]
22+
then METADATA_DIR="${DATA_DIR}"
2023
fi
2124

22-
if [ -z "${METADATA_DIR}" ]; then
23-
METADATA_DIR="${DATA_DIR}"
25+
if [ ! -d "${DATA_DIR}/attributemaps" ]
26+
then cp -pr /opt/satosa/attributemaps "${DATA_DIR}/attributemaps"
2427
fi
2528

26-
cd ${DATA_DIR}
29+
# activate virtualenv
30+
. /opt/satosa/bin/activate
2731

28-
mkdir -p ${METADATA_DIR}
32+
# generate metadata for frontend(IdP interface) and backend(SP interface)
33+
# write the result to mounted volume
34+
mkdir -p "${METADATA_DIR}"
35+
satosa-saml-metadata \
36+
"${DATA_DIR}/proxy_conf.yaml" \
37+
"${DATA_DIR}/metadata.key" \
38+
"${DATA_DIR}/metadata.crt" \
39+
--dir "${METADATA_DIR}"
2940

30-
if [ ! -d ${DATA_DIR}/attributemaps ]; then
31-
cp -pr /opt/satosa/attributemaps ${DATA_DIR}/attributemaps
41+
# if the user provided a gunicorn configuration, use it
42+
if [ -f "$GUNICORN_CONF" ]
43+
then conf_opt="--config ${GUNICORN_CONF}"
3244
fi
3345

34-
# Activate virtualenv
35-
. /opt/satosa/bin/activate
36-
37-
# generate metadata for front- (IdP) and back-end (SP) and write it to mounted volume
46+
# if HTTPS cert is available, use it
47+
https_key="${DATA_DIR}/https.key"
48+
https_crt="${DATA_DIR}/https.crt"
49+
if [ -f "$https_key" -a -f "$https_crt" ]
50+
then https_opts="--keyfile ${https_key} --certfile ${https_crt}"
51+
fi
3852

39-
satosa-saml-metadata proxy_conf.yaml ${DATA_DIR}/metadata.key ${DATA_DIR}/metadata.crt --dir ${METADATA_DIR}
53+
# if a chain is available, use it
54+
chain_pem="${DATA_DIR}/chain.pem"
55+
if [ -f "$chain_pem" ]
56+
then chain_opts="--ca-certs chain.pem"
57+
fi
4058

4159
# start the proxy
42-
if [[ -f https.key && -f https.crt ]]; then # if HTTPS cert is available, use it
43-
exec gunicorn -b0.0.0.0:${PROXY_PORT} --keyfile https.key --certfile https.crt satosa.wsgi:app
44-
else
45-
exec gunicorn -b0.0.0.0:${PROXY_PORT} satosa.wsgi:app
46-
fi
60+
exec gunicorn $conf_opt \
61+
-b 0.0.0.0:"${PROXY_PORT}" \
62+
satosa.wsgi:app \
63+
$https_opts \
64+
$chain_opts \
65+
;

0 commit comments

Comments
 (0)