diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d295c56..9eb1672 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: name: Lint & run tests strategy: matrix: - dokku-version: ["v0.21.4", "v0.22.0"] + dokku-version: ["v0.21.4", "v0.22.0", "v0.22.1"] steps: - uses: actions/checkout@v1 - name: Install test tools @@ -30,3 +30,6 @@ jobs: sudo dokku plugin:install file:///$(pwd) discourse - name: Run tests run: sudo make test + env: + # "an-engine" is used to test the env var parsing logic (-e), see issue #13 + HOSTNAME: "an-engine.discourse.dokku.me" diff --git a/internal-functions b/internal-functions index ec11794..e87e334 100644 --- a/internal-functions +++ b/internal-functions @@ -174,16 +174,28 @@ fn-upgrade-app() { fn-build-image "$APP_NAME" } +fn-get-env-vars-from-run-args() { + declare RUN_ARGS="$1" + # 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' +} + fn-configure-app() { declare APP_NAME="$1" HOSTNAME="$2" APP_STORAGE_ROOT="$3" dokku_log_info1 "Generating docker config..." local RUN_ARGS MAC_ADDRESS SHM_SIZE ENV_VARS + RUN_ARGS=$(fn-get-run-args "$APP_NAME" 2>&1) MAC_ADDRESS=$(echo "$RUN_ARGS" | sed -r 's/.*--mac-address(=| )([^ ]+).*/\2/') SHM_SIZE=$(echo "$RUN_ARGS" | sed -r 's/.*--shm-size(=| )([^ ]+).*/\2/') - ENV_VARS=$(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') + ENV_VARS=$(fn-get-env-vars-from-run-args "$RUN_ARGS") domains_set "$APP_NAME" "$HOSTNAME" @@ -208,10 +220,8 @@ fn-configure-app() { ## TODO: call plugin functions instead of dokku if fn-version-greater-equal "0.22.0"; then - echo "great than 0.22.0" dokku ps:set "$APP_NAME" restart-policy always else - echo "lower than 0.22.0" dokku ps:set-restart-policy "$APP_NAME" always fi } diff --git a/tests/test_helper.bash b/tests/test_helper.bash index 471952d..7a0204b 100644 --- a/tests/test_helper.bash +++ b/tests/test_helper.bash @@ -1,7 +1,7 @@ #!/usr/bin/env bash export APP_NAME="discourse-app" -export HOSTNAME="discourse.dokku.me" +export HOSTNAME=${HOSTNAME:="discourse.dokku.me"} export DEVELOPER_EMAILS="me@example.com,you@example.com" export SMTP_ADDRESS="box.example.com" export SMTP_PORT="587"