2018-02-12 02:45:50 -05:00
|
|
|
#!/usr/bin/env bash
|
2019-01-07 01:04:17 -05:00
|
|
|
set -eo pipefail
|
|
|
|
|
[[ $DOKKU_TRACE ]] && set -x
|
2018-02-12 02:45:50 -05:00
|
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
2018-08-01 02:00:32 -04:00
|
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
|
2018-02-12 02:45:50 -05:00
|
|
|
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
|
|
|
|
|
2020-02-10 02:40:59 -05:00
|
|
|
trigger-scheduler-docker-local-pre-deploy() {
|
2018-02-12 02:45:50 -05:00
|
|
|
declare desc="scheduler-docker-local pre-deploy plugin trigger"
|
2020-02-10 02:40:59 -05:00
|
|
|
declare trigger="pre-deploy"
|
2018-02-12 02:45:50 -05:00
|
|
|
declare APP="$1" IMAGE_TAG="$2"
|
|
|
|
|
|
2018-09-30 21:36:53 -04:00
|
|
|
local DOKKU_SCHEDULER=$(get_app_scheduler "$APP")
|
2018-02-12 02:45:50 -05:00
|
|
|
if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
2019-11-20 11:09:11 -05:00
|
|
|
scheduler-docker-local-pre-deploy-chown-app "$APP" "$IMAGE_TAG"
|
|
|
|
|
scheduler-docker-local-pre-deploy-precheck "$APP" "$IMAGE_TAG"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scheduler-docker-local-pre-deploy-chown-app() {
|
|
|
|
|
declare desc="Runs chown against the /app directory for herokuish images"
|
|
|
|
|
declare APP="$1" IMAGE_TAG="$2"
|
2019-07-19 15:50:55 -04:00
|
|
|
local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$APP"
|
2019-11-20 11:09:11 -05:00
|
|
|
local IMAGE DISABLE_CHOWN DOCKER_ARGS DOKKU_APP_TYPE DOKKU_APP_USER APP_PATHS CONTAINER_PATHS
|
|
|
|
|
declare -a ARG_ARRAY
|
2019-06-29 15:33:24 -04:00
|
|
|
|
2018-02-12 02:45:50 -05:00
|
|
|
IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG")
|
|
|
|
|
|
|
|
|
|
DOKKU_APP_TYPE=$(config_get "$APP" DOKKU_APP_TYPE || true)
|
|
|
|
|
DOKKU_APP_USER=$(config_get "$APP" DOKKU_APP_USER || true)
|
|
|
|
|
DOKKU_APP_USER=${DOKKU_APP_USER:="herokuishuser"}
|
2021-01-23 12:32:31 -05:00
|
|
|
APP_PATHS=$(plugn trigger storage-list "$APP" "deploy")
|
2018-02-12 02:45:50 -05:00
|
|
|
|
|
|
|
|
if [[ -n "$APP_PATHS" ]]; then
|
|
|
|
|
CONTAINER_PATHS=$(echo "$APP_PATHS" | awk -F ':' '{ print $2 }' | xargs)
|
|
|
|
|
DOCKER_ARGS=$(: | plugn trigger docker-args-deploy "$APP" "$IMAGE_TAG")
|
2021-07-11 20:53:02 -04:00
|
|
|
|
2021-09-18 18:51:33 -04:00
|
|
|
filterdArgs=("--cpus" "--gpus" "--memory" "--memory-reservation" "--memory-swap" "--publish" "--publish-all" "-p" "-P" "--restart")
|
2021-07-11 20:53:02 -04:00
|
|
|
for filteredArg in "${filterdArgs[@]}"; do
|
|
|
|
|
# shellcheck disable=SC2001
|
|
|
|
|
DOCKER_ARGS=$(sed -e "s/$filteredArg=[[:graph:]]\+[[:blank:]]\?//g" <<<"$DOCKER_ARGS")
|
|
|
|
|
|
|
|
|
|
# shellcheck disable=SC2001
|
|
|
|
|
DOCKER_ARGS=$(sed -e "s/$filteredArg\+[[:blank:]][[:graph:]]\+[[:blank:]]\?//g" <<<"$DOCKER_ARGS")
|
|
|
|
|
done
|
|
|
|
|
|
2018-02-12 02:45:50 -05:00
|
|
|
eval "ARG_ARRAY=($DOCKER_ARGS)"
|
|
|
|
|
fi
|
|
|
|
|
|
2018-08-01 02:00:32 -04:00
|
|
|
if [[ "$DOKKU_APP_TYPE" != "herokuish" ]] || [[ -z "$CONTAINER_PATHS" ]]; then
|
|
|
|
|
return
|
2018-02-12 02:45:50 -05:00
|
|
|
fi
|
2018-08-01 02:00:32 -04:00
|
|
|
|
|
|
|
|
DISABLE_CHOWN="$(fn-plugin-property-get "scheduler-docker-local" "$APP" "disable-chown" "")"
|
|
|
|
|
if [[ "$DISABLE_CHOWN" == "true" ]]; then
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
2020-11-22 16:57:39 -05:00
|
|
|
"$DOCKER_BIN" container run --rm "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS "${ARG_ARRAY[@]}" $IMAGE /bin/bash -c "find $CONTAINER_PATHS -not -user $DOKKU_APP_USER -print0 | xargs -0 -r chown -R $DOKKU_APP_USER" || true
|
2018-02-12 02:45:50 -05:00
|
|
|
}
|
|
|
|
|
|
2019-11-20 11:09:11 -05:00
|
|
|
scheduler-docker-local-pre-deploy-precheck() {
|
|
|
|
|
declare desc="Outputs the checks messages if necessary"
|
|
|
|
|
declare APP="$1" IMAGE_TAG="$2"
|
2021-08-05 04:16:49 -04:00
|
|
|
local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG")
|
2019-11-20 11:09:11 -05:00
|
|
|
local CHECKS_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
|
2021-01-02 05:23:48 -05:00
|
|
|
trap "rm -rf '$CHECKS_FILE' >/dev/null" RETURN INT TERM EXIT
|
2019-12-09 17:28:49 -05:00
|
|
|
copy_from_image "$IMAGE" "CHECKS" "$CHECKS_FILE" 2>/dev/null || true
|
2019-11-20 11:09:11 -05:00
|
|
|
|
|
|
|
|
dokku_log_info2 "Processing deployment checks"
|
2019-12-09 17:28:49 -05:00
|
|
|
if [[ ! -s "${CHECKS_FILE}" ]]; then
|
2021-02-28 01:18:33 -05:00
|
|
|
local CHECKS_URL="${DOKKU_CHECKS_URL:-https://dokku.com/docs/deployment/zero-downtime-deploys/}"
|
2019-11-20 11:09:11 -05:00
|
|
|
dokku_log_verbose "No CHECKS file found. Simple container checks will be performed."
|
|
|
|
|
dokku_log_verbose "For more efficient zero downtime deployments, create a CHECKS file. See ${CHECKS_URL} for examples"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 02:40:59 -05:00
|
|
|
trigger-scheduler-docker-local-pre-deploy "$@"
|