From 815cd530c8a834893d194c7bf53a419eaf290e3e Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 1 Nov 2020 17:45:44 -0500 Subject: [PATCH] chore: remove functions --- docs/appendices/0.22.0-migration-guide.md | 1 + plugins/ps/functions | 255 ---------------------- plugins/ps/internal-functions | 115 ---------- 3 files changed, 1 insertion(+), 370 deletions(-) diff --git a/docs/appendices/0.22.0-migration-guide.md b/docs/appendices/0.22.0-migration-guide.md index f520a56de..a4e4dc7f4 100644 --- a/docs/appendices/0.22.0-migration-guide.md +++ b/docs/appendices/0.22.0-migration-guide.md @@ -18,3 +18,4 @@ The `ps` command has had a few removals as a result of a rewrite to Golang: - The `ps:startall` command has been removed in favor of calling the `ps:start` with the `--all` flag instead of an app name. - The `DOKKU_PROCFILE` file is no longer located in the git directory for a given app on the server. It's location is currently not exposed. - The `procfile-get-command` plugin trigger no longer takes a `procfile path` as the final argument. +- All `ps` functions have been removed. Please us a trigger as appropriate or file a PR to have a new trigger/wrapper function added. diff --git a/plugins/ps/functions b/plugins/ps/functions index fec5beb55..7f5eecd21 100755 --- a/plugins/ps/functions +++ b/plugins/ps/functions @@ -2,135 +2,6 @@ set -eo pipefail [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/config/functions" - -get_cmd_from_procfile() { - declare desc="parse cmd from app Procfile" - declare APP="$1" PROC_TYPE="$2" PORT="${3:-5000}" - local DOKKU_PROCFILE="$DOKKU_ROOT/$APP/DOKKU_PROCFILE" - local COMMAND - verify_app_name "$APP" - - fn-procfile-get-command "$DOKKU_PROCFILE" "$PROC_TYPE" "$PORT" -} - -print_dokku_scale_file() { - declare desc="prints contents of DOKKU_SCALE file" - local APP="$1" - local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" - dokku_log_verbose_quiet "DOKKU_SCALE declares scale -> $(xargs <"$DOKKU_SCALE_FILE")" -} - -extract_procfile() { - declare desc="extracts procfile from app image" - local APP="$1" - local IMAGE_TAG="$2" - local IMAGE="$(get_deploying_app_image_name "$APP" "$IMAGE_TAG")" - local DOKKU_PROCFILE="$DOKKU_ROOT/$APP/DOKKU_PROCFILE" - verify_app_name "$APP" - - remove_procfile "$APP" - fn-procfile-extract "$IMAGE" "$DOKKU_PROCFILE" -} - -fn-procfile-extract() { - declare desc="extract procfile from a specified docker image" - declare IMAGE="$1" PROCFILE_PATH="$2" - - copy_from_image "$IMAGE" "Procfile" "$PROCFILE_PATH" 2>/dev/null || true - if [[ -f "$PROCFILE_PATH" ]]; then - dokku_log_info1_quiet "App Procfile file found" - # shellcheck disable=SC2069 - PROCFILE_ERRORS="$(procfile-util check --procfile "$PROCFILE_PATH" 2>&1 >/dev/null || true)" - if [[ -n "$PROCFILE_ERRORS" ]]; then - dokku_log_fail "${PROCFILE_ERRORS}" - fi - else - dokku_log_info1_quiet "No Procfile found in app image" - fi -} - -fn-procfile-get-command() { - declare desc="Fetch a command from a Procfile" - declare PROCFILE_PATH="$1" PROCESS_TYPE="$2" PORT="$3" - - if [[ ! -f "$PROCFILE_PATH" ]]; then - return - fi - - procfile-util show --procfile "$PROCFILE_PATH" --process-type "$PROCESS_TYPE" --default-port "$PORT" 2>/dev/null -} - -remove_procfile() { - declare desc="removes DOKKU_PROCFILE" - local APP="$1" - local DOKKU_PROCFILE="$DOKKU_ROOT/$APP/DOKKU_PROCFILE" - if [[ -f "$DOKKU_PROCFILE" ]]; then - rm -f "$DOKKU_PROCFILE" - fi -} - -generate_scale_file() { - declare desc="generates DOKKU_SCALE file" - local APP="$1" - local IMAGE_TAG="$2" - local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") - local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" - local DOKKU_PROCFILE="$DOKKU_ROOT/$APP/DOKKU_PROCFILE" - verify_app_name "$APP" - - if copy_from_image "$IMAGE" "DOKKU_SCALE" "$DOKKU_SCALE_FILE" 2>/dev/null; then - cp "$DOKKU_SCALE_FILE" "${DOKKU_SCALE_FILE}.extracted" - else - rm -f "${DOKKU_SCALE_FILE}.extracted" - fi - - if [[ ! -f $DOKKU_SCALE_FILE ]]; then - dokku_log_info1_quiet "DOKKU_SCALE file not found in app image. Generating one based on Procfile..." - - if [[ -f $DOKKU_PROCFILE ]]; then - while read -r line || [[ -n "$line" ]]; do - if [[ -z "$line" ]] || [[ "$line" == "#"* ]]; then - continue - fi - local NAME=${line%%:*} - local NUM_PROCS=0 - [[ "$NAME" == "web" ]] && NUM_PROCS=1 - [[ -n "$NAME" ]] && echo "$NAME=$NUM_PROCS" >>"$DOKKU_SCALE_FILE" - done < <(grep -v -E "^#" "$DOKKU_PROCFILE" | grep ':' | awk -F ':' '{ print $1 }' | sort | uniq) - else - echo "web=1" >>"$DOKKU_SCALE_FILE" - fi - fi - print_dokku_scale_file "$APP" -} - -set_scale() { - declare desc="sets app proc type scaling" - declare APP="$1" - local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" - local DOKKU_PROCFILE="$DOKKU_ROOT/$APP/DOKKU_PROCFILE" - shift 1 - - extract_procfile "$APP" "$IMAGE_TAG" >/dev/null - trap "remove_procfile $APP" RETURN INT TERM EXIT - - local SCALE_SETTINGS=("$@") - for procscale in "${SCALE_SETTINGS[@]}"; do - local PROC_NAME=${procscale%%=*} - local PROC_COUNT=${procscale#*=} - if [[ -f "$DOKKU_PROCFILE" ]] && [[ "$PROC_COUNT" != "0" ]] && ! procfile-util exists --procfile "$DOKKU_PROCFILE" --process-type "$PROC_NAME" >/dev/null 2>&1; then - dokku_log_fail "${PROC_NAME} is not a valid process name" - fi - is_number "$PROC_COUNT" || dokku_log_fail "ps:scale $PROC_COUNT is not a number" - dokku_log_info1_quiet "Scaling $APP:$PROC_NAME to $PROC_COUNT" - if (grep -q -E "^${PROC_NAME}=" "$DOKKU_SCALE_FILE" >/dev/null 2>&1); then - sed --in-place "s:^${PROC_NAME}=.*:$PROC_NAME=$PROC_COUNT:g" "$DOKKU_SCALE_FILE" - else - echo "$PROC_NAME=$PROC_COUNT" >>"$DOKKU_SCALE_FILE" - fi - done -} ps_restore() { declare desc="restores app" @@ -139,118 +10,6 @@ ps_restore() { ps_start "$APP" } -ps_start() { - declare desc="starts app" - local APP="$1" - verify_app_name "$APP" - local IMAGE_TAG=$(get_running_image_tag "$APP") - local RUNNING - - if (is_deployed "$APP"); then - plugn trigger pre-start "$APP" - RUNNING="$(fn-ps-is-app-running "$APP")" - - if [[ "$RUNNING" == "mixed" ]]; then - dokku_log_warn "App is running in mixed mode, releasing" - fi - - if [[ "$RUNNING" != "true" ]]; then - plugn trigger release-and-deploy "$APP" "$IMAGE_TAG" - else - dokku_log_warn "App $APP already running" - fi - plugn trigger proxy-build-config "$APP" - else - dokku_log_warn "App $APP has not been deployed" - fi -} - -ps_stop() { - declare desc="stops app" - local APP="$1" - verify_app_name "$APP" - - ! (is_deployed "$APP") && dokku_log_warn "App $APP has not been deployed" && exit 0 - - dokku_log_quiet "Stopping $APP ..." - local DOKKU_SCHEDULER=$(get_app_scheduler "$APP") - plugn trigger scheduler-stop "$DOKKU_SCHEDULER" "$APP" - plugn trigger post-stop "$APP" -} - -ps_rebuild() { - declare desc="rebuilds app from base image" - local APP="$1" - verify_app_name "$APP" - - plugn trigger receive-app "$APP" -} - -ps_restart() { - declare desc="restarts app" - local APP="$1" - verify_app_name "$APP" - local IMAGE_TAG=$(get_running_image_tag "$APP") - - if (is_deployed "$APP"); then - plugn trigger release-and-deploy "$APP" "$IMAGE_TAG" - else - dokku_log_warn "App $APP has not been deployed" - fi -} - -ps_scale() { - declare desc="sets app scaling config according arguments; otherwise according to DOKKU_SCALE file" - local APP="$1" - verify_app_name "$APP" - local IMAGE_TAG=$(get_running_image_tag "$APP") - local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" - local DOKKU_PROCFILE="$DOKKU_ROOT/$APP/DOKKU_PROCFILE" - shift 1 - - # shellcheck disable=SC2015 - [[ ! -e $DOKKU_PROCFILE ]] && extract_procfile "$APP" "$IMAGE_TAG" >/dev/null 2>&1 || true - if [[ ! -e $DOKKU_SCALE_FILE ]]; then - generate_scale_file "$APP" "$IMAGE_TAG" >/dev/null 2>&1 - elif [[ -e $DOKKU_PROCFILE ]]; then - for PROC_NAME in $(procfile-util list --procfile "$DOKKU_PROCFILE"); do - if ! grep -qE "^${PROC_NAME}=" "$DOKKU_SCALE_FILE"; then - echo "$PROC_NAME=0" >>"$DOKKU_SCALE_FILE" - fi - done - fi - if [[ -z "$@" ]]; then - dokku_log_info1_quiet "Scaling for $APP" - dokku_col_log_msg_quiet "proctype" "qty" - dokku_col_log_msg_quiet "--------" "---" - while read -r line || [[ -n "$line" ]]; do - [[ -z "$line" ]] && continue - local PROC_NAME=${line%%=*} - local PROC_COUNT=${line#*=} - dokku_col_log_msg "${PROC_NAME}:" "$PROC_COUNT" - done <"$DOKKU_SCALE_FILE" - else - if [[ "$(fn-ps-can-scale "$APP")" == "true" ]]; then - set_scale "$APP" "$@" - plugn trigger release-and-deploy "$APP" "$IMAGE_TAG" - else - dokku_log_fail "App contains DOKKU_SCALE file and cannot be manually scaled" - fi - fi -} - -get_raw_restart_policies() { - declare desc="strips docker options and prints raw restart policies" - local -r phase_file_path=$1 - [[ -r "$phase_file_path" ]] && sed -e '/^--restart=/!d' <"$phase_file_path" -} - -get_restart_policies() { - declare desc="strips docker options and prints restart policies" - local -r phase_file_path=$1 - get_raw_restart_policies "$phase_file_path" | sed -e 's/^--restart=//g' -} - fn-ps-app-status() { declare APP="$1" @@ -263,17 +22,3 @@ fn-ps-is-app-running() { APP_STATUS=$(fn-ps-app-status "$APP") echo "$APP_STATUS" | cut -d ' ' -f 2 } - -fn-ps-can-scale() { - declare APP="$1" - local IMAGE_TAG=$(get_running_image_tag "$APP") - local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" - local CAN_SCALE=false - - [[ ! -e $DOKKU_SCALE_FILE ]] && generate_scale_file "$APP" "$IMAGE_TAG" >/dev/null 2>&1 - if [[ ! -f "${DOKKU_SCALE_FILE}.extracted" ]]; then - CAN_SCALE=true - fi - - echo "$CAN_SCALE" -} diff --git a/plugins/ps/internal-functions b/plugins/ps/internal-functions index 8d863a87e..f21dcb4bc 100755 --- a/plugins/ps/internal-functions +++ b/plugins/ps/internal-functions @@ -6,121 +6,6 @@ source "$PLUGIN_AVAILABLE_PATH/ps/functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -cmd-ps-inspect() { - declare desc="displays a sanitized version of docker inspect for an app" - declare cmd="ps:inspect" - [[ "$1" == "$cmd" ]] && shift 1 - declare APP="$1" - - verify_app_name "$APP" - local DOKKU_SCHEDULER=$(get_app_scheduler "$APP") - plugn trigger scheduler-inspect "$DOKKU_SCHEDULER" "$APP" -} - -cmd-ps-report() { - declare desc="displays a ps report for one or more apps" - declare cmd="ps:report" - [[ "$1" == "$cmd" ]] && shift 1 - declare APP="$1" INFO_FLAG="$2" - local INSTALLED_APPS=$(dokku_apps) - - if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then - INFO_FLAG="$APP" - APP="" - fi - - if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then - INFO_FLAG="true" - fi - - if [[ -z "$APP" ]]; then - for app in $INSTALLED_APPS; do - cmd-ps-report-single "$app" "$INFO_FLAG" | tee || true - done - else - cmd-ps-report-single "$APP" "$INFO_FLAG" - fi -} - -cmd-ps-report-single() { - declare APP="$1" INFO_FLAG="$2" - local APP_DIR="$DOKKU_ROOT/$APP" - [[ "$INFO_FLAG" == "true" ]] && INFO_FLAG="" - - local APP_RUNNING="$(fn-ps-app-status "$APP")" - local PROCS=$(echo "$APP_RUNNING" | cut -d ' ' -f 1) - local RUNNING=$(echo "$APP_RUNNING" | cut -d ' ' -f 2) - - if (is_deployed "$APP"); then DEPLOYED="true"; else DEPLOYED="false"; fi - local passed_phases="deploy" - local RESTARTPOLICY=$(get_restart_policies "$(get_phase_file_path "$passed_phases")" || true) - local CAN_SCALE="$(fn-ps-can-scale "$APP")" - - local CONTAINER_FILES="$(find "$DOKKU_ROOT/$APP" -maxdepth 1 -name "CONTAINER.*" -printf "%f\n" 2>/dev/null | sort -t . -k 2 -n | xargs)" - local CONTAINER_FILE - local DOKKU_APP_RESTORE=$(config_get "$APP" DOKKU_APP_RESTORE || true) - local STATUSES=() - if [[ "$DOKKU_APP_RESTORE" != 0 ]]; then RESTORE="true"; else RESTORE="false"; fi - local APP_CONTAINER_STATUS - for CONTAINER_FILE in $CONTAINER_FILES; do - CID=$(<"$DOKKU_ROOT/$APP/$CONTAINER_FILE") - APP_CONTAINER_STATUS=$("$DOCKER_BIN" container inspect --format '{{.State.Status}}' "$CID" 2>/dev/null || true) - [[ -z "$APP_CONTAINER_STATUS" ]] && APP_CONTAINER_STATUS="missing" - STATUSES+=("${CONTAINER_FILE#*.}:$APP_CONTAINER_STATUS#${CID:0:12}") - done - local flag_map=( - "--processes: $PROCS" - "--deployed: $DEPLOYED" - "--running: $RUNNING" - "--restore: $RESTORE" - "--restart-policy: $RESTARTPOLICY" - "--ps-can-scale: $CAN_SCALE" - ) - - if [[ -z "$INFO_FLAG" ]]; then - dokku_log_info2_quiet "$APP ps information" - for flag in "${flag_map[@]}"; do - key="$(echo "${flag#--}" | cut -f1 -d' ' | tr - ' ')" - dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#*: }")" - done - for STATUS in "${STATUSES[@]}"; do - name=${STATUS%:*} - value=${STATUS#*:} - status=${value%#*} - cid=${value#*#} - dokku_log_verbose "$(printf "%-30s %-10s (CID: %s)" "Status $name:" "$status" "$cid")" - done - else - local match=false - local value_exists=false - for STATUS in "${STATUSES[@]}"; do - name=${STATUS%:*} - value=${STATUS#*:} - status=${value%#*} - cid=${value#*#} - status_flag="--status-$name" - flag_map+=("$status_flag: $status") - done - for flag in "${flag_map[@]}"; do - valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)" - if [[ "$flag" == "${INFO_FLAG}:"* ]]; then - value=${flag#*: } - size="${#value}" - if [[ "$size" -ne 0 ]]; then - echo "$value" && match=true && value_exists=true - else - match=true - fi - fi - done - if [[ "$match" == "true" ]]; then - [[ "$value_exists" == "true" ]] || dokku_log_fail "not deployed" - else - dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}" - fi - fi -} - fn-ps-parallel-cmd() { declare desc="Run a ps command against all apps" declare CMD="$1"