Skip to content

Commit ce3aa4b

Browse files
committed
remove calls to dokku binary for build/receive/release
1 parent fcefd4a commit ce3aa4b

File tree

10 files changed

+307
-319
lines changed

10 files changed

+307
-319
lines changed

docs/development/plugin-triggers.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ esac
164164
### `docker-args-build`
165165

166166
- Description:
167-
- Invoked by: `dokku build`
167+
- Invoked by: `dokku_build`
168168
- Arguments: `$APP $IMAGE_SOURCE_TYPE`
169169
- Example:
170170

@@ -300,7 +300,7 @@ nginx -t
300300
### `post-build-buildpack`
301301

302302
- Description: Allows you to run commands after the build image is create for a given app. Only applies to applications using buildpacks.
303-
- Invoked by: `dokku build`
303+
- Invoked by: `dokku_build`
304304
- Arguments: `$APP`
305305
- Example:
306306

@@ -315,7 +315,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
315315
### `post-build-dockerfile`
316316

317317
- Description: Allows you to run commands after the build image is create for a given app. Only applies to applications using a dockerfile.
318-
- Invoked by: `dokku build`
318+
- Invoked by: `dokku_build`
319319
- Arguments: `$APP`
320320
- Example:
321321

@@ -423,7 +423,7 @@ haproxy-build-config "$APP"
423423
### `post-release-buildpack`
424424

425425
- Description: Allows you to run commands after environment variables are set for the release step of the deploy. Only applies to applications using buildpacks.
426-
- Invoked by: `dokku release`
426+
- Invoked by: `dokku_release`
427427
- Arguments: `$APP $IMAGE_TAG`
428428
- Example:
429429

@@ -450,7 +450,7 @@ docker commit $ID $IMAGE > /dev/null
450450
### `post-release-dockerfile`
451451

452452
- Description: Allows you to run commands after environment variables are set for the release step of the deploy. Only applies to applications using a dockerfile.
453-
- Invoked by: `dokku release`
453+
- Invoked by: `dokku_release`
454454
- Arguments: `$APP $IMAGE_TAG`
455455
- Example:
456456

@@ -486,7 +486,7 @@ dokku config:set --no-restart $APP MANUALLY_STOPPED=1
486486
### `pre-build-buildpack`
487487

488488
- Description: Allows you to run commands before the build image is created for a given app. For instance, this can be useful to add env vars to your container. Only applies to applications using buildpacks.
489-
- Invoked by: `dokku build`
489+
- Invoked by: `dokku_build`
490490
- Arguments: `$APP`
491491
- Example:
492492

@@ -501,7 +501,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
501501
### `pre-build-dockerfile`
502502

503503
- Description: Allows you to run commands before the build image is created for a given app. For instance, this can be useful to add env vars to your container. Only applies to applications using a dockerfile.
504-
- Invoked by: `dokku build`
504+
- Invoked by: `dokku_build`
505505
- Arguments: `$APP`
506506
- Example:
507507

@@ -580,7 +580,7 @@ echo "$APP" > "$TMP_WORK_DIR/dokku-is-awesome"
580580
### `pre-release-buildpack`
581581

582582
- Description: Allows you to run commands before environment variables are set for the release step of the deploy. Only applies to applications using buildpacks.
583-
- Invoked by: `dokku release`
583+
- Invoked by: `dokku_release`
584584
- Arguments: `$APP $IMAGE_TAG`
585585
- Example:
586586

@@ -607,7 +607,7 @@ docker commit $ID $IMAGE > /dev/null
607607
### `pre-release-dockerfile`
608608

609609
- Description: Allows you to run commands before environment variables are set for the release step of the deploy. Only applies to applications using a dockerfile.
610-
- Invoked by: `dokku release`
610+
- Invoked by: `dokku_release`
611611
- Arguments: `$APP $IMAGE_TAG`
612612
- Example:
613613

dokku

+2-5
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,10 @@ execute_dokku_cmd() {
100100
nginx|nginx:*)
101101
local PLUGIN_NAME=${PLUGIN_NAME/nginx/nginx-vhosts}
102102
;;
103-
receive|deploy|build|release)
103+
deploy|delete|ls|run|cleanup)
104104
local PLUGIN_NAME="00_dokku-standard"
105105
;;
106-
trace|delete|ls|run|cleanup)
107-
local PLUGIN_NAME="00_dokku-standard"
108-
;;
109-
url|urls|report|version)
106+
trace|url|urls|report|version)
110107
local PLUGIN_NAME="00_dokku-standard"
111108
;;
112109
esac

plugins/00_dokku-standard/subcommands/build

-65
This file was deleted.
+1-170
Original file line numberDiff line numberDiff line change
@@ -1,175 +1,6 @@
11
#!/usr/bin/env bash
22
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
33
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
4-
source "$PLUGIN_AVAILABLE_PATH/checks/functions"
5-
source "$PLUGIN_AVAILABLE_PATH/config/functions"
6-
source "$PLUGIN_CORE_AVAILABLE_PATH/proxy/functions"
7-
8-
dokku_deploy_cmd() {
9-
declare desc="deploy phase"
10-
local cmd="deploy"
11-
[[ -z $2 ]] && dokku_log_fail "Please specify an app to deploy"
12-
local APP="$2"; local IMAGE_TAG="$3"; local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG")
13-
verify_app_name "$APP"
14-
plugn trigger pre-deploy "$APP" "$IMAGE_TAG"
15-
16-
is_image_herokuish_based "$IMAGE" && local DOKKU_HEROKUISH=true
17-
local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
18-
local oldids=$(get_app_container_ids "$APP")
19-
20-
local DOKKU_DEFAULT_DOCKER_ARGS=$(: | plugn trigger docker-args-deploy "$APP" "$IMAGE_TAG")
21-
local DOKKU_IS_APP_PROXY_ENABLED="$(is_app_proxy_enabled "$APP")"
22-
local DOKKU_DOCKER_STOP_TIMEOUT="$(config_get "$APP" DOKKU_DOCKER_STOP_TIMEOUT || true)"
23-
[[ $DOKKU_DOCKER_STOP_TIMEOUT ]] && DOCKER_STOP_TIME_ARG="--time=${DOKKU_DOCKER_STOP_TIMEOUT}"
24-
25-
local line; local PROC_TYPE; local PROC_COUNT; local CONTAINER_INDEX
26-
while read -r line || [[ -n "$line" ]]; do
27-
[[ "$line" =~ ^#.* ]] && continue
28-
line="$(strip_inline_comments "$line")"
29-
PROC_TYPE=${line%%=*}
30-
PROC_COUNT=${line#*=}
31-
CONTAINER_INDEX=1
32-
33-
if [[ "$(is_app_proctype_checks_disabled "$APP" "$PROC_TYPE")" == "true" ]]; then
34-
dokku_log_info1 "zero downtime is disabled for app ($APP.$PROC_TYPE). stopping currently running containers"
35-
local cid proctype_oldids="$(get_app_container_ids "$APP" "$PROC_TYPE")"
36-
for cid in $proctype_oldids; do
37-
dokku_log_info2 "stopping $APP.$PROC_TYPE ($cid)"
38-
# shellcheck disable=SC2086
39-
docker stop $DOCKER_STOP_TIME_ARG "$cid" &> /dev/null
40-
done
41-
fi
42-
43-
while [[ $CONTAINER_INDEX -le $PROC_COUNT ]]; do
44-
local id=""; local port=""; local ipaddr=""
45-
local DOKKU_CONTAINER_ID_FILE="$DOKKU_ROOT/$APP/CONTAINER.$PROC_TYPE.$CONTAINER_INDEX"
46-
local DOKKU_IP_FILE="$DOKKU_ROOT/$APP/IP.$PROC_TYPE.$CONTAINER_INDEX"
47-
local DOKKU_PORT_FILE="$DOKKU_ROOT/$APP/PORT.$PROC_TYPE.$CONTAINER_INDEX"
48-
49-
# start the app
50-
local DOCKER_ARGS="$DOKKU_DEFAULT_DOCKER_ARGS"
51-
local DOCKER_ARGS+=" -e DYNO='$PROC_TYPE.$CONTAINER_INDEX' "
52-
[[ "$DOKKU_TRACE" ]] && local DOCKER_ARGS+=" -e TRACE=true "
53-
54-
[[ -n "$DOKKU_HEROKUISH" ]] && local START_CMD="/start $PROC_TYPE"
55-
56-
if [[ -z "$DOKKU_HEROKUISH" ]]; then
57-
local DOKKU_DOCKERFILE_PORTS=($(config_get "$APP" DOKKU_DOCKERFILE_PORTS || true))
58-
local DOKKU_DOCKERFILE_START_CMD=$(config_get "$APP" DOKKU_DOCKERFILE_START_CMD || true)
59-
local DOKKU_PROCFILE_START_CMD=$(get_cmd_from_procfile "$APP" "$PROC_TYPE")
60-
local START_CMD=${DOKKU_DOCKERFILE_START_CMD:-$DOKKU_PROCFILE_START_CMD}
61-
fi
62-
63-
if [[ "$PROC_TYPE" == "web" ]]; then
64-
if [[ -z "${DOKKU_DOCKERFILE_PORTS[*]}" ]]; then
65-
local port=5000
66-
local DOKKU_DOCKER_PORT_ARGS+="-p $port"
67-
else
68-
local p
69-
for p in ${DOKKU_DOCKERFILE_PORTS[*]};do
70-
if [[ ! "$p" =~ .*udp.* ]]; then
71-
# set port to first non-udp port
72-
local p=${p//\/tcp}
73-
local port=${port:="$p"}
74-
fi
75-
local DOKKU_DOCKER_PORT_ARGS+=" -p $p "
76-
done
77-
fi
78-
if [[ "$DOKKU_IS_APP_PROXY_ENABLED" == "true" ]]; then
79-
# shellcheck disable=SC2086
80-
local id=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d -e PORT=$port $DOCKER_ARGS $IMAGE $START_CMD)
81-
local ipaddr=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$id")
82-
# Docker < 1.9 compatibility
83-
if [[ -z $ipaddr ]]; then
84-
local ipaddr=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$id")
85-
fi
86-
else
87-
# shellcheck disable=SC2086
88-
local id=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d $DOKKU_DOCKER_PORT_ARGS -e PORT=$port $DOCKER_ARGS $IMAGE $START_CMD)
89-
local port=$(docker port "$id" "$port" | sed 's/[0-9.]*://')
90-
local ipaddr=127.0.0.1
91-
fi
92-
else
93-
# shellcheck disable=SC2086
94-
local id=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d $DOCKER_ARGS $IMAGE $START_CMD)
95-
fi
96-
97-
kill_new() {
98-
declare desc="wrapper function to kill newly started app container"
99-
local id="$1"
100-
docker inspect "$id" &> /dev/null && docker stop "$id" > /dev/null && docker kill "$id" &> /dev/null
101-
trap - INT TERM EXIT
102-
kill -9 $$
103-
}
104-
105-
# run checks first, then post-deploy hooks, which switches proxy traffic
106-
trap 'kill_new $id' INT TERM EXIT
107-
if [[ "$(is_app_proctype_checks_disabled "$APP" "$PROC_TYPE")" == "false" ]]; then
108-
dokku_log_info1 "Attempting pre-flight checks"
109-
plugn trigger check-deploy "$APP" "$id" "$PROC_TYPE" "$port" "$ipaddr"
110-
fi
111-
trap - INT TERM EXIT
112-
113-
# now using the new container
114-
[[ -n "$id" ]] && echo "$id" > "$DOKKU_CONTAINER_ID_FILE"
115-
[[ -n "$ipaddr" ]] && echo "$ipaddr" > "$DOKKU_IP_FILE"
116-
[[ -n "$port" ]] && echo "$port" > "$DOKKU_PORT_FILE"
117-
118-
# cleanup pre-migration files
119-
rm -f "$DOKKU_ROOT/$APP/CONTAINER" "$DOKKU_ROOT/$APP/IP" "$DOKKU_ROOT/$APP/PORT"
120-
121-
local CONTAINER_INDEX=$(( CONTAINER_INDEX + 1 ))
122-
done
123-
# cleanup when we scale down
124-
if [[ "$PROC_COUNT" == 0 ]]; then
125-
local CONTAINER_IDX_OFFSET=0
126-
else
127-
local CONTAINER_IDX_OFFSET=$((PROC_COUNT + 1))
128-
fi
129-
local container_state_filetype
130-
for container_state_filetype in CONTAINER IP PORT; do
131-
cd "$DOKKU_ROOT/$APP"
132-
find . -maxdepth 1 -name "$container_state_filetype.$PROC_TYPE.*" -printf "%f\n" | sort -t . -k 3 -n | tail -n +$CONTAINER_IDX_OFFSET | xargs rm -f
133-
done
134-
done < "$DOKKU_SCALE_FILE"
135-
136-
dokku_log_info1 "Running post-deploy"
137-
plugn trigger post-deploy "$APP" "$port" "$ipaddr" "$IMAGE_TAG"
138-
139-
# kill the old container
140-
if [[ -n "$oldids" ]]; then
141-
142-
if [[ -z "$DOKKU_WAIT_TO_RETIRE" ]]; then
143-
local DOKKU_APP_DOKKU_WAIT_TO_RETIRE=$(config_get "$APP" DOKKU_WAIT_TO_RETIRE || true)
144-
local DOKKU_GLOBAL_DOKKU_WAIT_TO_RETIRE=$(config_get --global DOKKU_WAIT_TO_RETIRE || true)
145-
local DOKKU_WAIT_TO_RETIRE=${DOKKU_APP_DOKKU_WAIT_TO_RETIRE:="$DOKKU_GLOBAL_DOKKU_WAIT_TO_RETIRE"}
146-
fi
147-
148-
# Let the old container finish processing requests, before terminating it
149-
local WAIT="${DOKKU_WAIT_TO_RETIRE:-60}"
150-
dokku_log_info1 "Shutting down old containers in $WAIT seconds"
151-
local oldid
152-
for oldid in $oldids; do
153-
dokku_log_info2 "$oldid"
154-
done
155-
(
156-
exec >/dev/null 2>/dev/null </dev/null
157-
trap '' INT HUP
158-
sleep "$WAIT"
159-
for oldid in $oldids; do
160-
# Attempt to stop, if that fails, then force a kill as docker seems
161-
# to not send SIGKILL as the docs would indicate. If that fails, move
162-
# on to the next.
163-
# shellcheck disable=SC2086
164-
docker stop $DOCKER_STOP_TIME_ARG "$oldid" \
165-
|| docker kill "$oldid" \
166-
|| plugn trigger retire-container-failed "$APP" # plugin trigger for event logging
167-
done
168-
) & disown -a
169-
# Use trap since disown/nohup don't seem to keep child alive
170-
# Give child process just enough time to set the traps
171-
sleep 0.1
172-
fi
173-
}
1744

5+
shift 1
1756
dokku_deploy_cmd "$@"

plugins/00_dokku-standard/subcommands/receive

-22
This file was deleted.

0 commit comments

Comments
 (0)