[config] preliminary Dockerfile support
This commit is contained in:
@@ -7,15 +7,32 @@ config_docker_args() {
|
||||
declare desc="config docker-args plugin trigger"
|
||||
local trigger="$0 config_docker_args"
|
||||
local STDIN=$(cat); local APP="$1"; local IMAGE_TAG="$2"; local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG")
|
||||
local DOCKERFILE_ENV_FILE="$DOKKU_ROOT/$APP/DOCKERFILE_ENV_FILE"
|
||||
verify_app_name "$APP"
|
||||
|
||||
if ! is_image_herokuish_based "$IMAGE"; then
|
||||
> "$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"
|
||||
shopt -s extglob
|
||||
local ENV_ARGS
|
||||
declare -A ENV_ARGS
|
||||
for key in $(config_keys global); do
|
||||
VAR="$(config_get --global "$key")"
|
||||
printf -vVAR '%q' "${VAR%%*( )}"
|
||||
ENV_ARGS[$key]="$VAR"
|
||||
done
|
||||
for key in $(config_keys app "$APP"); do
|
||||
VAR="$(config_get "$APP" "$key")"
|
||||
printf -vVAR '%q' "${VAR%%*( )}"
|
||||
ENV_ARGS[$key]="$VAR"
|
||||
done
|
||||
shopt -u extglob
|
||||
local ALL_ENV_ARGS
|
||||
declare -a ALL_ENV_ARGS
|
||||
for key in "${!ENV_ARGS[@]}"; do
|
||||
local ARG="$key=${ENV_ARGS[$key]}"
|
||||
ALL_ENV_ARGS+=("--env")
|
||||
ALL_ENV_ARGS+=("$ARG")
|
||||
done
|
||||
|
||||
echo -n "$STDIN --env-file=$DOCKERFILE_ENV_FILE"
|
||||
echo -n "$STDIN ${ALL_ENV_ARGS[@]}"
|
||||
else
|
||||
echo -n "$STDIN"
|
||||
fi
|
||||
|
||||
@@ -13,6 +13,17 @@ config_export() {
|
||||
return 0
|
||||
}
|
||||
|
||||
config_keys() {
|
||||
declare desc="returns keys for app or global"
|
||||
local CONFIG_TYPE="$1"
|
||||
local APP="$2"
|
||||
if [[ $CONFIG_TYPE == "global" ]]; then
|
||||
APP="--global"
|
||||
fi
|
||||
$PLUGIN_AVAILABLE_PATH/config/subcommands/export config:export --keys "$APP"
|
||||
return 0
|
||||
}
|
||||
|
||||
config_get() {
|
||||
declare desc="get value of given config var"
|
||||
$PLUGIN_AVAILABLE_PATH/config/subcommands/get config:get "$@"
|
||||
|
||||
@@ -37,12 +37,13 @@ func (e *Env) stringWithEntryPrefix(prefix string) string {
|
||||
sort.Strings(keys)
|
||||
entries := make([]string, len(keys))
|
||||
for i, k := range keys {
|
||||
entries[i] = fmt.Sprintf("%s%s='%s'", prefix, k, singleQuoteEscape(e.env[k]))
|
||||
entries[i] = fmt.Sprintf("%s%s='%s'", prefix, k, SingleQuoteEscape(e.env[k]))
|
||||
}
|
||||
return strings.Join(entries, "\n")
|
||||
}
|
||||
|
||||
func singleQuoteEscape(value string) string { // so that 'esc'apped' -> 'esc'\''aped'
|
||||
//SingleQuoteEscape escapes the value as if it were shell-quoted in single quotes
|
||||
func SingleQuoteEscape(value string) string { // so that 'esc'apped' -> 'esc'\''aped'
|
||||
return strings.Replace(value, "'", "'\\''", -1)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
func main() {
|
||||
args := flag.NewFlagSet("config:export", flag.ExitOnError)
|
||||
global := args.Bool("global", false, "--global: use the global environment")
|
||||
keys := args.Bool("keys", false, "--keys: export keys only")
|
||||
envfile := args.Bool("envfile", false, "--envfile: export as envfile rather than bash exports")
|
||||
args.Parse(os.Args[2:])
|
||||
|
||||
@@ -32,6 +33,13 @@ func main() {
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
if *keys {
|
||||
for _, k := range env.Keys() {
|
||||
fmt.Println(k)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if *envfile {
|
||||
fmt.Println(env.EnvfileString())
|
||||
} else {
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
func main() {
|
||||
args := flag.NewFlagSet("config:get", flag.ExitOnError)
|
||||
global := args.Bool("global", false, "--global: use the global environment")
|
||||
quoted := args.Bool("quoted", false, "--quoted: get the value quoted")
|
||||
args.Parse(os.Args[2:])
|
||||
appName := args.Arg(0)
|
||||
nextArg := 0
|
||||
@@ -35,5 +36,10 @@ func main() {
|
||||
common.LogFail(fmt.Sprintf("Unexpected argument(s): %v", args.Args()[nextArg+1:]))
|
||||
}
|
||||
key := args.Arg(nextArg)
|
||||
fmt.Printf("%s", env.GetDefault(key, ""))
|
||||
value := env.GetDefault(key, "")
|
||||
if *quoted {
|
||||
fmt.Printf("'%s'", configenv.SingleQuoteEscape(value))
|
||||
} else {
|
||||
fmt.Printf("%s", value)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user