fix periodic snapshot upgrade edge cases
This commit is contained in:
parent
fe8d4fcb14
commit
4ca08a12a4
@ -5,10 +5,16 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/scripts/common.sh"
|
||||
|
||||
REUSE_ENV_FROM=""
|
||||
UPDATE_PACKAGE_IMAGE=1
|
||||
|
||||
usage() {
|
||||
cat <<'USAGE'
|
||||
Usage: ./upgrade.sh [--reuse-env-from /path/to/.env]
|
||||
Usage: ./upgrade.sh [--reuse-env-from /path/to/.env] [--keep-reused-image]
|
||||
|
||||
By default, --reuse-env-from preserves user/runtime settings but refreshes image
|
||||
tags from this package's .env.example so the upgraded service actually runs the
|
||||
new packaged runtime and monitor images. Use --keep-reused-image only when you
|
||||
intentionally want to keep the previous image tags.
|
||||
USAGE
|
||||
}
|
||||
|
||||
@ -18,6 +24,10 @@ while [[ $# -gt 0 ]]; do
|
||||
REUSE_ENV_FROM="$2"
|
||||
shift 2
|
||||
;;
|
||||
--keep-reused-image)
|
||||
UPDATE_PACKAGE_IMAGE=0
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
@ -38,6 +48,34 @@ if [[ -n "$REUSE_ENV_FROM" ]]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
refresh_env_key_from_example() {
|
||||
local key="$1"
|
||||
local value
|
||||
[[ -f "$ENV_EXAMPLE" ]] || die "missing $ENV_EXAMPLE"
|
||||
value="$(awk -F= -v key="$key" '$1 == key {sub(/^[^=]*=/, ""); print; exit}' "$ENV_EXAMPLE")"
|
||||
[[ -n "$value" ]] || return 0
|
||||
if grep -q "^${key}=" "$ENV_FILE"; then
|
||||
tmp_env="$(mktemp)"
|
||||
awk -v key="$key" -v value="$value" '
|
||||
BEGIN { done=0 }
|
||||
$0 ~ "^" key "=" { print key "=" value; done=1; next }
|
||||
{ print }
|
||||
END { if (!done) print key "=" value }
|
||||
' "$ENV_FILE" > "$tmp_env"
|
||||
mv "$tmp_env" "$ENV_FILE"
|
||||
else
|
||||
printf '%s=%s\n' "$key" "$value" >> "$ENV_FILE"
|
||||
fi
|
||||
log "refreshed $key from packaged .env.example"
|
||||
}
|
||||
|
||||
if [[ "$UPDATE_PACKAGE_IMAGE" == "1" ]]; then
|
||||
load_env
|
||||
refresh_env_key_from_example "RPKI_IMAGE"
|
||||
refresh_env_key_from_example "PROMETHEUS_IMAGE"
|
||||
refresh_env_key_from_example "GRAFANA_IMAGE"
|
||||
fi
|
||||
|
||||
load_env
|
||||
create_data_dirs
|
||||
install_docker_if_missing
|
||||
|
||||
@ -497,7 +497,14 @@ import sys
|
||||
runs_root = pathlib.Path(sys.argv[1])
|
||||
delta_count = 0
|
||||
run_dirs = sorted(
|
||||
[path for path in runs_root.glob("run_[0-9][0-9][0-9][0-9]") if path.is_dir()],
|
||||
[
|
||||
path
|
||||
for path in runs_root.glob("run_*")
|
||||
if path.is_dir()
|
||||
and path.name.startswith("run_")
|
||||
and path.name[4:].isdigit()
|
||||
],
|
||||
key=lambda path: int(path.name[4:]),
|
||||
reverse=True,
|
||||
)
|
||||
for run_dir in run_dirs:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user