-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17dcecc
commit e5f2ae1
Showing
2 changed files
with
84 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/bash | ||
|
||
echo "1. 환경 설정" | ||
source /etc/profile | ||
cd /home/ubuntu/tori-backend | ||
|
||
FAILURE_TIME=$(date '+%Y-%m-%d %H:%M:%S') | ||
TIMESTAMP=$(date +%Y%m%d_%H%M%S) | ||
LOG_FILENAME="build_failure_${TIMESTAMP}.log" | ||
LOCAL_LOG_PATH="/var/log/deploy/${LOG_FILENAME}" | ||
S3_LOG_PATH="s3://${S3_BUCKET}/deploy-logs/${LOG_FILENAME}" | ||
|
||
echo "2. 로컬 로그 저장" | ||
mkdir -p /var/log/deploy | ||
docker logs $(docker ps -q -l) > ${LOCAL_LOG_PATH} 2>&1 | ||
|
||
echo "3. S3에 로그 업로드" | ||
if aws s3 cp ${LOCAL_LOG_PATH} ${S3_LOG_PATH}; then | ||
echo "로그 업로드 성공: ${S3_LOG_PATH}" | ||
# 30분 동안 유효한 임시 URL 생성 | ||
LOG_URL=$(aws s3 presign ${S3_LOG_PATH} --expires-in 1800) | ||
else | ||
echo "로그 업로드 실패" | ||
LOG_URL="로그 업로드 실패" | ||
fi | ||
|
||
echo "4. Discord 알림 전송" | ||
MESSAGE=$(cat <<EOF | ||
\`\`\` | ||
______ _ _ ______ _ _ _ | ||
| ____(_) | | ____| (_) | | | | ||
| |__ _| | _ _ _ __ ___ | |__ __ _ _| | ___ __| | | ||
| __| | | |/ | | | '__/ _ \ | __/ _\` | | |/ _ \/ _\` | | ||
| | | | | (_| | | | __/ | | | (_| | | | __/ (_| | | ||
|_| |_|_|\__,_|_| \___| |_| \__,_|_|_|\___|\__,_| | ||
🚨 빌드 실패 🚨 | ||
실패 시간: ${FAILURE_TIME} | ||
원인: 도커 이미지 빌드 과정에서 오류가 발생했습니다. | ||
상세 로그: ${LOG_URL} | ||
(로그 URL은 30분간 유효합니다) | ||
\`\`\` | ||
EOF | ||
) | ||
|
||
JSON_PAYLOAD=$(jq -n \ | ||
--arg msg "$MESSAGE" \ | ||
'{content: $msg}') | ||
|
||
curl -H "Content-Type: application/json" \ | ||
-X POST \ | ||
-d "$JSON_PAYLOAD" \ | ||
${DISCORD_DEPLOY_WEBHOOK} | ||
|
||
echo "5. 로컬 로그 정리" | ||
find /var/log/deploy -name "build_failure_*.log" -type f -mtime +3 -delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters