feat: add ability to upgrade service image and image-version
This commit is contained in:
@@ -46,6 +46,7 @@ mysql:start <name> Start a previously stopped mysql service
|
||||
mysql:stop <name> Stop a running mysql service
|
||||
mysql:unexpose <name> Unexpose a previously exposed mysql service
|
||||
mysql:unlink <name> <app> Unlink the mysql service from the app
|
||||
mysql:upgrade <name> Upgrade service <service> to the specified version
|
||||
```
|
||||
|
||||
## usage
|
||||
|
||||
@@ -273,6 +273,18 @@ service_backup_unset_encryption() {
|
||||
rm -rf "$SERVICE_BACKUP_ENCRYPTION_ROOT"
|
||||
}
|
||||
|
||||
service_container_rm() {
|
||||
declare desc="Stops a service and removes the running container"
|
||||
declare SERVICE="$1"
|
||||
local SERVICE_NAME="$(get_service_name "$SERVICE")"
|
||||
|
||||
service_stop "$SERVICE"
|
||||
dokku_log_info2_quiet "Removing container"
|
||||
if ! docker rm "$SERVICE_NAME" > /dev/null 2>&1; then
|
||||
dokku_log_fail "Unable to stop container for service $SERVICE"
|
||||
fi
|
||||
}
|
||||
|
||||
service_enter() {
|
||||
declare desc="enters running app container of specified proc type"
|
||||
declare SERVICE="$1" && shift 1
|
||||
@@ -300,6 +312,17 @@ service_exposed_ports() {
|
||||
done
|
||||
}
|
||||
|
||||
service_image_exists() {
|
||||
declare desc="Checks if the current image exists"
|
||||
local IMAGE="$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION"
|
||||
|
||||
if [[ "$(docker images -q "$IMAGE" 2> /dev/null)" == "" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
service_info() {
|
||||
declare desc="Retrieves information about a given service"
|
||||
declare SERVICE="$1" INFO_FLAG="$2"
|
||||
|
||||
@@ -29,7 +29,7 @@ service_create() {
|
||||
|
||||
service_parse_args "${@:2}"
|
||||
|
||||
if ! docker images | grep -e "^$PLUGIN_IMAGE " | grep -q " $PLUGIN_IMAGE_VERSION " ; then
|
||||
if ! service_image_exists "$SERVICE"; then
|
||||
if [[ "$PLUGIN_DISABLE_PULL" == "true" ]]; then
|
||||
dokku_log_warn "${PLUGIN_DISABLE_PULL_VARIABLE} environment variable detected. Not running pull command." 1>&2
|
||||
dokku_log_warn " docker pull ${IMAGE}" 1>&2
|
||||
@@ -127,7 +127,6 @@ service_start() {
|
||||
|
||||
dokku_log_info2_quiet "Starting container"
|
||||
local PREVIOUS_ID=$(docker ps -f status=exited | grep -e "$SERVICE_NAME$" | awk '{print $1}') || true
|
||||
local IMAGE_EXISTS=$(docker images | grep -e "^$PLUGIN_IMAGE " | grep -q " $PLUGIN_IMAGE_VERSION " && true)
|
||||
local ROOTPASSWORD="$(cat "$SERVICE_ROOT/ROOTPASSWORD")"
|
||||
local PASSWORD="$(cat "$SERVICE_ROOT/PASSWORD")"
|
||||
|
||||
@@ -135,7 +134,7 @@ service_start() {
|
||||
docker start "$PREVIOUS_ID" > /dev/null
|
||||
service_port_unpause "$SERVICE"
|
||||
dokku_log_info2 "Container started"
|
||||
elif $IMAGE_EXISTS && [[ -n "$ROOTPASSWORD" ]] && [[ -n "$PASSWORD" ]]; then
|
||||
elif service_image_exists "$SERVICE" && [[ -n "$ROOTPASSWORD" ]] && [[ -n "$PASSWORD" ]]; then
|
||||
service_create_container "$SERVICE"
|
||||
else
|
||||
dokku_log_verbose_quiet "Neither container nor valid configuration exists for $SERVICE"
|
||||
|
||||
42
subcommands/upgrade
Executable file
42
subcommands/upgrade
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config"
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_BASE_PATH/common/functions"
|
||||
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
|
||||
|
||||
service-upgrade-cmd() {
|
||||
#E you can upgrade an existing service to a new image or image-version
|
||||
#E dokku $PLUGIN_COMMAND_PREFIX:upgrade lolipop
|
||||
#A service, service to run command against
|
||||
#F -c|--custom-env "USER=alpha;HOST=beta", semi-colon delimited environment variables to start the service with
|
||||
#F -i|--image IMAGE, the image name to start the service with
|
||||
#F -i|--image-version IMAGE_VERSION, the image version to start the service with
|
||||
declare desc="upgrade service <service> to the specified versions"
|
||||
local cmd="$PLUGIN_COMMAND_PREFIX:upgrade" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
|
||||
declare SERVICE="$1" CLONE_FLAGS_LIST="${@:2}"
|
||||
is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented"
|
||||
|
||||
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
|
||||
verify_service_name "$SERVICE"
|
||||
|
||||
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
|
||||
local ID="$(cat "$SERVICE_ROOT/ID")"
|
||||
is_container_status "$ID" "Running" || dokku_log_fail "Service ${SERVICE} container is not running"
|
||||
|
||||
PLUGIN_IMAGE=$(service_version "$SERVICE" | grep -o "^.*:" | sed -r "s/://g")
|
||||
PLUGIN_IMAGE_VERSION=$(service_version "$SERVICE" | grep -o ":.*$" | sed -r "s/://g")
|
||||
|
||||
service_parse_args "${@:2}"
|
||||
|
||||
if ! service_image_exists "$SERVICE"; then
|
||||
dokku_log_fail "Unable to proceed with upgrade, image ${PLUGIN_IMAGE}:${PLUGIN_IMAGE_VERSION} does not exist"
|
||||
fi
|
||||
|
||||
dokku_log_info2 "Stopping $SERVICE"
|
||||
service_container_rm "$NEW_SERVICE"
|
||||
dokku_log_info2 "Upgrading $SERVICE @ $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION"
|
||||
service_start "$NEW_SERVICE" "${@:2}"
|
||||
dokku_log_info2 "Done"
|
||||
}
|
||||
|
||||
service-upgrade-cmd "$@"
|
||||
Reference in New Issue
Block a user