**Motivations:** - Single generic orchestration in ia_dev while business logic stays in each project repo **Root causes:** - N/A (evolution) **Correctifs:** - N/A **Evolutions:** - Add orchestrator.sh (deploy.hooks.phases or fallback deploy.deploy_script_path) - Add deploy.sh <project_id> <env> [options] as canonical entry from ia_dev root - run-project-hooks.sh execs orchestrator.sh for backward compatibility - change-to-all-branches.sh and deploy-by-script-to.sh invoke orchestrator.sh when IA_PROJECT_ID is set - Document orchestration in README.md and deploy/lib/README.md **Pages affectées:** - README.md, deploy/orchestrator.sh, deploy/deploy.sh, deploy/run-project-hooks.sh, deploy/change-to-all-branches.sh, deploy/deploy-by-script-to.sh, deploy/lib/README.md
75 lines
2.8 KiB
Bash
Executable File
75 lines
2.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Generic deploy orchestrator: runs deploy.hooks.phases from projects/<id>/conf.json (paths relative to repository_root).
|
|
# If phases is empty or missing, exec deploy.deploy_script_path with the same arguments.
|
|
# Business logic (Prisma, systemd, remote layout) stays in each project's scripts under repository_root.
|
|
# Usage: orchestrator.sh <env> [options passed to each phase / fallback script]
|
|
# Requires: IA_PROJECT_ID, IA_DEV_ROOT (or re-exec from project root like change-to-all-branches).
|
|
set -euo pipefail
|
|
|
|
SCRIPT_REAL="$(readlink -f "${BASH_SOURCE[0]:-$0}" 2>/dev/null || realpath "${BASH_SOURCE[0]:-$0}" 2>/dev/null || echo "${BASH_SOURCE[0]:-$0}")"
|
|
DEPLOY_DIR="$(cd "$(dirname "$SCRIPT_REAL")" && pwd)"
|
|
IA_DEV_ROOT="$(cd "$DEPLOY_DIR/.." && pwd)"
|
|
|
|
_ORCH_TAG="[orchestrator]"
|
|
|
|
if [[ -z "${IA_PROJECT_ID:-}" ]]; then
|
|
echo "${_ORCH_TAG}[ERROR] IA_PROJECT_ID is not set" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# shellcheck source=../lib/project_config.sh
|
|
source "${IA_DEV_ROOT}/lib/project_config.sh"
|
|
# shellcheck source=../lib/project_git_root_from_conf.sh
|
|
source "${IA_DEV_ROOT}/lib/project_git_root_from_conf.sh"
|
|
ia_dev_resolve_project_git_root
|
|
REPO_ROOT="${IA_PROJECT_GIT_ROOT:-}"
|
|
if [[ -z "$REPO_ROOT" || ! -d "$REPO_ROOT" ]]; then
|
|
echo "${_ORCH_TAG}[ERROR] Could not resolve repository root for project ${IA_PROJECT_ID}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
CONF="${PROJECT_CONFIG_PATH:-}"
|
|
if [[ -z "$CONF" || ! -f "$CONF" ]]; then
|
|
echo "${_ORCH_TAG}[ERROR] Missing conf: ${CONF:-}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v jq >/dev/null 2>&1; then
|
|
echo "${_ORCH_TAG}[ERROR] jq is required to read deploy.hooks.phases" >&2
|
|
exit 1
|
|
fi
|
|
|
|
SECRETS_PATH_CFG="$(jq -r '.deploy.secrets_path // empty' "$CONF")"
|
|
if [[ -n "$SECRETS_PATH_CFG" && "$SECRETS_PATH_CFG" != "null" && -d "$SECRETS_PATH_CFG" ]]; then
|
|
export SECRETS_BASE="$SECRETS_PATH_CFG"
|
|
export LECOFFRE_SECRETS_BASE="$SECRETS_PATH_CFG"
|
|
fi
|
|
|
|
DEPLOY_SCRIPT_PATH="$(jq -r '.deploy.deploy_script_path // empty' "$CONF")"
|
|
if [[ -z "$DEPLOY_SCRIPT_PATH" || ! -f "$DEPLOY_SCRIPT_PATH" ]]; then
|
|
echo "${_ORCH_TAG}[ERROR] deploy.deploy_script_path missing or not a file: ${DEPLOY_SCRIPT_PATH:-}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
PHASE_COUNT="$(jq '.deploy.hooks.phases // [] | length' "$CONF")"
|
|
if [[ "$PHASE_COUNT" == "0" ]]; then
|
|
exec bash "$DEPLOY_SCRIPT_PATH" "$@"
|
|
fi
|
|
|
|
mapfile -t PHASE_SCRIPTS < <(jq -r '.deploy.hooks.phases[]? | if type == "string" then . elif type == "object" and (.run | type == "string") then .run else empty end' "$CONF")
|
|
|
|
if [[ ${#PHASE_SCRIPTS[@]} -eq 0 ]]; then
|
|
exec bash "$DEPLOY_SCRIPT_PATH" "$@"
|
|
fi
|
|
|
|
for rel in "${PHASE_SCRIPTS[@]}"; do
|
|
[[ -z "$rel" ]] && continue
|
|
phase_path="${REPO_ROOT}/${rel}"
|
|
if [[ ! -f "$phase_path" ]]; then
|
|
echo "${_ORCH_TAG}[ERROR] Phase script not found: ${phase_path}" >&2
|
|
exit 1
|
|
fi
|
|
echo "${_ORCH_TAG} Running: ${rel} $*"
|
|
bash "$phase_path" "$@"
|
|
done
|