-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollback.sh
More file actions
46 lines (38 loc) · 1.63 KB
/
rollback.sh
File metadata and controls
46 lines (38 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
set -euo pipefail
# ============================================================
# MOA 수동 롤백 스크립트
# 사용법:
# ./rollback.sh <docker_tag> → 지정한 버전으로 배포
# ./rollback.sh → 직전 성공 버전으로 배포
# ============================================================
DEPLOY_HISTORY="/home/ubuntu/app/deploy-history"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
if [ -n "${1:-}" ]; then
ROLLBACK_TAG="$1"
echo "[Rollback] Target version specified: ${ROLLBACK_TAG}"
else
if [ ! -f "${DEPLOY_HISTORY}" ]; then
echo "[ERROR] Deploy history file not found: ${DEPLOY_HISTORY}"
echo "Cannot determine previous version. Please specify a docker tag."
echo "Usage: ./rollback.sh <docker_tag>"
exit 1
fi
CURRENT_TAG=$(grep "|SUCCESS" "${DEPLOY_HISTORY}" | tail -1 | cut -d'|' -f3)
ROLLBACK_TAG=$(grep "|SUCCESS" "${DEPLOY_HISTORY}" | grep -v "|${CURRENT_TAG}|" | tail -1 | cut -d'|' -f3)
if [ -z "${ROLLBACK_TAG}" ]; then
echo "[ERROR] No previous successful deployment found in history."
echo "Deploy history contents:"
cat "${DEPLOY_HISTORY}"
exit 1
fi
echo "[Rollback] Previous successful version found: ${ROLLBACK_TAG}"
echo " (Current version: ${CURRENT_TAG})"
fi
echo "========================================"
echo " Rolling back to: ${ROLLBACK_TAG}"
echo "========================================"
echo ""
# deploy.sh를 재호출하여 롤백 실행
# → 동일한 health check, smoke test, graceful shutdown 안전장치 적용
exec bash "${SCRIPT_DIR}/deploy.sh" "${ROLLBACK_TAG}"