From b959a0bd56e4a7f9818fdbb3d31ef0af4fd1211b Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Wed, 16 Dec 2020 16:41:48 +0000 Subject: [PATCH 01/11] Test domain with dash. Refs #13 --- .github/workflows/test.yml | 2 ++ tests/suite.bats | 1 + tests/test_helper.bash | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d295c56..335bf95 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,3 +30,5 @@ jobs: sudo dokku plugin:install file:///$(pwd) discourse - name: Run tests run: sudo make test + env: + DISCOURSE_HOSTNAME: "discourse-test.dokku.me" diff --git a/tests/suite.bats b/tests/suite.bats index ef5f5d6..31e1d56 100644 --- a/tests/suite.bats +++ b/tests/suite.bats @@ -3,6 +3,7 @@ load test_helper @test "should create a new discourse app" { + echo "Deploying a new discourse app at $HOSTNAME" echo "127.0.0.1 $HOSTNAME" | sudo tee -a /etc/hosts dokku discourse:create "$APP_NAME" "$HOSTNAME" "$DEVELOPER_EMAILS" "$SMTP_ADDRESS" "$SMTP_PORT" "$SMTP_USER_NAME" "$SMTP_PASSWORD" grep -qxF "$(dokku apps:list 2> /dev/null)" <<< "$APP_NAME" diff --git a/tests/test_helper.bash b/tests/test_helper.bash index 471952d..3395314 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=${DISCOURSE_HOSTNAME:="discourse.dokku.me"} export DEVELOPER_EMAILS="me@example.com,you@example.com" export SMTP_ADDRESS="box.example.com" export SMTP_PORT="587" From 233cb3c063f566f846f16ffd1f35a1080de48f33 Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Wed, 16 Dec 2020 16:44:45 +0000 Subject: [PATCH 02/11] Run tests on 0.22.1 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 335bf95..14719dd 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 From a15de2700aa780e07ec4bf1922f3e8cb7f39b704 Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Wed, 16 Dec 2020 17:04:18 +0000 Subject: [PATCH 03/11] Fix echo hostname in tests --- .github/workflows/test.yml | 2 +- tests/suite.bats | 2 +- tests/test_helper.bash | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 14719dd..ba8d04e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,4 +31,4 @@ jobs: - name: Run tests run: sudo make test env: - DISCOURSE_HOSTNAME: "discourse-test.dokku.me" + HOSTNAME: "discourse-test.dokku.me" diff --git a/tests/suite.bats b/tests/suite.bats index 31e1d56..415b680 100644 --- a/tests/suite.bats +++ b/tests/suite.bats @@ -3,7 +3,7 @@ load test_helper @test "should create a new discourse app" { - echo "Deploying a new discourse app at $HOSTNAME" + echo "# Deploying a new discourse app at $HOSTNAME" >&3 echo "127.0.0.1 $HOSTNAME" | sudo tee -a /etc/hosts dokku discourse:create "$APP_NAME" "$HOSTNAME" "$DEVELOPER_EMAILS" "$SMTP_ADDRESS" "$SMTP_PORT" "$SMTP_USER_NAME" "$SMTP_PASSWORD" grep -qxF "$(dokku apps:list 2> /dev/null)" <<< "$APP_NAME" diff --git a/tests/test_helper.bash b/tests/test_helper.bash index 3395314..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_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" From fc79f77c878c1547387472967f9d06c6ff2b25a2 Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Thu, 17 Dec 2020 08:58:33 +0000 Subject: [PATCH 04/11] Remove debug --- internal-functions | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal-functions b/internal-functions index ec11794..c182502 100644 --- a/internal-functions +++ b/internal-functions @@ -208,10 +208,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 } From 393e914ba3e5bcc2f32e7633c8e0950d275fd55a Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Thu, 17 Dec 2020 19:38:37 +0000 Subject: [PATCH 05/11] Update test.yml --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ba8d04e..f2d4c1a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,4 +31,4 @@ jobs: - name: Run tests run: sudo make test env: - HOSTNAME: "discourse-test.dokku.me" + HOSTNAME: "an-engine.com" From 9b3c9c50aa4eaf44eb385f5f704b31a78d0637f2 Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Fri, 18 Dec 2020 11:48:35 +0000 Subject: [PATCH 06/11] Add debug --- internal-functions | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal-functions b/internal-functions index c182502..29df7d9 100644 --- a/internal-functions +++ b/internal-functions @@ -181,10 +181,15 @@ fn-configure-app() { local RUN_ARGS MAC_ADDRESS SHM_SIZE ENV_VARS RUN_ARGS=$(fn-get-run-args "$APP_NAME" 2>&1) + + echo "# RUN_ARGS: $RUN_ARGS" >&3 + 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') + echo "# ENV_VARS: $ENV_VARS" >&3 + domains_set "$APP_NAME" "$HOSTNAME" ## TODO: call plugin functions instead of dokku From 8af15b16bdca4e1a260f93e3403b582e78f9f38b Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Fri, 18 Dec 2020 11:57:23 +0000 Subject: [PATCH 07/11] Fix debug --- internal-functions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal-functions b/internal-functions index 29df7d9..86dff01 100644 --- a/internal-functions +++ b/internal-functions @@ -182,13 +182,13 @@ fn-configure-app() { local RUN_ARGS MAC_ADDRESS SHM_SIZE ENV_VARS RUN_ARGS=$(fn-get-run-args "$APP_NAME" 2>&1) - echo "# RUN_ARGS: $RUN_ARGS" >&3 + echo "# RUN_ARGS: $RUN_ARGS" 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') - echo "# ENV_VARS: $ENV_VARS" >&3 + echo "# ENV_VARS: $ENV_VARS" domains_set "$APP_NAME" "$HOSTNAME" From af52162549717e20032996a93905be101652b321 Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Fri, 18 Dec 2020 15:20:56 +0000 Subject: [PATCH 08/11] Fix run args env var extraction logic, with comments --- internal-functions | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal-functions b/internal-functions index 86dff01..8e3ebf7 100644 --- a/internal-functions +++ b/internal-functions @@ -174,6 +174,17 @@ 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 multple 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" @@ -186,7 +197,7 @@ fn-configure-app() { 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") echo "# ENV_VARS: $ENV_VARS" From 68cc9ddcfe501b5e85302290fd6cbebfc647f8bc Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Fri, 18 Dec 2020 15:31:01 +0000 Subject: [PATCH 09/11] Remove debug and add comments --- .github/workflows/test.yml | 3 ++- internal-functions | 8 ++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f2d4c1a..9eb1672 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,4 +31,5 @@ jobs: - name: Run tests run: sudo make test env: - HOSTNAME: "an-engine.com" + # "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 8e3ebf7..0119590 100644 --- a/internal-functions +++ b/internal-functions @@ -180,7 +180,7 @@ fn-get-env-vars-from-run-args() { # 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 multple consecutive whitespace chars + # 3. Next we use sed to remove "-e" flags as well as multiple consecutisssve 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' } @@ -191,16 +191,12 @@ fn-configure-app() { 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) - - echo "# RUN_ARGS: $RUN_ARGS" + 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=$(fn-get-env-vars-from-run-args "$RUN_ARGS") - echo "# ENV_VARS: $ENV_VARS" - domains_set "$APP_NAME" "$HOSTNAME" ## TODO: call plugin functions instead of dokku From 3b81928eac5bacde22d9b9ac75bd99e50d3a542f Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Fri, 18 Dec 2020 15:36:06 +0000 Subject: [PATCH 10/11] Remove test debug --- tests/suite.bats | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/suite.bats b/tests/suite.bats index 415b680..ef5f5d6 100644 --- a/tests/suite.bats +++ b/tests/suite.bats @@ -3,7 +3,6 @@ load test_helper @test "should create a new discourse app" { - echo "# Deploying a new discourse app at $HOSTNAME" >&3 echo "127.0.0.1 $HOSTNAME" | sudo tee -a /etc/hosts dokku discourse:create "$APP_NAME" "$HOSTNAME" "$DEVELOPER_EMAILS" "$SMTP_ADDRESS" "$SMTP_PORT" "$SMTP_USER_NAME" "$SMTP_PASSWORD" grep -qxF "$(dokku apps:list 2> /dev/null)" <<< "$APP_NAME" From f9ae1caeb2a95f2772969756f6a079b109566aa8 Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Fri, 18 Dec 2020 15:46:15 +0000 Subject: [PATCH 11/11] Fix spelling --- internal-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal-functions b/internal-functions index 0119590..e87e334 100644 --- a/internal-functions +++ b/internal-functions @@ -180,7 +180,7 @@ fn-get-env-vars-from-run-args() { # 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 consecutisssve whitespace chars + # 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' }