more style/function tweaks
This commit is contained in:
committed by
Michael Hobbs
parent
89f289b433
commit
aa2415eeb8
@@ -1,71 +1,78 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
STDIN=$(cat)
|
||||
APP="$1"; IMAGE_SOURCE_TYPE="$2"
|
||||
docker_args() {
|
||||
local desc="docker args plugin trigger"
|
||||
local trigger="$0"
|
||||
local STDIN=$(cat)
|
||||
local APP="$1"; local IMAGE_SOURCE_TYPE="$2"
|
||||
|
||||
case "$0" in
|
||||
*docker-args-build)
|
||||
PHASE=BUILD
|
||||
;;
|
||||
*docker-args-deploy)
|
||||
PHASE=DEPLOY
|
||||
;;
|
||||
*docker-args-run)
|
||||
PHASE=RUN
|
||||
;;
|
||||
esac
|
||||
case "$0" in
|
||||
*docker-args-build)
|
||||
local PHASE=BUILD
|
||||
;;
|
||||
*docker-args-deploy)
|
||||
local PHASE=DEPLOY
|
||||
;;
|
||||
*docker-args-run)
|
||||
local PHASE=RUN
|
||||
;;
|
||||
esac
|
||||
|
||||
FILE_PREFIX="DOCKER_OPTIONS_"
|
||||
PHASE_FILE_PATH="${DOKKU_ROOT}/${APP}/${FILE_PREFIX}${PHASE}"
|
||||
local FILE_PREFIX="DOCKER_OPTIONS_"
|
||||
local PHASE_FILE_PATH="${DOKKU_ROOT}/${APP}/${FILE_PREFIX}${PHASE}"
|
||||
|
||||
output=""
|
||||
local output=""
|
||||
|
||||
if [[ -f "$PHASE_FILE_PATH" ]]; then
|
||||
DONE=false
|
||||
until $DONE; do
|
||||
read -r line || DONE=true
|
||||
if [[ -f "$PHASE_FILE_PATH" ]]; then
|
||||
local DONE=false
|
||||
until $DONE; do
|
||||
local line
|
||||
read -r line || local DONE=true
|
||||
|
||||
[[ ! -n "$line" ]] && continue
|
||||
[[ ! -n "$line" ]] && continue
|
||||
|
||||
# shellcheck disable=SC1001
|
||||
case "$line" in
|
||||
\#*)
|
||||
continue
|
||||
;;
|
||||
*)
|
||||
case "$IMAGE_SOURCE_TYPE" in
|
||||
dockerfile)
|
||||
case "$line" in
|
||||
--link*|-v*)
|
||||
continue
|
||||
;;
|
||||
# shellcheck disable=SC1001
|
||||
case "$line" in
|
||||
\#*)
|
||||
continue
|
||||
;;
|
||||
*)
|
||||
case "$IMAGE_SOURCE_TYPE" in
|
||||
dockerfile)
|
||||
case "$line" in
|
||||
--link*|-v*)
|
||||
continue
|
||||
;;
|
||||
|
||||
*)
|
||||
output="$output $line"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
local output="$output $line"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
herokuish)
|
||||
case "$line" in
|
||||
--file*|--build-args*)
|
||||
continue
|
||||
;;
|
||||
herokuish)
|
||||
case "$line" in
|
||||
--file*|--build-args*)
|
||||
continue
|
||||
;;
|
||||
|
||||
*)
|
||||
output="$output $line"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
local output="$output $line"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
*)
|
||||
output="$output $line"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
done < "$PHASE_FILE_PATH"
|
||||
fi
|
||||
*)
|
||||
local output="$output $line"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
done < "$PHASE_FILE_PATH"
|
||||
fi
|
||||
|
||||
echo "$STDIN$output"
|
||||
echo "$STDIN$output"
|
||||
}
|
||||
|
||||
docker_args "$@"
|
||||
|
||||
@@ -49,8 +49,7 @@ display_all_phases_options() {
|
||||
local desc="print docker-options for all phases"
|
||||
local phases=("${AVAILABLE_PHASES[@]}")
|
||||
for phase in "${phases[@]}"; do
|
||||
local phase_file_path
|
||||
phase_file_path="$(get_phase_file_path "$phase")"
|
||||
local phase_file_path="$(get_phase_file_path "$phase")"
|
||||
if [[ -s "$phase_file_path" ]]; then
|
||||
display_phase_options "$phase" "$phase_file_path"
|
||||
fi
|
||||
@@ -62,8 +61,7 @@ display_passed_phases_options() {
|
||||
local passed_phases=("${!1}")
|
||||
local phase
|
||||
for phase in "${passed_phases[@]}"; do
|
||||
local phase_file_path
|
||||
phase_file_path="$(get_phase_file_path "$phase")"
|
||||
local phase_file_path="$(get_phase_file_path "$phase")"
|
||||
if [[ ! -s "$phase_file_path" ]]; then
|
||||
echo "${phase^} options: none"
|
||||
else
|
||||
@@ -79,11 +77,10 @@ add_passed_docker_option() {
|
||||
local passed_option_string="$*"
|
||||
local phase
|
||||
for phase in "${passed_phases[@]}"; do
|
||||
local phase_file_path
|
||||
phase_file_path="$(get_phase_file_path "$phase")"
|
||||
local phase_file_path="$(get_phase_file_path "$phase")"
|
||||
create_phase_file_if_required "$phase_file_path"
|
||||
echo "${passed_option_string}" >> "$phase_file_path"
|
||||
all_phase_options="$(< "$phase_file_path")"
|
||||
local all_phase_options="$(< "$phase_file_path")"
|
||||
echo -e "${all_phase_options}" | sed '/^$/d' | sort -u > "$phase_file_path"
|
||||
done
|
||||
}
|
||||
@@ -95,11 +92,10 @@ remove_passed_docker_option() {
|
||||
local passed_option_string="$*"
|
||||
local phase
|
||||
for phase in "${passed_phases[@]}"; do
|
||||
local phase_file_path
|
||||
phase_file_path="$(get_phase_file_path "$phase")"
|
||||
local phase_file_path="$(get_phase_file_path "$phase")"
|
||||
[[ ! -s "$phase_file_path" ]] || {
|
||||
all_phase_options="$(< "$phase_file_path")"
|
||||
all_phase_options=$(echo -e "${all_phase_options}" | sed "s#^${passed_option_string}\$##")
|
||||
local all_phase_options="$(< "$phase_file_path")"
|
||||
local all_phase_options=$(echo -e "${all_phase_options}" | sed "s#^${passed_option_string}\$##")
|
||||
echo -e "${all_phase_options}" | sed '/^$/d' | sort -u > "$phase_file_path"
|
||||
}
|
||||
done
|
||||
|
||||
@@ -10,7 +10,7 @@ docker_options_add_cmd() {
|
||||
verify_app_name "$2" && local APP="$2"
|
||||
read -ra passed_phases <<< "$(get_phases "$3")"
|
||||
shift 3 # everything else passed is the docker option
|
||||
passed_docker_option="$*"
|
||||
local passed_docker_option="$*"
|
||||
[[ -z "$passed_docker_option" ]] && dokku_log_fail "Please specify docker options to add to the phase"
|
||||
add_passed_docker_option passed_phases[@] "${passed_docker_option[@]}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user