Skip to content

Commit

Permalink
feat: 무중단 배포 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
abc5259 committed Oct 17, 2024
1 parent 8e9b01c commit 8110f41
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 16 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/dev-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ jobs:
run: |
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/dnd-server:latest
- name: SSH로 EC2에 접속하여 Docker Compose 실행
- name: SSH로 EC2에 접속하여 배포 스크립트 실행
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
script_stop: true
script: |
docker-compose -f /home/ubuntu/compose/docker-compose.yml down || true
docker-compose -f /home/ubuntu/compose/docker-compose.yml pull
docker-compose -f /home/ubuntu/compose/docker-compose.yml up -d
bash /home/ubuntu/compose/deploy.sh
12 changes: 0 additions & 12 deletions .github/workflows/staging-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,3 @@ jobs:
- name: Docker Hub에 Docker 이미지 Push하기
run: |
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/dnd-staging-server:latest
# - name: SSH로 EC2에 접속하여 Docker Compose 실행
# uses: appleboy/[email protected]
# with:
# host: ${{ secrets.EC2_HOST }}
# username: ${{ secrets.EC2_USERNAME }}
# key: ${{ secrets.EC2_PRIVATE_KEY }}
# script_stop: true
# script: |
# docker-compose -f /home/ubuntu/compose/docker-compose.yml down || true
# docker-compose -f /home/ubuntu/compose/docker-compose.yml pull
# docker-compose -f /home/ubuntu/compose/docker-compose.yml up -d
56 changes: 56 additions & 0 deletions deploy/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

IP=127.0.0.1
IS_DEV1=$(docker ps | grep dev1)

if [ -z "$IS_DEV1" ];then
BLUE_PORT="8081"
GREEN_PORT="8080"
CONTAINER_NAME="dev1"
STOP_CONTAINER_NAME="dev2"
else
BLUE_PORT="8080"
GREEN_PORT="8081"
CONTAINER_NAME="dev2"
STOP_CONTAINER_NAME="dev1"
fi

if [ $GREEN_PORT == "none" ]
then
echo "블루와 그린을 임으로 지정합니다.\n"
BLUE_PORT="8080"
GREEN_PORT="8081"
fi

echo -e "그린($GREEN_PORT)과 블루($BLUE_PORT) 서버 확인 ${CONTAINER_NAME} 컨테이너를 실행합니다."

docker compose pull $CONTAINER_NAME
docker compose up -d $CONTAINER_NAME

for retry in {1..10}
do
RESPONSE=$(curl -s http://$IP:$GREEN_PORT/actuator/health)
GREEN_HEALTH=$(echo ${RESPONSE} | grep 'UP' | wc -l)
if [ $GREEN_HEALTH -eq 1 ]
then
break
else
echo -e "$IP:$GREEN_PORT 가 켜져있지 않습니다. 10초 슬립하고 다시 헬스체크를 수행합니다."
sleep 10
fi
done

if [ $GREEN_HEALTH -eq 0 ]
then
echo -e "$IP:$GREEN_PORT 가 작동하지 않습니다."
exit 0
else
echo -e "$IP:$GREEN_PORT 가 정상적으로 실행 중입니다."
fi

echo "set \$service_url $CONTAINER_NAME;" | sudo tee ./conf/service-url.inc
sudo docker exec nginx nginx -s reload

echo "$STOP_CONTAINER_NAME 컨테이너 종료"
docker compose stop $STOP_CONTAINER_NAME
docker compose rm -f $STOP_CONTAINER_NAME
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
Expand Down Expand Up @@ -115,4 +116,5 @@ public ResponseEntity<ResponseDto<SnapDetailResponseDto>> findSnapById(
var data = snapService.findSnapById(snapId);
return ResponseDto.ok(data);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ List<SnapResponseDto> findParticipantSnapsInMeetingByCursorId(
""")
Optional<Snap> findSnapByIdWithParticipant(@Param("snapId") Long snapId);


}

0 comments on commit 8110f41

Please sign in to comment.