2016-01-12 14:07:35 -08:00
|
|
|
#!/usr/bin/env bash
|
2019-01-07 01:04:17 -05:00
|
|
|
set -eo pipefail
|
|
|
|
|
[[ $DOKKU_TRACE ]] && set -x
|
2016-01-12 14:07:35 -08:00
|
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
|
|
|
|
|
|
|
|
AVAILABLE_PHASES=(build deploy run)
|
|
|
|
|
|
2017-02-20 19:25:48 -07:00
|
|
|
fn-get-phase-file-path() {
|
|
|
|
|
declare desc="return docker-options config file path for specified phase"
|
|
|
|
|
local APP="$1" PHASE="$2"
|
|
|
|
|
local PHASE_FILE="${DOKKU_ROOT}/${APP}/DOCKER_OPTIONS_${PHASE^^}"
|
|
|
|
|
echo "$PHASE_FILE"
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-12 14:07:35 -08:00
|
|
|
get_phase_file_path() {
|
2016-03-08 15:30:34 -05:00
|
|
|
declare desc="return docker-options config file path for specified phase"
|
2016-01-12 14:07:35 -08:00
|
|
|
local phase_file_prefix="DOCKER_OPTIONS_"
|
2016-01-15 14:45:00 -08:00
|
|
|
local phase=$1
|
2017-02-20 19:25:48 -07:00
|
|
|
[[ "$APP" && "$phase" ]] || dokku_log_fail "Error: phase_file_path is incomplete."
|
2017-02-24 09:59:31 -07:00
|
|
|
fn-get-phase-file-path "$APP" "$phase"
|
2016-01-12 14:07:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get_phases() {
|
2016-03-08 15:30:34 -05:00
|
|
|
declare desc="returns array of passed passes if all are in allowed array"
|
2016-01-12 14:07:35 -08:00
|
|
|
local passed_phases_list="$1"
|
2021-02-13 02:22:21 -05:00
|
|
|
# shellcheck disable=SC2001
|
2019-01-07 01:04:17 -05:00
|
|
|
local -r phases_allowed=$(sed -e 's/ /\|/g' <<<"${AVAILABLE_PHASES[@]}")
|
2016-01-12 14:07:35 -08:00
|
|
|
local phase
|
|
|
|
|
local passed_phases
|
|
|
|
|
if [[ -n "$passed_phases_list" ]]; then
|
2019-01-07 01:04:17 -05:00
|
|
|
OIFS=$IFS
|
|
|
|
|
IFS=','
|
|
|
|
|
read -ra passed_phases <<<"$passed_phases_list"
|
2016-01-17 17:17:04 -08:00
|
|
|
IFS=$OIFS
|
2016-01-12 14:07:35 -08:00
|
|
|
for phase in "${passed_phases[@]}"; do
|
2019-01-07 01:04:17 -05:00
|
|
|
[[ "$phase" == @($phases_allowed) ]] || dokku_log_fail "Phase(s) must be one of [${AVAILABLE_PHASES[*]}]"
|
2016-01-12 14:07:35 -08:00
|
|
|
done
|
|
|
|
|
echo "${passed_phases[@]}"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_phase_file_if_required() {
|
2016-03-08 15:30:34 -05:00
|
|
|
declare desc="create phase file"
|
2016-01-12 14:07:35 -08:00
|
|
|
local phase_file_path="$1"
|
|
|
|
|
[[ -f "$phase_file_path" ]] || {
|
|
|
|
|
touch "$phase_file_path"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
display_phase_options() {
|
2016-03-08 15:30:34 -05:00
|
|
|
declare desc="print docker-options for specified phase"
|
2016-01-12 14:07:35 -08:00
|
|
|
local phase="$1"
|
|
|
|
|
local phase_file_path="$2"
|
|
|
|
|
echo "${phase^} options:"
|
|
|
|
|
sed -e 's/^/ /' "$phase_file_path"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
display_all_phases_options() {
|
2016-03-08 15:30:34 -05:00
|
|
|
declare desc="print docker-options for all phases"
|
2016-01-12 14:07:35 -08:00
|
|
|
local phases=("${AVAILABLE_PHASES[@]}")
|
|
|
|
|
for phase in "${phases[@]}"; do
|
2016-03-02 10:50:09 -08:00
|
|
|
local phase_file_path="$(get_phase_file_path "$phase")"
|
2016-01-12 14:07:35 -08:00
|
|
|
if [[ -s "$phase_file_path" ]]; then
|
2019-01-07 01:04:17 -05:00
|
|
|
display_phase_options "$phase" "$phase_file_path"
|
2016-01-12 14:07:35 -08:00
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
display_passed_phases_options() {
|
2016-03-08 15:30:34 -05:00
|
|
|
declare desc="print docker options for list of specified phases"
|
2016-01-12 14:07:35 -08:00
|
|
|
local passed_phases=("${!1}")
|
|
|
|
|
local phase
|
|
|
|
|
for phase in "${passed_phases[@]}"; do
|
2016-03-02 10:50:09 -08:00
|
|
|
local phase_file_path="$(get_phase_file_path "$phase")"
|
2016-01-12 14:07:35 -08:00
|
|
|
if [[ ! -s "$phase_file_path" ]]; then
|
|
|
|
|
echo "${phase^} options: none"
|
|
|
|
|
else
|
|
|
|
|
display_phase_options "$phase" "$phase_file_path"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
add_passed_docker_option() {
|
2016-03-08 15:30:34 -05:00
|
|
|
declare desc="adds docker option to specified phases"
|
2016-01-12 14:07:35 -08:00
|
|
|
local passed_phases=("${!1}")
|
|
|
|
|
shift
|
|
|
|
|
local passed_option_string="$*"
|
|
|
|
|
local phase
|
|
|
|
|
for phase in "${passed_phases[@]}"; do
|
2016-03-02 10:50:09 -08:00
|
|
|
local phase_file_path="$(get_phase_file_path "$phase")"
|
2016-01-12 14:07:35 -08:00
|
|
|
create_phase_file_if_required "$phase_file_path"
|
2019-01-07 01:04:17 -05:00
|
|
|
echo "${passed_option_string}" >>"$phase_file_path"
|
|
|
|
|
local all_phase_options="$(<"$phase_file_path")"
|
|
|
|
|
echo -e "${all_phase_options}" | sed '/^$/d' | sort -u >"$phase_file_path"
|
2016-01-12 14:07:35 -08:00
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
remove_passed_docker_option() {
|
2016-03-08 15:30:34 -05:00
|
|
|
declare desc="removes docker option from specified phases"
|
2016-01-12 14:07:35 -08:00
|
|
|
local passed_phases=("${!1}")
|
|
|
|
|
shift
|
|
|
|
|
local passed_option_string="$*"
|
|
|
|
|
local phase
|
|
|
|
|
for phase in "${passed_phases[@]}"; do
|
2016-03-02 10:50:09 -08:00
|
|
|
local phase_file_path="$(get_phase_file_path "$phase")"
|
2016-01-12 14:07:35 -08:00
|
|
|
[[ ! -s "$phase_file_path" ]] || {
|
2019-01-07 01:04:17 -05:00
|
|
|
local all_phase_options="$(<"$phase_file_path")"
|
2016-03-02 10:50:09 -08:00
|
|
|
local all_phase_options=$(echo -e "${all_phase_options}" | sed "s#^${passed_option_string}\$##")
|
2019-01-07 01:04:17 -05:00
|
|
|
echo -e "${all_phase_options}" | sed '/^$/d' | sort -u >"$phase_file_path"
|
2016-01-12 14:07:35 -08:00
|
|
|
}
|
|
|
|
|
done
|
|
|
|
|
}
|