From 7078040dca33a3ca3a622463af2978a071fcd7a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl?= Date: Fri, 11 Jun 2021 13:10:38 +0200 Subject: [PATCH] feat: Add --skip-env-config switch --- README.md | 3 +++ functions | 12 +++++++----- internal-functions | 29 ++++++++++++++++------------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 1b4005e..1658fb7 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,9 @@ A discourse container config file is created when a discourse app is created. Th 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. +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 : +`dokku discourse:create --skip-env-config` + After making change be sure to run `dokku discourse:create ` to rebuild and re-deploy the discourse app. ### Upgrade a discourse app diff --git a/functions b/functions index aa25b09..2fc4e3c 100755 --- a/functions +++ b/functions @@ -25,11 +25,13 @@ discourse_create_app() { [[ -z "$APP_NAME" ]] && dokku_log_fail "Missing app argument" [[ -z "$HOSTNAME" ]] && HOSTNAME=$(fn-get-input "Hostname for your Discourse?" "$(fn-get-env-config DISCOURSE_HOSTNAME)") - [[ -z "$DEVELOPER_EMAILS" ]] && DEVELOPER_EMAILS=$(fn-get-input "Email address for admin account(s)?" "$(fn-get-env-config DISCOURSE_DEVELOPER_EMAILS)") - [[ -z "$SMTP_ADDRESS" ]] && SMTP_ADDRESS=$(fn-get-input "SMTP server address?" "$(fn-get-env-config DISCOURSE_SMTP_ADDRESS)") - [[ -z "$SMTP_PORT" ]] && SMTP_PORT=$(fn-get-input "SMTP port?" "$(fn-get-env-config DISCOURSE_SMTP_PORT)") - [[ -z "$SMTP_USERNAME" ]] && SMTP_USERNAME=$(fn-get-input "SMTP user name?" "$(fn-get-env-config DISCOURSE_SMTP_USER_NAME)") - [[ -z "$SMTP_PASSWORD" ]] && SMTP_PASSWORD=$(fn-get-input "SMTP password?" "$(fn-get-env-config DISCOURSE_SMTP_PASSWORD)") + if [ "$DEVELOPER_EMAILS" != "--skip-env-config" ]; then + [[ -z "$DEVELOPER_EMAILS" ]] && DEVELOPER_EMAILS=$(fn-get-input "Email address for admin account(s)?" "$(fn-get-env-config DISCOURSE_DEVELOPER_EMAILS)") + [[ -z "$SMTP_ADDRESS" ]] && SMTP_ADDRESS=$(fn-get-input "SMTP server address?" "$(fn-get-env-config DISCOURSE_SMTP_ADDRESS)") + [[ -z "$SMTP_PORT" ]] && SMTP_PORT=$(fn-get-input "SMTP port?" "$(fn-get-env-config DISCOURSE_SMTP_PORT)") + [[ -z "$SMTP_USERNAME" ]] && SMTP_USERNAME=$(fn-get-input "SMTP user name?" "$(fn-get-env-config DISCOURSE_SMTP_USER_NAME)") + [[ -z "$SMTP_PASSWORD" ]] && SMTP_PASSWORD=$(fn-get-input "SMTP password?" "$(fn-get-env-config DISCOURSE_SMTP_PASSWORD)") + fi local APP_STORAGE_ROOT="$STORAGE_ROOT/$APP_NAME" diff --git a/internal-functions b/internal-functions index e87e334..232a13e 100644 --- a/internal-functions +++ b/internal-functions @@ -84,15 +84,16 @@ fn-update-discourse-container-config() { SMTP_PORT="$6" \ SMTP_USER_NAME="$7" \ SMTP_PASSWORD="$8" - - fn-update-discourse-config-env \ - "$APP_NAME" \ - "$HOSTNAME" \ - "$DEVELOPER_EMAILS" \ - "$SMTP_ADDRESS" \ - "$SMTP_PORT" \ - "$SMTP_USER_NAME" \ - "$SMTP_PASSWORD" + if [ "$DEVELOPER_EMAILS" != "--skip-env-config" ]; then + fn-update-discourse-config-env \ + "$APP_NAME" \ + "$HOSTNAME" \ + "$DEVELOPER_EMAILS" \ + "$SMTP_ADDRESS" \ + "$SMTP_PORT" \ + "$SMTP_USER_NAME" \ + "$SMTP_PASSWORD" + fi fn-update-discourse-config-set-volumes "$APP_NAME" "$APP_STORAGE_ROOT" @@ -179,10 +180,12 @@ fn-get-env-vars-from-run-args() { # 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 # We want to extract the env vars from the string and produce a new string in form "ENV=var ENV2=var" # 1. We use grep to extract the "-e ENV=var" strings - # 2. grep will give us newlines, so we convert those to spaces using tr - # 3. Next we use sed to remove "-e" flags as well as multiple consecutive whitespace chars - # 4. Finally we use sed to trim leading and trailing spaces - 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' + # 2. Next we use sed to remove "-e" flags + # 3. Then we use sed to remove leading and trailing single quote if exists (docker env escaping strategy) + # 4. grep will give us newlines, so we convert those to spaces using tr + # 5. Finally we use sed to trim leading and trailing spaces + 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' + } fn-configure-app() {