-
Notifications
You must be signed in to change notification settings - Fork 2
/
docker-entrypoint.sh
executable file
·223 lines (184 loc) · 6.29 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
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
#!/bin/bash
set -eo pipefail
# -e Exit immediately if a command exits with a non-zero status.
# -o pipefail the return value of a pipeline is the status of the last command
# to exit with a non-zero status, or zero if no command exited with a non-zero status
CONFIG_HASH=$(head -n 1 /CONFIG_HASH)
ERROR="\x1b[1;31m"
DEFAULT="\x1b[0m"
# logging functions
log() {
local level="$1"; shift
local type="$1"; shift
printf "[$level$type$DEFAULT]: $*\n"
}
error_log() {
log "$ERROR" "$@" >&2
exit 1
}
# if command starts with an option, prepend supertokens start
if [ "${1}" = 'dev' -o "${1}" = "production" -o "${1:0:2}" = "--" ]; then
# set -- supertokens start "$@"
set -- supertokens start "$@"
# check if --foreground option is passed or not
if [[ "$*" != *--foreground* ]]
then
set -- "$@" --foreground
fi
fi
CONFIG_FILE=/usr/lib/supertokens/config.yaml
TEMP_LOCATION_WHEN_READONLY=/lib/supertokens/temp/
CONFIG_MD5SUM="$(md5sum /usr/lib/supertokens/config.yaml | awk '{ print $1 }')"
#always assume readonly
#changing where the config file is written
ORIGINAL_CONFIG=$CONFIG_FILE
mkdir -p $TEMP_LOCATION_WHEN_READONLY
CONFIG_FILE="${TEMP_LOCATION_WHEN_READONLY}/config.yaml"
cat $ORIGINAL_CONFIG >> $CONFIG_FILE
#required by JNA
export _JAVA_OPTIONS=-Djava.io.tmpdir=$TEMP_LOCATION_WHEN_READONLY
#make sure the CLI knows which config file to pass to the core
set -- "$@" --with-config="$CONFIG_FILE" --with-temp-dir="$TEMP_LOCATION_WHEN_READONLY" --foreground
if [ "$CONFIG_HASH" = "$CONFIG_MD5SUM" ]
then
echo "" >> $CONFIG_FILE
echo "host: 0.0.0.0" >> $CONFIG_FILE
# verify api keys are passed
if [ ! -z $API_KEYS ]
then
echo "api_keys: $API_KEYS" >> $CONFIG_FILE
fi
# verify mongodb connection uri is passed
if [ ! -z $MONGODB_CONNECTION_URI ]
then
echo "mongodb_connection_uri: $MONGODB_CONNECTION_URI" >> $CONFIG_FILE
fi
# check if supertokens port is passed
if [ ! -z $SUPERTOKENS_PORT ]
then
echo "port: $SUPERTOKENS_PORT" >> $CONFIG_FILE
fi
# check if access token validity is passed
if [ ! -z $ACCESS_TOKEN_VALIDITY ]
then
echo "access_token_validity: $ACCESS_TOKEN_VALIDITY" >> $CONFIG_FILE
fi
# check if access token blacklisting is passed
if [ ! -z $ACCESS_TOKEN_BLACKLISTING ]
then
echo "access_token_blacklisting: $ACCESS_TOKEN_BLACKLISTING" >> $CONFIG_FILE
fi
# check if access token signing key dynamic is passed
if [ ! -z $ACCESS_TOKEN_SIGNING_KEY_DYNAMIC ]
then
echo "access_token_signing_key_dynamic: $ACCESS_TOKEN_SIGNING_KEY_DYNAMIC" >> $CONFIG_FILE
fi
# check if access token signing key update interval is passed
if [ ! -z $ACCESS_TOKEN_DYNAMIC_SIGNING_KEY_UPDATE_INTERVAL ]
then
echo "access_token_dynamic_signing_key_update_interval: $ACCESS_TOKEN_DYNAMIC_SIGNING_KEY_UPDATE_INTERVAL" >> $CONFIG_FILE
fi
# check if refresh token validity is passed
if [ ! -z $REFRESH_TOKEN_VALIDITY ]
then
echo "refresh_token_validity: $REFRESH_TOKEN_VALIDITY" >> $CONFIG_FILE
fi
if [ ! -z $BASE_PATH ]
then
echo "base_path: $BASE_PATH" >> $CONFIG_FILE
fi
if [ ! -z $LOG_LEVEL ]
then
echo "log_level: $LOG_LEVEL" >> $CONFIG_FILE
fi
if [ ! -z $IP_ALLOW_REGEX ]
then
echo "ip_allow_regex: $IP_ALLOW_REGEX" >> $CONFIG_FILE
fi
if [ ! -z $IP_DENY_REGEX ]
then
echo "ip_deny_regex: $IP_DENY_REGEX" >> $CONFIG_FILE
fi
if [ ! -z $SUPERTOKENS_SAAS_SECRET ]
then
echo "supertokens_saas_secret: $SUPERTOKENS_SAAS_SECRET" >> $CONFIG_FILE
fi
if [ ! -z $SUPERTOKENS_MAX_CDI_VERSION ]
then
echo "supertokens_max_cdi_version: $SUPERTOKENS_MAX_CDI_VERSION" >> $CONFIG_FILE
fi
# check if info log path is not passed
if [ ! -z $INFO_LOG_PATH ]
then
if [[ ! -f $INFO_LOG_PATH ]]
then
touch $INFO_LOG_PATH
fi
echo "info_log_path: $INFO_LOG_PATH" >> $CONFIG_FILE
else
echo "info_log_path: null" >> $CONFIG_FILE
fi
# check if error log path is passed
if [ ! -z $ERROR_LOG_PATH ]
then
if [[ ! -f $ERROR_LOG_PATH ]]
then
touch $ERROR_LOG_PATH
fi
echo "error_log_path: $ERROR_LOG_PATH" >> $CONFIG_FILE
else
echo "error_log_path: null" >> $CONFIG_FILE
fi
# check if telemetry config is passed
if [ ! -z $DISABLE_TELEMETRY ]
then
echo "disable_telemetry: $DISABLE_TELEMETRY" >> $CONFIG_FILE
fi
# check if session expired status code is passed
if [ ! -z $SESSION_EXPIRED_STATUS_CODE ]
then
echo "session_expired_status_code: $SESSION_EXPIRED_STATUS_CODE" >> $CONFIG_FILE
fi
# check if cookie same site is passed
if [ ! -z $COOKIE_SAME_SITE ]
then
echo "cookie_same_site: $COOKIE_SAME_SITE" >> $CONFIG_FILE
fi
# check if max server pool size is passed
if [ ! -z $MAX_SERVER_POOL_SIZE ]
then
echo "max_server_pool_size: $MAX_SERVER_POOL_SIZE" >> $CONFIG_FILE
fi
# check if mongodb database name is passed
if [ ! -z $MONGODB_DATABASE_NAME ]
then
echo "mongodb_database_name: $MONGODB_DATABASE_NAME" >> $CONFIG_FILE
fi
# check if mongodb collection name prefix is passed
if [ ! -z $MONGODB_COLLECTION_NAMES_PREFIX ]
then
echo "mongodb_collection_names_prefix: $MONGODB_COLLECTION_NAMES_PREFIX" >> $CONFIG_FILE
fi
# THE CONFIGS BELOW ARE DEPRECATED----------------
# check if mongodb key value table name is passed
if [ ! -z $MONGODB_KEY_VALUE_COLLECTION_NAME ]
then
echo "mongodb_key_value_collection_name: $MONGODB_KEY_VALUE_COLLECTION_NAME" >> $CONFIG_FILE
fi
# check if mongodb session info table name is passed
if [ ! -z $MONGODB_SESSION_INFO_COLLECTION_NAME ]
then
echo "mongodb_session_info_collection_name: $MONGODB_SESSION_INFO_COLLECTION_NAME" >> $CONFIG_FILE
fi
fi
# check if no options has been passed to docker run
if [[ "$@" == "supertokens start" ]]
then
set -- "$@" --with-config="$CONFIG_FILE" --foreground
fi
# If container is started as root user, restart as dedicated supertokens user
if [ "$(id -u)" = "0" ] && [ "$1" = 'supertokens' ]; then
exec gosu supertokens "$@"
else
exec "$@"
fi