Skip to content

Commit b17ab33

Browse files
author
Gaël
committed
feat: Add --skip-env-config switch
1 parent c5ef604 commit b17ab33

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ A discourse container config file is created when a discourse app is created. Th
5858

5959
You can edit the config at `/home/dokku/APP_NAME/discourse_standalone.yml`. Don't make any changes to the `volumes` section, but feel free to change anything else.
6060

61+
Warning: The env part is overrided by dokku-discourse plugin. If you want to use custom configuration, and skip this override, please use the following syntaxe :
62+
`dokku discourse:create <app> <hostname to listen> --skip-env-config`
63+
6164
After making change be sure to run `dokku discourse:create <app>` to rebuild and re-deploy the discourse app.
6265

6366
### Upgrade a discourse app

functions

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ discourse_create_app() {
2525

2626
[[ -z "$APP_NAME" ]] && dokku_log_fail "Missing app argument"
2727
[[ -z "$HOSTNAME" ]] && HOSTNAME=$(fn-get-input "Hostname for your Discourse?" "$(fn-get-env-config DISCOURSE_HOSTNAME)")
28-
[[ -z "$DEVELOPER_EMAILS" ]] && DEVELOPER_EMAILS=$(fn-get-input "Email address for admin account(s)?" "$(fn-get-env-config DISCOURSE_DEVELOPER_EMAILS)")
29-
[[ -z "$SMTP_ADDRESS" ]] && SMTP_ADDRESS=$(fn-get-input "SMTP server address?" "$(fn-get-env-config DISCOURSE_SMTP_ADDRESS)")
30-
[[ -z "$SMTP_PORT" ]] && SMTP_PORT=$(fn-get-input "SMTP port?" "$(fn-get-env-config DISCOURSE_SMTP_PORT)")
31-
[[ -z "$SMTP_USERNAME" ]] && SMTP_USERNAME=$(fn-get-input "SMTP user name?" "$(fn-get-env-config DISCOURSE_SMTP_USER_NAME)")
32-
[[ -z "$SMTP_PASSWORD" ]] && SMTP_PASSWORD=$(fn-get-input "SMTP password?" "$(fn-get-env-config DISCOURSE_SMTP_PASSWORD)")
28+
if [ "$DEVELOPER_EMAILS" != "--skip-env-config" ]; then
29+
[[ -z "$DEVELOPER_EMAILS" ]] && DEVELOPER_EMAILS=$(fn-get-input "Email address for admin account(s)?" "$(fn-get-env-config DISCOURSE_DEVELOPER_EMAILS)")
30+
[[ -z "$SMTP_ADDRESS" ]] && SMTP_ADDRESS=$(fn-get-input "SMTP server address?" "$(fn-get-env-config DISCOURSE_SMTP_ADDRESS)")
31+
[[ -z "$SMTP_PORT" ]] && SMTP_PORT=$(fn-get-input "SMTP port?" "$(fn-get-env-config DISCOURSE_SMTP_PORT)")
32+
[[ -z "$SMTP_USERNAME" ]] && SMTP_USERNAME=$(fn-get-input "SMTP user name?" "$(fn-get-env-config DISCOURSE_SMTP_USER_NAME)")
33+
[[ -z "$SMTP_PASSWORD" ]] && SMTP_PASSWORD=$(fn-get-input "SMTP password?" "$(fn-get-env-config DISCOURSE_SMTP_PASSWORD)")
34+
fi
3335

3436
local APP_STORAGE_ROOT="$STORAGE_ROOT/$APP_NAME"
3537

internal-functions

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,16 @@ fn-update-discourse-container-config() {
8484
SMTP_PORT="$6" \
8585
SMTP_USER_NAME="$7" \
8686
SMTP_PASSWORD="$8"
87-
88-
fn-update-discourse-config-env \
89-
"$APP_NAME" \
90-
"$HOSTNAME" \
91-
"$DEVELOPER_EMAILS" \
92-
"$SMTP_ADDRESS" \
93-
"$SMTP_PORT" \
94-
"$SMTP_USER_NAME" \
95-
"$SMTP_PASSWORD"
87+
if [ "$DEVELOPER_EMAILS" != "--skip-env-config" ]; then
88+
fn-update-discourse-config-env \
89+
"$APP_NAME" \
90+
"$HOSTNAME" \
91+
"$DEVELOPER_EMAILS" \
92+
"$SMTP_ADDRESS" \
93+
"$SMTP_PORT" \
94+
"$SMTP_USER_NAME" \
95+
"$SMTP_PASSWORD"
96+
fi
9697

9798
fn-update-discourse-config-set-volumes "$APP_NAME" "$APP_STORAGE_ROOT"
9899

@@ -179,10 +180,13 @@ fn-get-env-vars-from-run-args() {
179180
# RUN_ARGS will be a string in form "+ true run --shm-size=512m -d --restart=always -e LANG=en_US.UTF-8 -e RAILS_ENV=production" etc
180181
# We want to extract the env vars from the string and produce a new string in form "ENV=var ENV2=var"
181182
# 1. We use grep to extract the "-e ENV=var" strings
182-
# 2. grep will give us newlines, so we convert those to spaces using tr
183-
# 3. Next we use sed to remove "-e" flags as well as multiple consecutive whitespace chars
184-
# 4. Finally we use sed to trim leading and trailing spaces
185-
echo "$RUN_ARGS" | grep -Po '[[:space:]]-e[[:space:]]*[^[:space:]]+' | tr "\n" "\t" | sed -r "s/\s+\-e\s+|\s+/ /g" | sed -r 's/^\s*|\s*$//g'
183+
# 2. Next we use sed to remove "-e" flags
184+
# 3. Next we use sed to remove leading and trailing single quote if exists (docker env escaping strategy)
185+
# 4. We use awk to break then reconstruct with escaping strategy of dokku config:set (not 'FOO=BAR' but FOO='BAR')
186+
# 5. grep will give us newlines, so we convert those to spaces using tr
187+
# 6. Finally we use sed to trim leading and trailing spaces
188+
echo "$RUN_ARGS" | grep -Po '[[:space:]]-e[[:space:]]*[^[:space:]]+' | sed -r "s/\s+\-e\s+//g" | sed -r 's/^\x27|\x27$//g' | tr '\n' ' ' | sed -r 's/^\s*|\s*$//g'
189+
186190
}
187191

188192
fn-configure-app() {

0 commit comments

Comments
 (0)