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
|
||||
echo "$SERVICE_SHM_SIZE" >"$SERVICE_ROOT/SHM_SIZE"
|
||||
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() {
|
||||
@@ -396,7 +404,13 @@ service_exposed_ports() {
|
||||
|
||||
service_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
|
||||
return 1
|
||||
|
||||
@@ -91,6 +91,9 @@ service_create_container() {
|
||||
SHM_SIZE="--shm-size=${SERVICE_SHM_SIZE}"
|
||||
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
|
||||
ID=$(docker run --name "$SERVICE_NAME" $MEMORY_LIMIT $SHM_SIZE -v "$SERVICE_HOST_ROOT/data:/data/db" --env-file="$SERVICE_ROOT/ENV" --env "MONGO_INITDB_DATABASE=$DATABASE_NAME" -d --restart always --label dokku=service --label dokku.service=mongo "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" mongod $CONFIG_OPTIONS)
|
||||
echo "$ID" >"$SERVICE_ROOT/ID"
|
||||
@@ -160,6 +163,8 @@ service_start() {
|
||||
service_create_container "$SERVICE"
|
||||
else
|
||||
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"
|
||||
else
|
||||
dokku_log_verbose_quiet "Neither container nor valid configuration exists for $SERVICE"
|
||||
|
||||
10
install
10
install
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config"
|
||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common-functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
@@ -46,6 +47,15 @@ EOL
|
||||
local SERVICES=$(ls "$PLUGIN_DATA_ROOT" 2>/dev/null)
|
||||
for SERVICE in $SERVICES; do
|
||||
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
|
||||
mv "$SERVICE_ROOT/${PLUGIN_VARIABLE}_CONFIG_OPTIONS" "$SERVICE_ROOT/CONFIG_OPTIONS"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user