From 5fb30ab9344be2a0e5e1c102dea3e922de32f16b Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Tue, 3 Feb 2015 13:46:56 -0800 Subject: [PATCH] source global env prior to app env. closes #931 --- docs/configuration-management.md | 2 +- dokku | 7 ++++++- plugins/checks/check-deploy | 1 + plugins/nginx-vhosts/commands | 1 + tests/unit/config.bats | 10 ++++++++++ 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/configuration-management.md b/docs/configuration-management.md index 72ad94174..eaad8e900 100644 --- a/docs/configuration-management.md +++ b/docs/configuration-management.md @@ -13,4 +13,4 @@ config:unset KEY1 [KEY2 ...] - unset one or more config vars The variables are available both at at run time and during the application build/compilation step. You no longer need a `user-env` plugin as Dokku handles this functionality in a way equivalent to how Heroku handles it. -> Note: Global `BUILD_ENV` files are currently migrated into a global `ENV` file. Configuring your global `ENV` file is manual, and should be considered potentially dangerous as configuration applies to all applications. +> Note: Global `BUILD_ENV` files are currently migrated into a global `ENV` file and sourced before app-specific variables. This means that app-specific variables will take precedence over global variables. Configuring your global `ENV` file is manual, and should be considered potentially dangerous as configuration applies to all applications. diff --git a/dokku b/dokku index 36e318c35..5a9f9f436 100755 --- a/dokku +++ b/dokku @@ -67,8 +67,13 @@ case "$1" in release) APP="$2"; IMAGE="dokku/$APP" pluginhook pre-release $APP + if [[ -f "$DOKKU_ROOT/ENV" ]]; then + id=$(docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/00-global-env.sh" < "$DOKKU_ROOT/ENV") + test "$(docker wait $id)" -eq 0 + docker commit $id $IMAGE > /dev/null + fi if [[ -f "$DOKKU_ROOT/$APP/ENV" ]]; then - id=$(docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/app-env.sh" < "$DOKKU_ROOT/$APP/ENV") + id=$(docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/01-app-env.sh" < "$DOKKU_ROOT/$APP/ENV") test "$(docker wait $id)" -eq 0 docker commit $id $IMAGE > /dev/null fi diff --git a/plugins/checks/check-deploy b/plugins/checks/check-deploy index be0c93625..ff82af9c5 100755 --- a/plugins/checks/check-deploy +++ b/plugins/checks/check-deploy @@ -18,6 +18,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x CONTAINERID="$1"; APP="$2"; PORT="$3" ; HOSTNAME="${4:-localhost}" # source in app env to get DOKKU_CHECKS_WAIT and any other necessary vars +[[ -f "$DOKKU_ROOT/ENV" ]] && source $DOKKU_ROOT/ENV [[ -f "$DOKKU_ROOT/$APP/ENV" ]] && source $DOKKU_ROOT/$APP/ENV # echo "DOKKU_CHECKS_WAIT is $DOKKU_CHECKS_WAIT" FILENAME="$DOKKU_ROOT/$APP/CHECKS" diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index 3ec06faa5..f0d797742 100755 --- a/plugins/nginx-vhosts/commands +++ b/plugins/nginx-vhosts/commands @@ -27,6 +27,7 @@ case "$1" in DOKKU_APP_LISTEN_IP=$(< "$DOKKU_ROOT/$APP/IP") fi + [[ -f "$DOKKU_ROOT/ENV" ]] && source $DOKKU_ROOT/ENV [[ -f "$DOKKU_ROOT/$APP/ENV" ]] && source $DOKKU_ROOT/$APP/ENV if [[ ! -n "$NO_VHOST" ]] && [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then diff --git a/tests/unit/config.bats b/tests/unit/config.bats index 2699c7619..2d09661bb 100644 --- a/tests/unit/config.bats +++ b/tests/unit/config.bats @@ -3,11 +3,13 @@ load test_helper setup() { + sudo -H -u dokku /bin/bash -c "echo 'export global_test=true' > $DOKKU_ROOT/ENV" create_app } teardown() { destroy_app + rm -f "$DOKKU_ROOT/ENV" } @test "config:set" { @@ -46,3 +48,11 @@ teardown() { echo "status: "$status assert_output "" } + +@test "config (global)" { + deploy_app + run bash -c "dokku run $TEST_APP env | egrep '^global_test=true'" + echo "output: "$output + echo "status: "$status + assert_success +}