-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
54 lines (42 loc) · 1.93 KB
/
deploy.sh
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
47
48
49
50
51
52
53
54
#!/bin/bash
# 사용할 리전을 명시
REGION="ap-northeast-2"
DEPLOY_LOG_PATH="/home/ubuntu/frontend/production/log/deploy/deploy_$(date +%Y%m%d).log"
echo "> deployment start : $(date +%c)" >> $DEPLOY_LOG_PATH
# 최신 배포 ID 가져오기
DEPLOYMENT_ID=$(grep -oP '\[d-[a-zA-Z0-9]+\]' /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log | tail -1 | grep -oP 'd-[a-zA-Z0-9]+')
# 배포 그룹 이름 가져오기
DEPLOYMENT_GROUP_NAME=$(aws deploy get-deployment --region "$REGION" --deployment-id "$DEPLOYMENT_ID" --query 'deploymentInfo.deploymentGroupName' --output text)
echo "배포 그룹 이름: $DEPLOYMENT_GROUP_NAME" >> $DEPLOY_LOG_PATH
# app directory
APP_DIR="/home/ubuntu/frontend"
PRODUCTION_DIR="$APP_DIR/production/cotato"
RELEASE_DIR="$APP_DIR/release/cotato"
# 배포 그룹 이름에 따라 대상 디렉토리를 설정
if [[ "$DEPLOYMENT_GROUP_NAME" == "cotato-deploy-fe-production" ]]; then
TARGET_DIR=$PRODUCTION_DIR
elif [[ "$DEPLOYMENT_GROUP_NAME" == "cotato-deploy-fe-release" ]]; then
TARGET_DIR=$RELEASE_DIR
else
echo "Unknown deployment group: $DEPLOYMENT_GROUP_NAME" >> $DEPLOY_LOG_PATH
exit 1
fi
# 기존 파일 및 디렉토리 삭제
if [ -d "$TARGET_DIR/build" ]; then
rm -rf "$TARGET_DIR/build"
echo "기존 build 디렉토리 존재" >> $DEPLOY_LOG_PATH
fi
if [ -f "$TARGET_DIR/appspec.yml" ]; then
rm "$TARGET_DIR/appspec.yml"
echo "기존 appspec.yml 존재" >> $DEPLOY_LOG_PATH
fi
if [ -f "$TARGET_DIR/deploy.sh" ]; then
rm "$TARGET_DIR/deploy.sh"
echo "기존 deploy.sh 존재" >> $DEPLOY_LOG_PATH
fi
# build 디렉토리, appspec.yml, deploy.sh 파일을 대상 디렉토리로 이동
mv "$APP_DIR/cotato/build" "$TARGET_DIR"
mv "$APP_DIR/cotato/appspec.yml" "$TARGET_DIR"
mv "$APP_DIR/cotato/deploy.sh" "$TARGET_DIR"
echo "Deployment files moved to $TARGET_DIR" >> $DEPLOY_LOG_PATH
echo "> deployment end : $(date +%c)" >> $DEPLOY_LOG_PATH