65 lines
1.5 KiB
Bash
Executable File
65 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
# shellcheck source=./lib.sh
|
|
source "$SCRIPT_DIR/lib.sh"
|
|
|
|
ENV_FILE="$SCRIPT_DIR/stack.env"
|
|
AUTO_YES=false
|
|
PRUNE_IMAGES=false
|
|
|
|
usage() {
|
|
cat <<USAGE
|
|
Usage: $(basename "$0") [options]
|
|
|
|
Upgrade stack images and recreate containers with current compose config.
|
|
|
|
Options:
|
|
--env-file=PATH Env file path (default: setup/pi-monitoring/stack.env)
|
|
--prune Prune dangling Docker images after upgrade
|
|
--yes, -y Skip confirmation prompt
|
|
--help, -h Show help
|
|
USAGE
|
|
}
|
|
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--env-file=*) ENV_FILE="${arg#*=}" ;;
|
|
--prune) PRUNE_IMAGES=true ;;
|
|
--yes|-y) AUTO_YES=true ;;
|
|
--help|-h) usage; exit 0 ;;
|
|
*) log_error "Unknown argument: $arg"; usage; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
require_cmd docker
|
|
load_stack_env "$ENV_FILE"
|
|
compose_file_path="$(compose_file)"
|
|
|
|
if ! confirm_action "Upgrade monitoring stack now?" "$AUTO_YES"; then
|
|
log_info "Cancelled"
|
|
exit 0
|
|
fi
|
|
|
|
log_info "Pulling latest images..."
|
|
docker compose \
|
|
--project-name "$COMPOSE_PROJECT_NAME" \
|
|
--env-file "$ENV_FILE" \
|
|
-f "$compose_file_path" \
|
|
pull
|
|
|
|
log_info "Recreating services..."
|
|
docker compose \
|
|
--project-name "$COMPOSE_PROJECT_NAME" \
|
|
--env-file "$ENV_FILE" \
|
|
-f "$compose_file_path" \
|
|
up -d --remove-orphans
|
|
|
|
if [[ "$PRUNE_IMAGES" == "true" ]]; then
|
|
log_info "Pruning dangling images..."
|
|
docker image prune -f
|
|
fi
|
|
|
|
log_success "Upgrade complete"
|