Skip to content

Commit

Permalink
Merge pull request #495 from team-yello/develop
Browse files Browse the repository at this point in the history
develop [develop] fix: ubuntu migration
  • Loading branch information
euije authored Jun 30, 2024
2 parents ffcd176 + aaf473d commit 09e6783
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ application-local.yml
firebase*.json
*client_secret*.json

docker/docker-compose.mq.yml

### monitoring ###
monitoring/prometheus/volume
monitoring/grafana
Expand Down
8 changes: 4 additions & 4 deletions appspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ os: linux
## 코드 파일 전송
files:
- source: /
destination: /home/ec2-user/app
destination: ~/app
overwrite: yes # overwrite 허용 여부

## 권한 설정
permissions:
- object: /
pattern: "**" # 전체 파일
owner: ec2-user
group: ec2-user
owner: ubuntu
group: ubuntu

# 실행될 스크립트
hooks:
# 시작 시
ApplicationStart:
- location: deploy.sh
timeout: 60
runas: ec2-user
runas: ubuntu
30 changes: 15 additions & 15 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ DOCKER_APP_NAME=yello

# BLUE 서버 체크
EXIST_BLUE=$(sudo docker-compose -p ${DOCKER_APP_NAME}-blue -f docker-compose.blue.yml ps | grep Up)
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] 배포를 시작합니다." >> /home/ec2-user/deploy.log
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] 배포를 시작합니다." >> ~/deploy.log

# Redis 컨테이너가 실행 중인지 확인
REDIS_RUNNING=$(sudo docker ps -q -f "name=redis" -f "expose=6379")

# Redis 컨테이너가 실행 중이면 일시적으로 종료
if [ -n "$REDIS_RUNNING" ]; then
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Redis 컨테이너를 일시적으로 종료합니다." >> /home/ec2-user/deploy.log
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Redis 컨테이너를 일시적으로 종료합니다." >> ~/deploy.log
sudo docker-compose -p ${DOCKER_APP_NAME}-blue -f docker-compose.blue.yml stop redis
sudo docker-compose -p ${DOCKER_APP_NAME}-green -f docker-compose.green.yml stop redis
fi
Expand All @@ -22,11 +22,11 @@ if [ -z "$EXIST_BLUE" ]; then
REDIS_GREEN_RUNNING=$(sudo docker-compose -p ${DOCKER_APP_NAME}-green -f docker-compose.green.yml ps | grep redis)

if [ -n "$REDIS_GREEN_RUNNING" ]; then
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Green Redis 컨테이너를 종료합니다." >> /home/ec2-user/deploy.log
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Green Redis 컨테이너를 종료합니다." >> ~/deploy.log
sudo docker-compose -p ${DOCKER_APP_NAME}-green -f docker-compose.green.yml stop redis
fi

echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Blue 배포를 시작합니다." >> /home/ec2-user/deploy.log
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Blue 배포를 시작합니다." >> ~/deploy.log

sudo docker-compose -p ${DOCKER_APP_NAME}-blue -f docker-compose.blue.yml up -d --build
sleep 30
Expand All @@ -35,22 +35,22 @@ if [ -z "$EXIST_BLUE" ]; then
if [ -z "$BLUE_HEALTH" ]; then
sudo ./slack_blue.sh
else
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Green 서버를 종료합니다." >> /home/ec2-user/deploy.log
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Green 서버를 종료합니다." >> ~/deploy.log
sudo docker-compose -p ${DOCKER_APP_NAME}-green -f docker-compose.green.yml down
sudo docker image prune -af
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Green 서버를 종료했습니다." >> /home/ec2-user/deploy.log
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Green 서버를 종료했습니다." >> ~/deploy.log
fi

# BLUE가 실행중이면 GREEN up
else
REDIS_BLUE_RUNNING=$(sudo docker-compose -p ${DOCKER_APP_NAME}-blue -f docker-compose.blue.yml ps | grep redis)

if [ -n "REDIS_BLUE_RUNNING" ]; then
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Blue Redis 컨테이너를 종료합니다." >> /home/ec2-user/deploy.log
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Blue Redis 컨테이너를 종료합니다." >> ~/deploy.log
sudo docker-compose -p ${DOCKER_APP_NAME}-blue -f docker-compose.blue.yml stop redis
fi

echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Green 배포가 시작됩니다." >> /home/ec2-user/deploy.log
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Green 배포가 시작됩니다." >> ~/deploy.log
sudo docker-compose -p ${DOCKER_APP_NAME}-green -f docker-compose.green.yml up -d --build
sleep 30

Expand All @@ -59,21 +59,21 @@ else
if [ -z "$GREEN_HEALTH" ]; then
sudo ./slack_green.sh
else
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Blue 서버를 종료합니다." >> /home/ec2-user/deploy.log
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Blue 서버를 종료합니다." >> ~/deploy.log
sudo docker-compose -p ${DOCKER_APP_NAME}-blue -f docker-compose.blue.yml down
sudo docker image prune -af
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Blue 서버를 종료했습니다." >> /home/ec2-user/deploy.log
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Blue 서버를 종료했습니다." >> ~/deploy.log
fi
fi

# Redis 컨테이너가 종료되었을 경우 다시 시작
if [ -n "$REDIS_RUNNING" ]; then
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Redis 컨테이너를 다시 시작합니다." >> /home/ec2-user/deploy.log
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Redis 컨테이너를 다시 시작합니다." >> ~/deploy.log
sudo docker-compose -p ${DOCKER_APP_NAME}-blue -f docker-compose.blue.yml start redis
sudo docker image prune -af
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Redis 컨테이너를 다시 시작했습니다." >> /home/ec2-user/deploy.log
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] Redis 컨테이너를 다시 시작했습니다." >> ~/deploy.log
fi

echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] 배포를 종료합니다." >> /home/ec2-user/deploy.log
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] 배포 프로세스 완료 =====================" >> /home/ec2-user/deploy.log
echo >> /home/ec2-user/deploy.log
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] 배포를 종료합니다." >> ~/deploy.log
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] 배포 프로세스 완료 =====================" >> ~/deploy.log
echo >> ~/deploy.log

0 comments on commit 09e6783

Please sign in to comment.