Use config_export function instead of calling dokku as a subcommand

This commit is contained in:
Jose Diaz-Gonzalez
2015-08-30 01:55:14 -04:00
parent cddc4afcea
commit e7c035e207
8 changed files with 40 additions and 21 deletions

View File

@@ -335,6 +335,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
# `DOKKU_DISABLE_DEPLOY` env var is set to `true` for an app
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_PATH/config/functions"
CONTAINERID="$1"; APP="$2"; PORT="$3" ; HOSTNAME="${4:-localhost}"

View File

@@ -1,13 +1,14 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_PATH/common/functions"
source "$PLUGIN_PATH/config/functions"
case "$1" in
build)
APP="$2"; IMAGE="dokku/$APP"; IMAGE_SOURCE_TYPE="$3"; TMP_WORK_DIR="$4"
CACHE_DIR="$DOKKU_ROOT/$APP/cache"
eval "$(dokku config $APP --export)"
eval "$(config_export app $APP)"
pushd "$TMP_WORK_DIR" &> /dev/null
case "$IMAGE_SOURCE_TYPE" in
@@ -65,17 +66,17 @@ case "$1" in
# *DEPRECATED* in v0.3.22: `pluginhook pre-release-buildstep` will be removed in future releases
pluginhook pre-release-buildstep "$APP"
pluginhook pre-release-buildpack "$APP"
if [[ -n $(dokku config --global --export) ]]; then
if [[ -n $(config_export global) ]]; then
TMPFILE=$(mktemp /tmp/dokku.XXXXXX) || dokku_log_fail "Cannot create temp file using mktemp in /tmp dir"
dokku config --global --export > $TMPFILE
config_export global > $TMPFILE
id=$(docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/00-global-env.sh" < "$TMPFILE")
test "$(docker wait $id)" -eq 0
docker commit $id $IMAGE > /dev/null
rm -rf $TMPFILE
fi
if [[ -n $(dokku config $APP --export) ]]; then
if [[ -n $(config_export app $APP) ]]; then
TMPFILE=$(mktemp /tmp/dokku.XXXXXX) || dokku_log_fail "Cannot create temp file using mktemp in /tmp dir"
dokku config $APP --export > $TMPFILE
config_export app $APP > $TMPFILE
id=$(docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/01-app-env.sh" < "$TMPFILE")
test "$(docker wait $id)" -eq 0
docker commit $id $IMAGE > /dev/null
@@ -191,7 +192,7 @@ case "$1" in
verify_app_name "$2"
APP="$2";
eval "$(dokku config $APP --export)"
eval "$(config_export app $APP)"
if [[ -s "$DOKKU_ROOT/$APP/URLS" ]]; then
case "$1" in

View File

@@ -1,6 +1,7 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_PATH/common/functions"
source "$PLUGIN_PATH/config/functions"
APP="$1"; IMAGE="dokku/$APP"; BUILD_ENV=""
@@ -12,14 +13,14 @@ APP="$1"; IMAGE="dokku/$APP"; BUILD_ENV=""
dokku config:get --global CURL_CONNECT_TIMEOUT > /dev/null 2>&1 || dokku config:set --global CURL_CONNECT_TIMEOUT=5
dokku config:get --global CURL_TIMEOUT > /dev/null 2>&1 || dokku config:set --global CURL_TIMEOUT=30
if [[ -n $(dokku config --global --export) ]]; then
if [[ -n $(config_export global) ]]; then
BUILD_ENV+=$'\n'
BUILD_ENV+=$(dokku config --global --export)
BUILD_ENV+=$(config_export global)
BUILD_ENV+=$'\n'
fi
if [[ -n $(dokku config $APP --export) ]]; then
if [[ -n $(config_export app $APP) ]]; then
BUILD_ENV+=$'\n'
BUILD_ENV+=$(dokku config $APP --export)
BUILD_ENV+=$(config_export app $APP)
BUILD_ENV+=$'\n'
fi

View File

@@ -36,6 +36,7 @@
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_PATH/common/functions"
source "$PLUGIN_PATH/config/functions"
APP="$1"; DOKKU_APP_CONTAINER_ID="$2"; DOKKU_APP_CONTAINER_TYPE="$3"; DOKKU_APP_LISTEN_PORT="$4"; DOKKU_APP_LISTEN_IP="$5"
if [[ -z "$DOKKU_APP_LISTEN_PORT" ]] && [[ -f "$DOKKU_ROOT/$APP/PORT" ]]; then
@@ -51,8 +52,8 @@ fi
# source global and in-app envs to get DOKKU_CHECKS_WAIT and any other necessary vars
eval "$(dokku config --global $APP --export)"
eval "$(dokku config $APP --export)"
eval "$(config_export global)"
eval "$(config_export app $APP)"
# Wait this many seconds (default 5) for server to start before running checks.
WAIT="${DOKKU_CHECKS_WAIT:-5}"

View File

@@ -89,9 +89,9 @@ case "$1" in
config)
parse_config_args "$@"
config_create
is_config_export "$@" && config_export "$DOKKU_CONFIG_TYPE" "$APP" && exit 0
[[ "$APP" ]] && DOKKU_CONFIG_TYPE=$APP
[[ ! -s $ENV_FILE ]] && is_config_export "$@" && exit 0
[[ ! -s $ENV_FILE ]] && echo "no config vars for $DOKKU_CONFIG_TYPE" && exit 1
VARS=$(grep -Eo "export ([a-zA-Z_][a-zA-Z0-9_]*=.*)" $ENV_FILE | cut -d" " -f2-)
@@ -101,10 +101,6 @@ case "$1" in
echo $VARS
exit 0
fi
if [[ "$var" == "--export" ]]; then
echo "$VARS" | awk '{print "export " $0}'
exit 0
fi
done

View File

@@ -1,14 +1,15 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_PATH/common/functions"
source "$PLUGIN_PATH/config/functions"
STDIN=$(cat); APP="$1"; IMAGE="dokku/$APP"
DOCKERFILE_ENV_FILE="$DOKKU_ROOT/$APP/DOCKERFILE_ENV_FILE"
if ! is_image_herokuish_based "$IMAGE"; then
> "$DOCKERFILE_ENV_FILE"
dokku config --global --export | sed -e "s:^export ::g" -e "s:=':=:g" -e "s:'$::g" > "$DOCKERFILE_ENV_FILE"
dokku config "$APP" --export | sed -e "s:^export ::g" -e "s:=':=:g" -e "s:'$::g" >> "$DOCKERFILE_ENV_FILE"
config_export global | sed -e "s:^export ::g" -e "s:=':=:g" -e "s:'$::g" > "$DOCKERFILE_ENV_FILE"
config_export app $APP | sed -e "s:^export ::g" -e "s:=':=:g" -e "s:'$::g" >> "$DOCKERFILE_ENV_FILE"
echo "$STDIN --env-file=$DOCKERFILE_ENV_FILE"
else

17
plugins/config/functions Normal file
View File

@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_PATH/common/functions"
config_export() {
local CONFIG_TYPE="$1"
local APP="$2"
local ENV_FILE="$DOKKU_ROOT/$APP/ENV"
[[ $CONFIG_TYPE == "global" ]] && ENV_FILE="$DOKKU_ROOT/ENV"
[[ ! -f $ENV_FILE ]] && return 0
[[ ! -s $ENV_FILE ]] && return 0
VARS=$(grep -Eo "export ([a-zA-Z_][a-zA-Z0-9_]*=.*)" $ENV_FILE | cut -d" " -f2-)
echo "$VARS" | awk '{print "export " $0}'
return 0
}

View File

@@ -1,6 +1,7 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_PATH/common/functions"
source "$PLUGIN_PATH/config/functions"
validate_nginx () {
set +e
@@ -52,8 +53,8 @@ case "$1" in
DOKKU_APP_CIDS=($(get_app_container_ids $APP))
docker cp "${DOKKU_APP_CIDS[0]}:/app/nginx.conf.template" "$DOKKU_ROOT/$APP/" 2> /dev/null || true
eval "$(dokku config --global $APP --export)"
eval "$(dokku config $APP --export)"
eval "$(config_export global)"
eval "$(config_export app $APP)"
[[ -f "$APP_NGINX_TEMPLATE" ]] && NGINX_TEMPLATE="$APP_NGINX_TEMPLATE" && NGINX_CUSTOM_TEMPLATE="true" && dokku_log_info1 'Overriding default nginx.conf with detected nginx.conf.template'
if [[ ! -n "$NO_VHOST" ]] && [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then