**Motivations:** Same tee naming as lecoffre_ng_test deploy.sh when SITE_CODE is set. **Correctives:** deploy_<env>_<site>_kogus_<ts>.log when site env is set; header includes site=. **Evolutions:** kogus docs IMPORT_V1 + agents-scripts-split log path wording. **Page affectées:** deploy/lib/deploy-log.sh, projects/kogus/docs.
44 lines
1.7 KiB
Bash
44 lines
1.7 KiB
Bash
#!/usr/bin/env bash
|
|
# Optional tee of deploy output to a log file under the project root.
|
|
|
|
# Args: project_root log_to_dir_relative [deploy_env]
|
|
# With deploy_env and SITE_CODE|LECOFFRE_SITE_CODE|DEPLOY_SITE_CODE: deploy_<env>_<site>_kogus_YYYYMMDD_HHMMSS.log (multisite + .secrets/kogus/<env>/).
|
|
# With deploy_env only: deploy_<env>_YYYYMMDD_HHMMSS.log
|
|
deploy_script_tee_log_if_requested() {
|
|
local project_root="${1:?}"
|
|
local log_to_dir="${2:-}"
|
|
local deploy_env="${3:-}"
|
|
if [[ -z "$log_to_dir" ]]; then
|
|
return 0
|
|
fi
|
|
mkdir -p "${project_root}/${log_to_dir}"
|
|
local site_slug="${SITE_CODE:-${LECOFFRE_SITE_CODE:-${DEPLOY_SITE_CODE:-}}}"
|
|
if [[ "$site_slug" == "notary" ]]; then
|
|
site_slug="lecoffreio"
|
|
fi
|
|
local ts
|
|
ts="$(date +%Y%m%d_%H%M%S)"
|
|
local log_file
|
|
if [[ -n "$deploy_env" ]]; then
|
|
if [[ -n "$site_slug" ]]; then
|
|
log_file="${project_root}/${log_to_dir}/deploy_${deploy_env}_${site_slug}_kogus_${ts}.log"
|
|
else
|
|
log_file="${project_root}/${log_to_dir}/deploy_${deploy_env}_${ts}.log"
|
|
fi
|
|
else
|
|
log_file="${project_root}/${log_to_dir}/deploy_${ts}.log"
|
|
fi
|
|
{
|
|
printf '%s\n' "=== LeCoffre deploy log ==="
|
|
printf '%s\n' "environment=${deploy_env:-<unset>} site=${site_slug:-<unset>} started_at=${DEPLOY_STARTED_AT:-} project_root=${project_root}"
|
|
} >"$log_file"
|
|
_IA_DEV_DEPLOY_LOG="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
if [[ -f "${_IA_DEV_DEPLOY_LOG}/lib/smart_ide_logs.sh" ]]; then
|
|
# shellcheck source=../../lib/smart_ide_logs.sh
|
|
SMART_IDE_LOG_IA_DEV_ROOT="$_IA_DEV_DEPLOY_LOG" source "${_IA_DEV_DEPLOY_LOG}/lib/smart_ide_logs.sh"
|
|
smart_ide_log_event "deploy_script_tee_log project_root=${project_root} log_file=${log_file}"
|
|
fi
|
|
exec > >(tee -a "$log_file")
|
|
info "[deploy] Teeing output to ${log_file}"
|
|
}
|