From ebeab99cdde56afcf24e041ccc97a8619eeb772e Mon Sep 17 00:00:00 2001 From: leiyun Date: Sun, 14 Jun 2026 17:15:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- isolated/apply-update.sh | 32 ++++++++++++++++++++++++++++---- isolated/build-update.sh | 3 +++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/isolated/apply-update.sh b/isolated/apply-update.sh index e54f72f..fe82e81 100644 --- a/isolated/apply-update.sh +++ b/isolated/apply-update.sh @@ -6,6 +6,7 @@ set -Eeuo pipefail # bash apply-update.sh # bash apply-update.sh emp-admin emp-monitor # DEPLOY_ENV=emp-uat ENV_FILE=.env COMPOSE_FILE=docker-compose.yml bash apply-update.sh +# COMPOSE_FILES="/path/docker-compose.yml:/path/docker-compose.logs.yml" bash apply-update.sh SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" @@ -15,6 +16,7 @@ PROJECT_NAME="${PROJECT_NAME:-$DEPLOY_ENV}" DEPLOY_HOME="${DEPLOY_HOME:-/home/admin-x99/$DEPLOY_ENV}" ENV_FILE="${ENV_FILE:-.env}" COMPOSE_FILE="${COMPOSE_FILE:-docker-compose.yml}" +COMPOSE_FILES="${COMPOSE_FILES:-}" IMAGE_TAR="${IMAGE_TAR:-images.tar}" SERVICE_FILE="${SERVICE_FILE:-services.txt}" @@ -83,6 +85,28 @@ resolve_runtime_file() { echo "$requested" } +resolve_compose_files() { + local raw_files=() + local file resolved + if [[ -n "$COMPOSE_FILES" ]]; then + IFS=':' read -r -a raw_files <<< "$COMPOSE_FILES" + else + raw_files=("$COMPOSE_FILE") + fi + + COMPOSE_ARGS=() + RESOLVED_COMPOSE_FILES=() + for file in "${raw_files[@]}"; do + [[ -n "$file" ]] || continue + resolved="$(resolve_runtime_file "$file" "docker-compose.yml")" + [[ -f "$resolved" ]] || die "Missing compose file: $resolved" + RESOLVED_COMPOSE_FILES+=("$resolved") + COMPOSE_ARGS+=("-f" "$resolved") + done + + [[ "${#COMPOSE_ARGS[@]}" -gt 0 ]] || die "No compose files resolved." +} + read_services() { local raw_services=() if [[ "$#" -gt 0 ]]; then @@ -102,9 +126,8 @@ read_services() { need_cmd docker ENV_FILE="$(resolve_runtime_file "$ENV_FILE" ".env")" -COMPOSE_FILE="$(resolve_runtime_file "$COMPOSE_FILE" "docker-compose.yml")" +resolve_compose_files [[ -f "$ENV_FILE" ]] || die "Missing env file: $ENV_FILE" -[[ -f "$COMPOSE_FILE" ]] || die "Missing compose file: $COMPOSE_FILE" [[ -f "$IMAGE_TAR" ]] || die "Missing image tar: $IMAGE_TAR" mapfile -t UPDATE_SERVICES < <(read_services "$@") @@ -112,6 +135,7 @@ mapfile -t UPDATE_SERVICES < <(read_services "$@") COMPOSE_CMD="$(resolve_compose_cmd)" +log "Compose files: ${RESOLVED_COMPOSE_FILES[*]}" log "Load images: $IMAGE_TAR" docker load -i "$IMAGE_TAR" @@ -119,7 +143,7 @@ log "Recreate services: ${UPDATE_SERVICES[*]}" # shellcheck disable=SC2086 $COMPOSE_CMD \ --env-file "$ENV_FILE" \ - -f "$COMPOSE_FILE" \ + "${COMPOSE_ARGS[@]}" \ -p "$PROJECT_NAME" \ up -d --no-deps --force-recreate "${UPDATE_SERVICES[@]}" @@ -127,6 +151,6 @@ log "Current service status" # shellcheck disable=SC2086 $COMPOSE_CMD \ --env-file "$ENV_FILE" \ - -f "$COMPOSE_FILE" \ + "${COMPOSE_ARGS[@]}" \ -p "$PROJECT_NAME" \ ps "${UPDATE_SERVICES[@]}" diff --git a/isolated/build-update.sh b/isolated/build-update.sh index 5b66d8b..b31840b 100644 --- a/isolated/build-update.sh +++ b/isolated/build-update.sh @@ -337,5 +337,8 @@ Manual fallback: cd /tmp/emp-update bash apply-update.sh +If the target runtime uses a compose override, pass all compose files: + COMPOSE_FILES="/home/admin-x99/emp/$DEPLOY_ENV/runtime/docker-compose.yml:/home/admin-x99/emp/$DEPLOY_ENV/runtime/docker-compose.logs.yml" bash apply-update.sh + EOF fi