Skip to content

Commit a3787ee

Browse files
authored
Add support for domains with dashes (#14)
* Test domain with dash. Refs #13 * Run tests on 0.22.1 * Fix echo hostname in tests * Remove debug * Update test.yml * Add debug * Fix debug * Fix run args env var extraction logic, with comments * Remove debug and add comments * Remove test debug * Fix spelling
1 parent ef1c58f commit a3787ee

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
name: Lint & run tests
1313
strategy:
1414
matrix:
15-
dokku-version: ["v0.21.4", "v0.22.0"]
15+
dokku-version: ["v0.21.4", "v0.22.0", "v0.22.1"]
1616
steps:
1717
- uses: actions/checkout@v1
1818
- name: Install test tools
@@ -30,3 +30,6 @@ jobs:
3030
sudo dokku plugin:install file:///$(pwd) discourse
3131
- name: Run tests
3232
run: sudo make test
33+
env:
34+
# "an-engine" is used to test the env var parsing logic (-e), see issue #13
35+
HOSTNAME: "an-engine.discourse.dokku.me"

internal-functions

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,28 @@ fn-upgrade-app() {
174174
fn-build-image "$APP_NAME"
175175
}
176176

177+
fn-get-env-vars-from-run-args() {
178+
declare RUN_ARGS="$1"
179+
# 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
180+
# We want to extract the env vars from the string and produce a new string in form "ENV=var ENV2=var"
181+
# 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'
186+
}
187+
177188
fn-configure-app() {
178189
declare APP_NAME="$1" HOSTNAME="$2" APP_STORAGE_ROOT="$3"
179190

180191
dokku_log_info1 "Generating docker config..."
181192

182193
local RUN_ARGS MAC_ADDRESS SHM_SIZE ENV_VARS
194+
183195
RUN_ARGS=$(fn-get-run-args "$APP_NAME" 2>&1)
184196
MAC_ADDRESS=$(echo "$RUN_ARGS" | sed -r 's/.*--mac-address(=| )([^ ]+).*/\2/')
185197
SHM_SIZE=$(echo "$RUN_ARGS" | sed -r 's/.*--shm-size(=| )([^ ]+).*/\2/')
186-
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')
198+
ENV_VARS=$(fn-get-env-vars-from-run-args "$RUN_ARGS")
187199

188200
domains_set "$APP_NAME" "$HOSTNAME"
189201

@@ -208,10 +220,8 @@ fn-configure-app() {
208220

209221
## TODO: call plugin functions instead of dokku
210222
if fn-version-greater-equal "0.22.0"; then
211-
echo "great than 0.22.0"
212223
dokku ps:set "$APP_NAME" restart-policy always
213224
else
214-
echo "lower than 0.22.0"
215225
dokku ps:set-restart-policy "$APP_NAME" always
216226
fi
217227
}

tests/test_helper.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
export APP_NAME="discourse-app"
4-
export HOSTNAME="discourse.dokku.me"
4+
export HOSTNAME=${HOSTNAME:="discourse.dokku.me"}
55
export DEVELOPER_EMAILS="[email protected],[email protected]"
66
export SMTP_ADDRESS="box.example.com"
77
export SMTP_PORT="587"

0 commit comments

Comments
 (0)