allow tagging and deployment of tagged app images
This commit is contained in:
@@ -5,7 +5,9 @@ source "$PLUGIN_PATH/config/functions"
|
||||
|
||||
case "$1" in
|
||||
build)
|
||||
APP="$2"; IMAGE="dokku/$APP"; IMAGE_SOURCE_TYPE="$3"; TMP_WORK_DIR="$4"
|
||||
APP="$2"; IMAGE_SOURCE_TYPE="$3"; TMP_WORK_DIR="$4"
|
||||
verify_app_name "$APP"
|
||||
|
||||
CACHE_DIR="$DOKKU_ROOT/$APP/cache"
|
||||
|
||||
eval "$(config_export app $APP)"
|
||||
@@ -58,14 +60,16 @@ case "$1" in
|
||||
;;
|
||||
|
||||
release)
|
||||
APP="$2"; IMAGE="dokku/$APP"; IMAGE_SOURCE_TYPE="$3"
|
||||
APP="$2"; IMAGE_SOURCE_TYPE="$3"; TAG="$4"
|
||||
verify_app_name "$APP" "$TAG"
|
||||
|
||||
case "$IMAGE_SOURCE_TYPE" in
|
||||
herokuish)
|
||||
# *DEPRECATED* in v0.3.15: `pluginhook pre-release` will be removed in future releases
|
||||
pluginhook pre-release "$APP"
|
||||
pluginhook pre-release "$APP" "$TAG"
|
||||
# *DEPRECATED* in v0.3.22: `pluginhook pre-release-buildstep` will be removed in future releases
|
||||
pluginhook pre-release-buildstep "$APP"
|
||||
pluginhook pre-release-buildpack "$APP"
|
||||
pluginhook pre-release-buildstep "$APP" "$TAG"
|
||||
pluginhook pre-release-buildpack "$APP" "$TAG"
|
||||
if [[ -n $(config_export global) ]]; then
|
||||
id=$(config_export global | docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/00-global-env.sh")
|
||||
test "$(docker wait $id)" -eq 0
|
||||
@@ -77,15 +81,15 @@ case "$1" in
|
||||
docker commit $id $IMAGE > /dev/null
|
||||
fi
|
||||
# *DEPRECATED* in v0.3.15: `pluginhook post-release` will be removed in future releases
|
||||
pluginhook post-release "$APP"
|
||||
pluginhook post-release "$APP" "$TAG"
|
||||
# *DEPRECATED* in v0.3.22: `pluginhook post-release-buildstep` will be removed in future releases
|
||||
pluginhook post-release-buildstep "$APP"
|
||||
pluginhook post-release-buildpack "$APP"
|
||||
pluginhook post-release-buildstep "$APP" "$TAG"
|
||||
pluginhook post-release-buildpack "$APP" "$TAG"
|
||||
;;
|
||||
|
||||
dockerfile)
|
||||
pluginhook pre-release-dockerfile "$APP"
|
||||
pluginhook post-release-dockerfile "$APP"
|
||||
pluginhook pre-release-dockerfile "$APP" "$TAG"
|
||||
pluginhook post-release-dockerfile "$APP" "$TAG"
|
||||
;;
|
||||
|
||||
*)
|
||||
@@ -140,8 +144,7 @@ case "$1" in
|
||||
|
||||
logs)
|
||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||
verify_app_name "$2"
|
||||
APP="$2";
|
||||
APP="$2"; verify_app_name "$2"
|
||||
|
||||
if (is_deployed $APP); then
|
||||
CONTAINER_IDS=( $(get_app_container_ids $APP) )
|
||||
@@ -167,13 +170,13 @@ case "$1" in
|
||||
|
||||
run)
|
||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||
verify_app_name "$2"
|
||||
APP="$2"; IMAGE="dokku/$APP"
|
||||
APP="$2"; TAG=$(get_running_image_tag $APP)
|
||||
verify_app_name "$APP" "$TAG"
|
||||
|
||||
shift 2
|
||||
|
||||
DOCKER_ARGS=$(: | pluginhook docker-args $APP run)
|
||||
DOCKER_ARGS+=$(: | pluginhook docker-args-run $APP)
|
||||
DOCKER_ARGS=$(: | pluginhook docker-args $APP run $TAG)
|
||||
DOCKER_ARGS+=$(: | pluginhook docker-args-run $APP $TAG)
|
||||
[[ $DOKKU_RM_CONTAINER ]] && DOKKU_RUN_OPTS="--rm"
|
||||
has_tty && DOKKU_RUN_OPTS+=" -i -t"
|
||||
is_image_herokuish_based "$IMAGE" && EXEC_CMD="/exec"
|
||||
@@ -183,9 +186,7 @@ case "$1" in
|
||||
|
||||
url | urls)
|
||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||
verify_app_name "$2"
|
||||
APP="$2";
|
||||
|
||||
APP="$2"; verify_app_name "$2"
|
||||
eval "$(config_export app $APP)"
|
||||
|
||||
if [[ -s "$DOKKU_ROOT/$APP/URLS" ]]; then
|
||||
|
||||
@@ -19,11 +19,10 @@ case "$1" in
|
||||
|
||||
apps:destroy)
|
||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||
verify_app_name "$2"
|
||||
[[ "$2" == "tls" ]] && echo "Unable to destroy tls directory" && exit 1
|
||||
APP="$2"; IMAGE="dokku/$APP"
|
||||
|
||||
[[ "$3" == "force" ]] && DOKKU_APPS_FORCE_DELETE=1
|
||||
APP="$2"; verify_app_name "$APP"
|
||||
|
||||
if [[ -z "$DOKKU_APPS_FORCE_DELETE" ]]; then
|
||||
dokku_log_warn "WARNING: Potentially Destructive Action"
|
||||
dokku_log_warn "This command will destroy $APP (including all add-ons)."
|
||||
@@ -48,8 +47,6 @@ case "$1" in
|
||||
done
|
||||
fi
|
||||
|
||||
docker images | grep $IMAGE | awk '{print $3}' | xargs docker rmi &> /dev/null &
|
||||
|
||||
pluginhook post-delete $APP
|
||||
;;
|
||||
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
APP="$1"
|
||||
|
||||
[[ -n $1 ]] && rm -r "$DOKKU_ROOT/$1" > /dev/null
|
||||
[[ -n $APP ]] && rm -r "$DOKKU_ROOT/$APP" > /dev/null
|
||||
|
||||
# remove all application containers & images
|
||||
# shellcheck disable=SC2046
|
||||
docker rm -f $(docker ps -a --no-trunc | egrep "dokku/${APP}:" | awk '{ print $1 }' | xargs) &>/dev/null || true
|
||||
# shellcheck disable=SC2046
|
||||
docker rmi $(docker images -q $IMAGE | xargs) &>/dev/null || true
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$(dirname $0)/../common/functions"
|
||||
|
||||
APP="$1"; CACHE_DIR="$DOKKU_ROOT/$APP/cache"
|
||||
verify_app_name "$APP"
|
||||
|
||||
APP="$1"; IMAGE="dokku/$APP"; CACHE_DIR="$DOKKU_ROOT/$APP/cache"
|
||||
if [[ -d $CACHE_DIR ]]; then
|
||||
docker run --rm -v "$CACHE_DIR:/cache" "$IMAGE" find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} \; || true
|
||||
fi
|
||||
|
||||
@@ -3,7 +3,8 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_PATH/common/functions"
|
||||
source "$PLUGIN_PATH/config/functions"
|
||||
|
||||
APP="$1"; IMAGE="dokku/$APP"; BUILD_ENV=""
|
||||
APP="$1"; BUILD_ENV=""
|
||||
verify_app_name "$APP"
|
||||
|
||||
[[ -f "$DOKKU_ROOT/BUILD_ENV" ]] && cat "$DOKKU_ROOT/BUILD_ENV" >> "$DOKKU_ROOT/ENV" && {
|
||||
dokku_log_info2 "Using a global BUILD_ENV file is deprecated as of 0.3.26"
|
||||
|
||||
@@ -114,23 +114,38 @@ dokku_container_log_verbose_quiet() {
|
||||
}
|
||||
|
||||
verify_app_name() {
|
||||
local APP="$1"
|
||||
local APP="$1"; local TAG="$2"
|
||||
[[ ! -n "$APP" ]] && dokku_log_fail "(verify_app_name) APP must not be null"
|
||||
[[ ! -d "$DOKKU_ROOT/$APP" ]] && dokku_log_fail "App $APP does not exist"
|
||||
IMAGE="dokku/$APP"
|
||||
|
||||
if [[ -n "$TAG" ]]; then
|
||||
IMAGE="dokku/$APP:$TAG"
|
||||
else
|
||||
IMAGE="dokku/$APP"
|
||||
fi
|
||||
export IMAGE
|
||||
return 0
|
||||
}
|
||||
|
||||
verify_image() {
|
||||
local IMAGE="$1"
|
||||
DOKKU_APP_IMAGES=$(docker images -q $IMAGE)
|
||||
if [[ -n "$DOKKU_APP_IMAGES" ]]; then
|
||||
if (docker inspect "$IMAGE" &>/dev/null); then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
get_running_image_tag() {
|
||||
local APP="$1"
|
||||
[[ ! -n "$APP" ]] && dokku_log_fail "(get_running_image_tag) APP must not be null"
|
||||
verify_app_name "$APP"
|
||||
|
||||
CIDS=( $(get_container_ids $APP) )
|
||||
RUNNING_IMAGE_TAG=$(docker ps -a --no-trunc | egrep ${CIDS[0]} 2>/dev/null | awk '{ print $2 }' | awk -F: '{ print $2 }' || echo '')
|
||||
echo $RUNNING_IMAGE_TAG
|
||||
}
|
||||
|
||||
is_image_herokuish_based() {
|
||||
# circleci can't support --rm as they run lxc in lxc
|
||||
[[ ! -f "/home/ubuntu/.circlerc" ]] && local DOCKER_ARGS="--rm"
|
||||
@@ -267,3 +282,23 @@ is_app_running() {
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
release_and_deploy() {
|
||||
local APP="$1"; local TAG="$2"; verify_app_name "$APP" "$TAG"
|
||||
|
||||
if verify_image "$IMAGE"; then
|
||||
if is_image_herokuish_based "$IMAGE"; then
|
||||
IMAGE_SOURCE_TYPE="herokuish"
|
||||
else
|
||||
IMAGE_SOURCE_TYPE="dockerfile"
|
||||
fi
|
||||
|
||||
dokku_log_info1 "Releasing $APP ($IMAGE)..."
|
||||
dokku release "$APP" "$IMAGE_SOURCE_TYPE" "$TAG"
|
||||
dokku_log_info1 "Deploying $APP ($IMAGE)..."
|
||||
dokku deploy "$APP" "$TAG"
|
||||
dokku_log_info2 "Application deployed:"
|
||||
dokku urls $APP | sed "s/^/ /"
|
||||
echo
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_PATH/common/functions"
|
||||
source "$PLUGIN_PATH/config/functions"
|
||||
|
||||
STDIN=$(cat); APP="$1"; IMAGE="dokku/$APP"
|
||||
STDIN=$(cat); APP="$1"; TAG="$2"
|
||||
DOCKERFILE_ENV_FILE="$DOKKU_ROOT/$APP/DOCKERFILE_ENV_FILE"
|
||||
verify_app_name "$APP" "$TAG"
|
||||
|
||||
if ! is_image_herokuish_based "$IMAGE"; then
|
||||
> "$DOCKERFILE_ENV_FILE"
|
||||
|
||||
@@ -6,24 +6,23 @@ source "$(dirname $0)/functions"
|
||||
case "$1" in
|
||||
ps)
|
||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||
verify_app_name "$2"
|
||||
|
||||
APP="$2"; CONTAINER_IDS=$(get_app_container_ids $APP)
|
||||
APP="$2"; verify_app_name "$APP"; local DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids $APP)
|
||||
! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0
|
||||
|
||||
for CID in $CONTAINER_IDS; do
|
||||
for CID in $DOKKU_APP_RUNNING_CONTAINER_IDS; do
|
||||
has_tty && DOKKU_RUN_OPTS="-i -t"
|
||||
dokku_log_info1_quiet "running processes in container: $CID"
|
||||
docker exec $DOKKU_RUN_OPTS $CID /bin/sh -c "ps auxwww"
|
||||
done
|
||||
;;
|
||||
|
||||
ps:start)
|
||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||
verify_app_name "$2"; APP="$2"
|
||||
APP="$2"; TAG=$(get_running_image_tag "$APP"); verify_app_name "$APP" "$TAG"
|
||||
! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0
|
||||
|
||||
if ! (is_app_running $APP); then
|
||||
release_and_deploy $APP
|
||||
release_and_deploy "$APP" "$TAG"
|
||||
else
|
||||
echo "App $APP already running"
|
||||
fi
|
||||
@@ -31,12 +30,9 @@ case "$1" in
|
||||
|
||||
ps:stop)
|
||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||
verify_app_name "$2"
|
||||
|
||||
APP="$2"; CONTAINER_IDS=$(get_app_container_ids $APP)
|
||||
APP="$2"; verify_app_name "$APP"; local DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids $APP)
|
||||
! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0
|
||||
|
||||
DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids $APP)
|
||||
if [[ -n "$DOKKU_APP_RUNNING_CONTAINER_IDS" ]]; then
|
||||
echo "Stopping $APP ..."
|
||||
docker stop $DOKKU_APP_RUNNING_CONTAINER_IDS > /dev/null || true
|
||||
@@ -47,8 +43,7 @@ case "$1" in
|
||||
|
||||
ps:rebuild)
|
||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||
verify_app_name "$2"
|
||||
APP="$2"
|
||||
APP="$2"; verify_app_name "$APP"
|
||||
|
||||
pluginhook -p receive-app $APP
|
||||
;;
|
||||
@@ -65,12 +60,10 @@ case "$1" in
|
||||
|
||||
ps:restart)
|
||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||
verify_app_name "$2"
|
||||
|
||||
APP="$2"
|
||||
APP="$2"; TAG=$(get_running_image_tag $APP); verify_app_name "$APP" "$TAG"
|
||||
! (is_deployed $APP) && echo "App $APP has not been deployed" && exit 0
|
||||
|
||||
release_and_deploy $APP
|
||||
release_and_deploy "$APP" "$TAG"
|
||||
;;
|
||||
|
||||
ps:restartall)
|
||||
@@ -85,18 +78,18 @@ case "$1" in
|
||||
|
||||
ps:scale)
|
||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||
verify_app_name "$2"
|
||||
APP="$2"; TAG=$(get_running_image_tag "$APP"); verify_app_name "$APP" "$TAG"
|
||||
|
||||
APP="$2"; DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
|
||||
DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
|
||||
shift 2
|
||||
|
||||
generate_scale_file "$APP"
|
||||
generate_scale_file "$APP" "$TAG"
|
||||
if [[ -z "$@" ]];then
|
||||
dokku_log_info1 "Scaling for $APP"
|
||||
dokku_log_info2 "$(< $DOKKU_SCALE_FILE)"
|
||||
else
|
||||
set_scale "$APP" "$@"
|
||||
release_and_deploy "$APP"
|
||||
release_and_deploy "$APP" "$TAG"
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
@@ -2,27 +2,6 @@
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_PATH/common/functions"
|
||||
|
||||
release_and_deploy() {
|
||||
source "$PLUGIN_PATH/common/functions"
|
||||
local APP="$1"; local IMAGE="dokku/$APP"
|
||||
|
||||
if verify_image "$IMAGE"; then
|
||||
if is_image_herokuish_based "$IMAGE"; then
|
||||
IMAGE_SOURCE_TYPE="herokuish"
|
||||
else
|
||||
IMAGE_SOURCE_TYPE="dockerfile"
|
||||
fi
|
||||
|
||||
dokku_log_info1 "Releasing $APP ..."
|
||||
dokku release "$APP" "$IMAGE_SOURCE_TYPE"
|
||||
dokku_log_info1 "Deploying $APP ..."
|
||||
dokku deploy "$APP"
|
||||
dokku_log_info2 "Application deployed:"
|
||||
dokku urls $APP | sed "s/^/ /"
|
||||
echo
|
||||
fi
|
||||
}
|
||||
|
||||
print_dokku_scale_file(){
|
||||
local APP="$1"; local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
|
||||
while read line || [ -n "$line" ]
|
||||
@@ -32,7 +11,8 @@ print_dokku_scale_file(){
|
||||
}
|
||||
|
||||
generate_scale_file() {
|
||||
local APP="$1"; local IMAGE="dokku/$APP"; local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
|
||||
local APP="$1"; local TAG="$3"; local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
|
||||
verify_app_name "$APP" "$TAG"
|
||||
copy_from_image "$IMAGE" "/app/DOKKU_SCALE" "$DOKKU_ROOT/$APP" 2>/dev/null || true
|
||||
if [[ ! -f $DOKKU_SCALE_FILE ]]; then
|
||||
dokku_log_info1_quiet "DOKKU_SCALE file not found in app image. Defaulting to a single web process"
|
||||
@@ -62,4 +42,3 @@ set_scale() {
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
63
plugins/tag/commands
Executable file
63
plugins/tag/commands
Executable file
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$(dirname $0)/../common/functions"
|
||||
source "$(dirname $0)/functions"
|
||||
|
||||
case "$1" in
|
||||
tag:add)
|
||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||
APP="$2"; TAG="$3"
|
||||
verify_app_name "$APP"
|
||||
verify_image "$IMAGE" || dokku_log_fail "App image ($IMAGE) not found"
|
||||
|
||||
tag_image "$IMAGE:latest" "$IMAGE:$TAG"
|
||||
dokku_log_info2_quiet "Added $TAG tag to $IMAGE"
|
||||
;;
|
||||
|
||||
tag:deploy)
|
||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||
APP="$2"; TAG="$3"
|
||||
verify_app_name "$APP"
|
||||
verify_image "$IMAGE:$TAG" || dokku_log_fail "App image ($IMAGE:$TAG) not found"
|
||||
|
||||
release_and_deploy $APP $TAG
|
||||
;;
|
||||
|
||||
tag:list)
|
||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||
APP="$2"; verify_app_name "$APP"
|
||||
|
||||
dokku_log_info2_quiet "Image tags for $IMAGE"
|
||||
docker images "$IMAGE"
|
||||
;;
|
||||
|
||||
tag:rm)
|
||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||
APP="$2"; TAG="$3"
|
||||
verify_app_name "$2"
|
||||
|
||||
case "$TAG" in
|
||||
latest)
|
||||
dokku_log_fail "You can't remove internal dokku tag ($TAG) for $IMAGE"
|
||||
;;
|
||||
|
||||
*)
|
||||
docker rmi "$IMAGE:$TAG"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
help | tag:help)
|
||||
cat && cat<<EOF
|
||||
tag:add <app> <tag> Add tag to latest running app image
|
||||
tag:deploy <app> <tag> Deploy tagged app image
|
||||
tag:list <app> List all app image tags
|
||||
tag:rm <app> <tag> Remove app image tag
|
||||
EOF
|
||||
;;
|
||||
|
||||
*)
|
||||
exit $DOKKU_NOT_IMPLEMENTED_EXIT
|
||||
;;
|
||||
|
||||
esac
|
||||
7
plugins/tag/functions
Executable file
7
plugins/tag/functions
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$(dirname $0)/../common/functions"
|
||||
|
||||
tag_image() {
|
||||
docker tag -f "$1" "$2"
|
||||
}
|
||||
Reference in New Issue
Block a user