Skip to content

Commit 13b1877

Browse files
committed
entrypoint: Automatically map all zulip__ secrets to zulip-secrets.conf.
1 parent a7bbdb9 commit 13b1877

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

docker-compose.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,6 @@ services:
107107
SETTING_MEMCACHED_LOCATION: "memcached:11211"
108108
SETTING_RABBITMQ_HOST: "rabbitmq"
109109
SETTING_REDIS_HOST: "redis"
110-
SECRETS_postgres_password_FILE: /run/secrets/zulip__postgres_password
111-
SECRETS_memcached_password_FILE: /run/secrets/zulip__memcached_password
112-
SECRETS_rabbitmq_password_FILE: /run/secrets/zulip__rabbitmq_password
113-
SECRETS_redis_password_FILE: /run/secrets/zulip__redis_password
114-
SECRETS_secret_key_FILE: /run/secrets/zulip__secret_key
115-
SECRETS_email_password_FILE: /run/secrets/zulip__email_password
116110
SETTING_EXTERNAL_HOST: "localhost.localdomain"
117111
SETTING_ZULIP_ADMINISTRATOR: "admin@example.com"
118112
SETTING_EMAIL_HOST: "" # e.g. smtp.example.com

entrypoint.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,20 @@ secretsConfiguration() {
280280
echo "Setting $SECRET_KEY from environment variable $key"
281281
crudini --set "$DATA_DIR/zulip-secrets.conf" "secrets" "${SECRET_KEY}" "${SECRET_VAR}"
282282
done
283+
# Secrets detected in /run/secrets/ override those via env vars
284+
for secrets_path in /run/secrets/zulip__*; do
285+
secrets_filename="$(basename "$secrets_path")"
286+
local SECRET_KEY="${secrets_filename#zulip__}"
287+
local SECRET_VAR="$(cat "$secrets_path")"
288+
if [ -z "$SECRET_VAR" ]; then
289+
echo "Empty secret for key \"$SECRET_KEY\"."
290+
elif [[ "$SECRET_VAR" =~ $'\n' ]]; then
291+
echo "ERROR: Secret \"$SECRET_KEY\" contains a newline!"
292+
exit 1
293+
fi
294+
echo "Setting $SECRET_KEY from secret in $secrets_path"
295+
crudini --set "$DATA_DIR/zulip-secrets.conf" "secrets" "${SECRET_KEY}" "${SECRET_VAR}"
296+
done
283297
echo "Zulip secrets configuration succeeded."
284298
}
285299
databaseConfiguration() {

0 commit comments

Comments
 (0)