Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for domains with dashes #14

Merged
merged 12 commits into from
Dec 18, 2020
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
16 changes: 13 additions & 3 deletions internal-functions
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_helper.bash
Original file line number Diff line number Diff line change
@@ -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"
Expand Down