feat: allow specifying a single process type to restart

This changes restarts to drop the 'release' part that currently gets triggered, which also helps reduce the possibility that a new image layer will be added due to predeploy deploy triggers.

Note that the old method essentially halfway-rebuilt the app (which was what added the extra layer). This refactor removes that, which is a bc-break.

Additionally, scaling processes will result in deploying _only_ restarting the processes being scaled.

Closes #2184
This commit is contained in:
Jose Diaz-Gonzalez
2021-09-05 00:02:46 -04:00
parent 8f7f03a7d8
commit b48b79f5ca
13 changed files with 115 additions and 36 deletions

View File

@@ -226,20 +226,21 @@ func GetAppRunningContainerIDs(appName string, containerType string) ([]string,
return runningContainerIDs, nil
}
// GetRunningImageTag retrieves current image tag for a given app and returns empty string if no deployed containers are found
func GetRunningImageTag(appName string) (string, error) {
containerIDs, err := GetAppContainerIDs(appName, "")
// GetRunningImageTag retrieves current deployed image tag for a given app
func GetRunningImageTag(appName string, imageTag string) (string, error) {
b, err := PlugnTriggerOutput("deployed-app-image-tag", []string{appName}...)
if err != nil {
return "", err
return imageTag, err
}
newImageTag := strings.TrimSpace(string(b[:]))
if newImageTag != "" {
imageTag = newImageTag
}
if imageTag == "" {
imageTag = "latest"
}
for _, containerID := range containerIDs {
if image, err := DockerInspect(containerID, "{{ .Config.Image }}"); err == nil {
return strings.Split(image, ":")[1], nil
}
}
return "", errors.New("No image tag found")
return imageTag, nil
}
// DokkuApps returns a list of all local apps

6
plugins/common/deploy Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
cmd-deploy "$@"

View File

@@ -286,16 +286,14 @@ get_deploying_app_image_name() {
declare desc="return deploying image identifier for a given app, tag tuple. validate if tag is presented"
local APP="$1"
local IMAGE_TAG="$2"
IMAGE_REPO="$3"
local IMAGE_REPO="$3"
IMAGE_TAG="$(get_running_image_tag "$APP" "$IMAGE_TAG")"
local IMAGE_REMOTE_REPOSITORY=$(plugn trigger deployed-app-repository "$APP")
local NEW_IMAGE_TAG=$(plugn trigger deployed-app-image-tag "$APP")
local NEW_IMAGE_REPO=$(plugn trigger deployed-app-image-repo "$APP")
[[ -n "$NEW_IMAGE_REPO" ]] && IMAGE_REPO="$NEW_IMAGE_REPO"
[[ -n "$NEW_IMAGE_TAG" ]] && IMAGE_TAG="$NEW_IMAGE_TAG"
[[ -z "$IMAGE_REPO" ]] && IMAGE_REPO=$(get_app_image_repo "$APP")
[[ -z "$IMAGE_TAG" ]] && IMAGE_TAG="latest"
local IMAGE="${IMAGE_REMOTE_REPOSITORY}${IMAGE_REPO}:${IMAGE_TAG}"
verify_image "$IMAGE" || dokku_log_fail "App image ($IMAGE) not found"
@@ -329,12 +327,14 @@ get_app_scheduler() {
}
get_running_image_tag() {
declare desc="retrieve current image tag for a given app. returns empty string if no deployed containers are found"
local APP="$1"
declare desc="retrieves current deployed image tag for a given app"
local APP="$1" IMAGE_TAG="$2"
local CIDS=($(get_app_container_ids "$APP"))
local RUNNING_IMAGE_TAG=$("$DOCKER_BIN" container inspect --format '{{ .Config.Image }}' "${CIDS[0]}" 2>/dev/null | awk -F: '{ print $2 }' || echo '')
echo "$RUNNING_IMAGE_TAG"
local NEW_IMAGE_TAG=$(plugn trigger deployed-app-image-tag "$APP")
[[ -n "$NEW_IMAGE_TAG" ]] && IMAGE_TAG="$NEW_IMAGE_TAG"
[[ -z "$IMAGE_TAG" ]] && IMAGE_TAG="latest"
echo "$IMAGE_TAG"
}
is_image_cnb_based() {
@@ -638,12 +638,11 @@ dokku_release() {
cmd-deploy() {
declare desc="deploy phase"
declare APP="$1" IMAGE_TAG="$2"
source "$PLUGIN_AVAILABLE_PATH/config/functions"
declare APP="$1" IMAGE_TAG="$2" PROCESS_TYPE="$3"
verify_app_name "$APP"
local DOKKU_SCHEDULER=$(get_app_scheduler "$APP")
plugn trigger scheduler-deploy "$DOKKU_SCHEDULER" "$APP" "$IMAGE_TAG"
plugn trigger scheduler-deploy "$DOKKU_SCHEDULER" "$APP" "$IMAGE_TAG" "$PROCESS_TYPE"
}
release_and_deploy() {