-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
scheduler-deploy
executable file
·98 lines (79 loc) · 4.24 KB
/
scheduler-deploy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
source "$PLUGIN_AVAILABLE_PATH/scheduler-kubernetes/internal-functions"
scheduler-kubernetes-scheduler-deploy() {
declare desc="deploys an image tag for a given application"
declare trigger="scheduler-kubernetes scheduler-deploy"
declare DOKKU_SCHEDULER="$1" APP="$2" IMAGE_TAG="$3"
local DEPLOYMENT_TEMPLATE="$PLUGIN_AVAILABLE_PATH/scheduler-kubernetes/templates/deployment.json.sigil"
local SERVICE_TEMPLATE="$PLUGIN_AVAILABLE_PATH/scheduler-kubernetes/templates/service.json.sigil"
local KUBE_ARGS NAMESPACE
if [[ "$DOKKU_SCHEDULER" != "kubernetes" ]]; then
return
fi
local line PROC_TYPE PROC_COUNT CONTAINER_INDEX
local DEPLOYMENT_ID="$(date +%s)"
local TMP_FILE=$(mktemp "/tmp/${FUNCNAME[0]}.XXXX")
trap 'rm -rf "$TMP_FILE" > /dev/null' RETURN INT TERM EXIT
dokku_log_info2 "Deploying via kubernetes"
IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG")
fn-set-pod-disruption-constraints "$APP"
export KUBECONFIG="${DOKKU_ROOT}/.kube/config"
export KUBEDOG_KUBE_CONFIG="${DOKKU_ROOT}/.kube/config"
KUBE_ARGS=()
NAMESPACE="$(fn-plugin-property-get "scheduler-kubernetes" "$APP" "namespace" "default")"
KUBE_ARGS+=("--namespace=$NAMESPACE")
fn-scheduler-kubernetes-ensure-namespace "$NAMESPACE" >/dev/null
local IMAGE_PULL_SECRETS="$(fn-plugin-property-get "scheduler-kubernetes" "$APP" "imagePullSecrets" "")"
local SERVICE_PROCESS_TYPES=$(fn-plugin-property-get "scheduler-kubernetes" "$APP" "service-process-types" "")
local VALID_SERVICE_TYPES
if [[ -n "$SERVICE_PROCESS_TYPES" ]]; then
IFS=',' read -ra VALID_SERVICE_TYPES <<<"$SERVICE_PROCESS_TYPES"
fi
VALID_SERVICE_TYPES+=("web")
local IMAGE_SOURCE_TYPE="dockerfile"
is_image_cnb_based "$IMAGE" && DOKKU_CNB=true
is_image_herokuish_based "$IMAGE" "$APP" && DOKKU_HEROKUISH=true
local IMAGE_SOURCE_TYPE="dockerfile"
[[ "$DOKKU_HEROKUISH" == "true" ]] && IMAGE_SOURCE_TYPE="herokuish"
[[ "$DOKKU_CNB" == "true" ]] && IMAGE_SOURCE_TYPE="pack"
while read -r line || [[ -n "$line" ]]; do
[[ "$line" =~ ^#.* ]] && continue
line="$(strip_inline_comments "$line")"
PROC_TYPE=${line%%=*}
PROC_COUNT=${line#*=}
dokku_log_info1 "Deploying ${PROC_TYPE} to ${PROC_COUNT}"
local SIGIL_PARAMS=(APP="$APP" IMAGE="$IMAGE" PROCESS_COUNT="$PROC_COUNT" PROCESS_TYPE="$PROC_TYPE" PORT="5000")
sigil -f "$DEPLOYMENT_TEMPLATE" "${SIGIL_PARAMS[@]}" | cat -s >"$TMP_FILE"
[[ "$PROC_TYPE" != "web" ]] && fn-strip-ports "$TMP_FILE"
fn-set-env-vars "$APP" "$TMP_FILE"
fn-set-ports "$APP" "$TMP_FILE"
fn-set-resource-constraints "$APP" "$PROC_TYPE" "$TMP_FILE"
fn-set-image-pull-secrets "$IMAGE_PULL_SECRETS" "$TMP_FILE"
fn-set-healthchecks "$APP" "$PROC_TYPE" "$TMP_FILE"
fn-set-deployment-annotations "$APP" "$TMP_FILE"
fn-set-pod-annotations "$APP" "$TMP_FILE"
fn-set-mount "$APP" "$TMP_FILE"
if [[ "$IMAGE_SOURCE_TYPE" != "pack" ]]; then
fn-set-command-and-args "$APP" "$PROC_TYPE" "$IMAGE_SOURCE_TYPE" "$TMP_FILE"
fi
plugn trigger pre-deploy-kubernetes-apply "$APP" "$PROC_TYPE" "$TMP_FILE" deployment
"${DOKKU_LIB_ROOT}/data/scheduler-kubernetes/kubectl" "${KUBE_ARGS[@]}" apply -f "$TMP_FILE" | sed "s/^/ /"
"${DOKKU_LIB_ROOT}/data/scheduler-kubernetes/kubedog" "${KUBE_ARGS[@]}" --timeout=600 rollout track deployment "${APP}-${PROC_TYPE}"
if fn-in-array "$PROC_TYPE" "${VALID_SERVICE_TYPES[@]}"; then
sigil -f "$SERVICE_TEMPLATE" "${SIGIL_PARAMS[@]}" | cat -s >"$TMP_FILE"
fn-set-service-annotations "$APP" "$TMP_FILE"
plugn trigger pre-deploy-kubernetes-apply "$APP" "$PROC_TYPE" "$TMP_FILE" service
"${DOKKU_LIB_ROOT}/data/scheduler-kubernetes/kubectl" "${KUBE_ARGS[@]}" apply -f "$TMP_FILE" | sed "s/^/ /"
fi
plugn trigger post-deploy-kubernetes-apply "$APP" "$PROC_TYPE" "$TMP_FILE" deployment
done < <(plugn trigger ps-current-scale "$APP")
dokku_log_info2 "Deploy complete"
dokku_log_info1 "Running post-deploy"
plugn trigger core-post-deploy "$APP" "" "" "$IMAGE_TAG"
plugn trigger post-deploy "$APP" "" "" "$IMAGE_TAG"
}
scheduler-kubernetes-scheduler-deploy "$@"