fix: pin the image and image version of a created service at creation time
This will help ensure that users upgrading to a new plugin version who stop/start databases will always get the same version. This is particularly important for datastores such as elasticsearch and postgres that have more involved upgraded processes.
This commit is contained in:
@@ -251,6 +251,14 @@ service_commit_config() {
|
|||||||
if [[ -n "$SERVICE_SHM_SIZE" ]]; then
|
if [[ -n "$SERVICE_SHM_SIZE" ]]; then
|
||||||
echo "$SERVICE_SHM_SIZE" >"$SERVICE_ROOT/SHM_SIZE"
|
echo "$SERVICE_SHM_SIZE" >"$SERVICE_ROOT/SHM_SIZE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$PLUGIN_IMAGE" ]]; then
|
||||||
|
echo "$PLUGIN_IMAGE" >"$SERVICE_ROOT/IMAGE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$PLUGIN_IMAGE_VERSION" ]]; then
|
||||||
|
echo "$PLUGIN_IMAGE_VERSION" >"$SERVICE_ROOT/IMAGE_VERSION"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
service_backup_auth() {
|
service_backup_auth() {
|
||||||
@@ -396,7 +404,13 @@ service_exposed_ports() {
|
|||||||
|
|
||||||
service_image_exists() {
|
service_image_exists() {
|
||||||
declare desc="check if the current image exists"
|
declare desc="check if the current image exists"
|
||||||
local IMAGE="$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION"
|
declare SERVICE="$1"
|
||||||
|
local plugin_image="$PLUGIN_IMAGE"
|
||||||
|
local plugin_image_version="$PLUGIN_IMAGE_VERSION"
|
||||||
|
|
||||||
|
[[ -f "$SERVICE_ROOT/IMAGE" ]] && plugin_image="$(cat "$SERVICE_ROOT/IMAGE")"
|
||||||
|
[[ -f "$SERVICE_ROOT/IMAGE_VERSION" ]] && plugin_image_version="$(cat "$SERVICE_ROOT/IMAGE_VERSION")"
|
||||||
|
local IMAGE="$plugin_image:$plugin_image_version"
|
||||||
|
|
||||||
if [[ "$(docker images -q "$IMAGE" 2>/dev/null)" == "" ]]; then
|
if [[ "$(docker images -q "$IMAGE" 2>/dev/null)" == "" ]]; then
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -83,6 +83,9 @@ service_create_container() {
|
|||||||
SHM_SIZE="--shm-size=${SERVICE_SHM_SIZE}"
|
SHM_SIZE="--shm-size=${SERVICE_SHM_SIZE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
[[ -f "$SERVICE_ROOT/IMAGE" ]] && PLUGIN_IMAGE="$(cat "$SERVICE_ROOT/IMAGE")"
|
||||||
|
[[ -f "$SERVICE_ROOT/IMAGE_VERSION" ]] && PLUGIN_IMAGE_VERSION="$(cat "$SERVICE_ROOT/IMAGE_VERSION")"
|
||||||
|
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
ID=$(docker run --name "$SERVICE_NAME" $MEMORY_LIMIT $SHM_SIZE -v "$SERVICE_HOST_ROOT/data:/var/lib/postgresql/data" -e "POSTGRES_PASSWORD=$PASSWORD" --env-file="$SERVICE_ROOT/ENV" -d --restart always --label dokku=service --label dokku.service=postgres "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" $CONFIG_OPTIONS)
|
ID=$(docker run --name "$SERVICE_NAME" $MEMORY_LIMIT $SHM_SIZE -v "$SERVICE_HOST_ROOT/data:/var/lib/postgresql/data" -e "POSTGRES_PASSWORD=$PASSWORD" --env-file="$SERVICE_ROOT/ENV" -d --restart always --label dokku=service --label dokku.service=postgres "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" $CONFIG_OPTIONS)
|
||||||
echo "$ID" >"$SERVICE_ROOT/ID"
|
echo "$ID" >"$SERVICE_ROOT/ID"
|
||||||
@@ -160,6 +163,8 @@ service_start() {
|
|||||||
service_create_container "$SERVICE"
|
service_create_container "$SERVICE"
|
||||||
else
|
else
|
||||||
if ! service_image_exists "$SERVICE"; then
|
if ! service_image_exists "$SERVICE"; then
|
||||||
|
[[ -f "$SERVICE_ROOT/IMAGE" ]] && PLUGIN_IMAGE="$(cat "$SERVICE_ROOT/IMAGE")"
|
||||||
|
[[ -f "$SERVICE_ROOT/IMAGE_VERSION" ]] && PLUGIN_IMAGE_VERSION="$(cat "$SERVICE_ROOT/IMAGE_VERSION")"
|
||||||
dokku_log_verbose_quiet "Missing image $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION for $SERVICE"
|
dokku_log_verbose_quiet "Missing image $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION for $SERVICE"
|
||||||
else
|
else
|
||||||
dokku_log_verbose_quiet "Neither container nor valid configuration exists for $SERVICE"
|
dokku_log_verbose_quiet "Neither container nor valid configuration exists for $SERVICE"
|
||||||
|
|||||||
10
install
10
install
@@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config"
|
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config"
|
||||||
|
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common-functions"
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
[[ $DOKKU_TRACE ]] && set -x
|
[[ $DOKKU_TRACE ]] && set -x
|
||||||
|
|
||||||
@@ -46,6 +47,15 @@ EOL
|
|||||||
local SERVICES=$(ls "$PLUGIN_DATA_ROOT" 2>/dev/null)
|
local SERVICES=$(ls "$PLUGIN_DATA_ROOT" 2>/dev/null)
|
||||||
for SERVICE in $SERVICES; do
|
for SERVICE in $SERVICES; do
|
||||||
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
|
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
|
||||||
|
|
||||||
|
if [[ ! -f "$SERVICE_ROOT/IMAGE" ]] || [[ ! -f "$SERVICE_ROOT/IMAGE_VERSION" ]]; then
|
||||||
|
local image="$(service_version "$SERVICE")"
|
||||||
|
if [[ "$image" == *":"* ]]; then
|
||||||
|
echo "${image%:*}" > "$SERVICE_ROOT/IMAGE"
|
||||||
|
echo "${image##*:}" > "$SERVICE_ROOT/IMAGE_VERSION"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -f "$SERVICE_ROOT/${PLUGIN_VARIABLE}_CONFIG_OPTIONS" ]]; then
|
if [[ -f "$SERVICE_ROOT/${PLUGIN_VARIABLE}_CONFIG_OPTIONS" ]]; then
|
||||||
mv "$SERVICE_ROOT/${PLUGIN_VARIABLE}_CONFIG_OPTIONS" "$SERVICE_ROOT/CONFIG_OPTIONS"
|
mv "$SERVICE_ROOT/${PLUGIN_VARIABLE}_CONFIG_OPTIONS" "$SERVICE_ROOT/CONFIG_OPTIONS"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user