Skip to content

Commit

Permalink
Merge pull request #502 from team-yello/staging
Browse files Browse the repository at this point in the history
AWS migration
  • Loading branch information
euije authored Jul 2, 2024
2 parents ceffa3e + 102987b commit d944f8b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 40 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/deploy-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ jobs:
run: |
aws s3 cp \
--region ap-northeast-2 \
./yello-build.zip s3://yello-test-application-bucket
./yello-build.zip s3://yello-test-bucket
- name: 📡 CodeDeploy에 배포를 요청합니다.
run: aws deploy create-deployment --application-name yello-deploy-application
run: aws deploy create-deployment --application-name yello-test-deploy
--deployment-config-name CodeDeployDefault.OneAtATime
--deployment-group-name yello-testing
--s3-location bucket=yello-test-application-bucket,bundleType=zip,key=yello-build.zip
--deployment-group-name yello-test-deploy
--s3-location bucket=yello-test-bucket,bundleType=zip,key=yello-build.zip

- name: 💡 배포 상태를 Slack을 통해 전송합니다.
uses: rtCamp/action-slack-notify@v2
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ jobs:
run: |
aws s3 cp \
--region ap-northeast-2 \
./yello-build.zip s3://yello-server-bucket
./yello-build.zip s3://yello-bucket
- name: 📡 CodeDeploy에 배포를 요청합니다.
run: aws deploy create-deployment --application-name yello-server-deploy
run: aws deploy create-deployment --application-name yello-deploy
--deployment-config-name CodeDeployDefault.OneAtATime
--deployment-group-name yello-app
--s3-location bucket=yello-server-bucket,bundleType=zip,key=yello-build.zip
--deployment-group-name yello-deploy
--s3-location bucket=yello-bucket,bundleType=zip,key=yello-build.zip

- name: 💡 배포 상태를 Slack을 통해 전송합니다.
uses: rtCamp/action-slack-notify@v2
Expand Down
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/rabbitmq/**

### 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: /home/ubuntu/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
6 changes: 0 additions & 6 deletions docker/docker-compose.blue.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
#blue
version: '3'
services:
redis:
image: redis
ports:
- "6379:6379"
backend:
build: .
ports:
- "8081:80"
container_name: yello-blue
environment:
- TZ=Asia/Seoul
depends_on:
- redis
6 changes: 0 additions & 6 deletions docker/docker-compose.green.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
#blue
version: '3'
services:
redis:
image: redis
ports:
- "6379:6379"
backend:
build: .
ports:
- "8082:80"
container_name: yello-green
environment:
- TZ=Asia/Seoul
depends_on:
- redis
32 changes: 16 additions & 16 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/bin/bash

cd /home/ec2-user/app
cd /home/ubuntu/app
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)] 배포를 시작합니다." >> /home/ubuntu/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 컨테이너를 일시적으로 종료합니다." >> /home/ubuntu/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 컨테이너를 종료합니다." >> /home/ubuntu/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 배포를 시작합니다." >> /home/ubuntu/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 서버를 종료합니다." >> /home/ubuntu/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 서버를 종료했습니다." >> /home/ubuntu/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 컨테이너를 종료합니다." >> /home/ubuntu/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 배포가 시작됩니다." >> /home/ubuntu/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 서버를 종료합니다." >> /home/ubuntu/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 서버를 종료했습니다." >> /home/ubuntu/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 컨테이너를 다시 시작합니다." >> /home/ubuntu/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 컨테이너를 다시 시작했습니다." >> /home/ubuntu/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)] 배포를 종료합니다." >> /home/ubuntu/deploy.log
echo "[$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)] 배포 프로세스 완료 =====================" >> /home/ubuntu/deploy.log
echo >> /home/ubuntu/deploy.log

0 comments on commit d944f8b

Please sign in to comment.