Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect Procfile when setting run command #35

Merged
merged 5 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion install
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ scheduler-kubernetes-install() {

local KUBEDOG_VENDOR_URL="${KUBEDOG_VENDOR_URL:-"https://dl.bintray.com"}"
local KUBEDOG_VERSION="${KUBEDOG_VERSION:-v0.3.4}"
local KUBEDOG_URL="${KUBEDOG_URL:-"${KUBEDOG_VENDOR_URL}/flant/kubedog/${KUBEDOG_VERSION}/kubedog-linux-amd64-${KUBEDOG_VERSION}"}"

# hardcode kubedog vendor for now
KUBEDOG_URL=https://github.com/dokku/dokku-scheduler-kubernetes/releases/download/0.17.6/kubedog-linux-amd64-v0.3.4
if [[ ! -f "${DOKKU_LIB_ROOT}/data/scheduler-kubernetes/kubedog-${KUBEDOG_VERSION}" ]]; then
dokku_log_info1_quiet "Installing kubedog@${KUBEDOG_VERSION}"
curl -sL "${KUBEDOG_VENDOR_URL}/flant/kubedog/${KUBEDOG_VERSION}/kubedog-linux-amd64-${KUBEDOG_VERSION}" -o "${DOKKU_LIB_ROOT}/data/scheduler-kubernetes/kubedog-${KUBEDOG_VERSION}"
curl -sL "$KUBEDOG_URL" -o "${DOKKU_LIB_ROOT}/data/scheduler-kubernetes/kubedog-${KUBEDOG_VERSION}"
cp "${DOKKU_LIB_ROOT}/data/scheduler-kubernetes/kubedog-${KUBEDOG_VERSION}" "${DOKKU_LIB_ROOT}/data/scheduler-kubernetes/kubedog"
chmod +x "${DOKKU_LIB_ROOT}/data/scheduler-kubernetes/kubedog"
fi
Expand Down
57 changes: 57 additions & 0 deletions internal-functions
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,63 @@ fn-scheduler-kubernetes-remove-pvc() {
"${DOKKU_LIB_ROOT}/data/scheduler-kubernetes/kubectl" "${KUBE_ARGS[@]}" delete pvc "$NAME"
}

fn-set-command-and-args() {
declare desc="set the command and args"
declare APP="$1" PROC_TYPE="$2" IMAGE_SOURCE_TYPE="$3" DEPLOYMENT_FILE="$4"

local TMP_FILE=$(mktemp "/tmp/${FUNCNAME[0]}.XXXX")
trap 'rm -rf "$TMP_FILE" > /dev/null' RETURN INT TERM EXIT

DOKKU_HEROKUISH=false
[[ "$IMAGE_SOURCE_TYPE" == "herokuish" ]] && DOKKU_HEROKUISH=true

local command_with_args="$(fn-scheduler-kubernetes-extract-start-cmd "$APP" "$PROC_TYPE" "$DOKKU_HEROKUISH" 5000)"
if [[ -z "$command_with_args" ]]; then
dokku_log_fail "No $PROC_TYPE command detected for app"
return
fi

COMMAND=""
ARGS=()
i=0
for word in ${command_with_args[@]}; do
[[ "$i" -eq 0 ]] && COMMAND="$word"
[[ "$i" -ne 0 ]] && ARGS+=("$word")
i=$((i + 1))
done

COMMAND="$COMMAND" jq -M ".spec.template.spec.containers[0].command = [env.COMMAND]" <"$DEPLOYMENT_FILE" >"$TMP_FILE"
mv "$TMP_FILE" "$DEPLOYMENT_FILE"
jq -M ".spec.template.spec.containers[0].args = []" <"$DEPLOYMENT_FILE" >"$TMP_FILE"
mv "$TMP_FILE" "$DEPLOYMENT_FILE"

for ARG in "${ARGS[@]}"; do
ARG="$ARG" jq -M ".spec.template.spec.containers[0].args += [env.ARG]" <"$DEPLOYMENT_FILE" >"$TMP_FILE"
mv "$TMP_FILE" "$DEPLOYMENT_FILE"
done
}


fn-scheduler-kubernetes-extract-start-cmd() {
declare APP="$1" PROC_TYPE="$2" DOKKU_HEROKUISH="$3" PORT="$4"
local DOKKU_DOCKERFILE_START_CMD DOKKU_PROCFILE_START_CMD START_CMD

local START_CMD
[[ "$DOKKU_HEROKUISH" == "true" ]] && START_CMD="/start $PROC_TYPE"
DOKKU_START_CMD=$(config_get "$APP" DOKKU_START_CMD || true)
[[ -n "$DOKKU_START_CMD" ]] && START_CMD="$DOKKU_START_CMD"

if [[ "$DOKKU_HEROKUISH" != "false" ]]; then
echo "$START_CMD"
return
fi

DOKKU_DOCKERFILE_START_CMD=$(config_get "$APP" DOKKU_DOCKERFILE_START_CMD || true)
DOKKU_PROCFILE_START_CMD=$(plugn trigger procfile-get-command "$APP" "$PROC_TYPE" "$PORT")
START_CMD=${DOKKU_DOCKERFILE_START_CMD:-$DOKKU_PROCFILE_START_CMD}
echo "$START_CMD"
}

fn-set-mount() {
declare desc="mount volumes on path"
declare APP="$1" DEPLOYMENT_FILE="$2"
Expand Down
8 changes: 8 additions & 0 deletions scheduler-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ scheduler-kubernetes-scheduler-deploy() {
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")"
Expand All @@ -65,6 +72,7 @@ scheduler-kubernetes-scheduler-deploy() {
fn-set-deployment-annotations "$APP" "$TMP_FILE"
fn-set-pod-annotations "$APP" "$TMP_FILE"
fn-set-mount "$APP" "$TMP_FILE"
fn-set-command-and-args "$APP" "$PROC_TYPE" "$IMAGE_SOURCE_TYPE" "$TMP_FILE"

plugn trigger pre-deploy-kubernetes-apply "$APP" "$PROC_TYPE" "$TMP_FILE" deployment

Expand Down
4 changes: 4 additions & 0 deletions subcommands/show-manifest
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ cmd-scheduler-kubernetes-show-manifest() {
fi
VALID_SERVICE_TYPES+=("web")

local IMAGE_SOURCE_TYPE="dockerfile"
is_image_herokuish_based "$IMAGE" "$APP" && IMAGE_SOURCE_TYPE="herokuish"

while read -r line || [[ -n "$line" ]]; do
[[ "$line" =~ ^#.* ]] && continue
line="$(strip_inline_comments "$line")"
Expand All @@ -58,6 +61,7 @@ cmd-scheduler-kubernetes-show-manifest() {
fn-set-deployment-annotations "$APP" "$TMP_FILE"
fn-set-pod-annotations "$APP" "$TMP_FILE"
fn-set-mount "$APP" "$TMP_FILE"
fn-set-command-and-args "$APP" "$PROC_TYPE" "$IMAGE_SOURCE_TYPE" "$TMP_FILE"

plugn trigger pre-deploy-kubernetes-apply "$APP" "$PROC_TYPE" "$TMP_FILE" deployment
if [[ "$MANIFEST_TYPE" == "deployment" ]]; then
Expand Down
6 changes: 0 additions & 6 deletions templates/deployment.json.sigil
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@
"spec": {
"containers": [
{
"args": [
"{{ $.PROCESS_TYPE }}"
],
"command": [
"/start"
],
"env": [],
"image": "{{ $.IMAGE }}",
"imagePullPolicy": "Always",
Expand Down