chore: enhance image reference resolution in updater script
- Added functionality to resolve image references with digests, improving the rollback process in the updater script. - Updated health check URLs in targets.json.example to use service names instead of localhost, ensuring proper connectivity in containerized environments.
This commit is contained in:
@@ -105,6 +105,14 @@ running_image_digest() {
|
||||
if [[ -z "$image_id" ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
local repo_digest
|
||||
repo_digest="$(docker image inspect "$image_id" --format '{{index .RepoDigests 0}}' 2>/dev/null || true)"
|
||||
if [[ -n "$repo_digest" && "$repo_digest" == *@* ]]; then
|
||||
printf '%s' "${repo_digest#*@}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
docker image inspect "$image_id" --format '{{.Id}}'
|
||||
}
|
||||
|
||||
@@ -151,7 +159,39 @@ image_with_digest() {
|
||||
local image="$1"
|
||||
local digest="$2"
|
||||
local base="${image%@*}"
|
||||
printf '%s@%s' "$base" "$digest"
|
||||
|
||||
if docker image inspect "$digest" >/dev/null 2>&1; then
|
||||
printf '%s' "$digest"
|
||||
return 0
|
||||
fi
|
||||
|
||||
local repo="$base"
|
||||
if [[ "$base" == *:* ]]; then
|
||||
repo="${base%:*}"
|
||||
fi
|
||||
|
||||
local ref="${repo}@${digest}"
|
||||
if docker image inspect "$ref" >/dev/null 2>&1; then
|
||||
printf '%s' "$ref"
|
||||
return 0
|
||||
fi
|
||||
|
||||
printf '%s' "$ref"
|
||||
}
|
||||
|
||||
resolve_image_ref() {
|
||||
local image="$1"
|
||||
local digest="$2"
|
||||
local ref
|
||||
ref="$(image_with_digest "$image" "$digest")"
|
||||
|
||||
if docker image inspect "$ref" >/dev/null 2>&1; then
|
||||
printf '%s' "$ref"
|
||||
return 0
|
||||
fi
|
||||
|
||||
docker pull "$ref" >/dev/null
|
||||
printf '%s' "$ref"
|
||||
}
|
||||
|
||||
build_run_args_from_snapshot() {
|
||||
@@ -303,7 +343,12 @@ restore_container() {
|
||||
|
||||
docker rm -f "$container_name" >/dev/null 2>&1 || true
|
||||
if [[ -n "$previous_digest" ]]; then
|
||||
run_container_from_snapshot "$container_name" "$snapshot_file" "$(image_with_digest "$image" "$previous_digest")" || {
|
||||
local rollback_image
|
||||
if ! rollback_image="$(resolve_image_ref "$image" "$previous_digest")"; then
|
||||
log error "target=${target_id} action=rollback_failed reason=image_unavailable digest=${previous_digest}"
|
||||
return 1
|
||||
fi
|
||||
run_container_from_snapshot "$container_name" "$snapshot_file" "$rollback_image" || {
|
||||
log error "target=${target_id} action=rollback_failed"
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"image": "git.shts.su/denozord/mikrotikmanager-backend:latest",
|
||||
"health": {
|
||||
"type": "http",
|
||||
"url": "http://127.0.0.1:8000/health",
|
||||
"url": "http://backend:8000/health",
|
||||
"expect_status": 200
|
||||
}
|
||||
},
|
||||
@@ -16,7 +16,7 @@
|
||||
"image": "git.shts.su/denozord/mikrotikmanager-frontend:latest",
|
||||
"health": {
|
||||
"type": "http",
|
||||
"url": "http://127.0.0.1:3000/",
|
||||
"url": "http://frontend:3000/",
|
||||
"expect_status": 200
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user