Skip to content

Commit

Permalink
Revert "deploy: CI/CD 수정 (#38)"
Browse files Browse the repository at this point in the history
This reverts commit 683bdf9.
  • Loading branch information
LJH098 authored Nov 11, 2024
1 parent 683bdf9 commit 9f444ba
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions .github/workflows/prod-deploy-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ name: CI/CD Workflow for Develop
on:
# PR 작성 및 업데이트 시 CI 실행
pull_request:
branches: [ "deploy-#37" ]
branches: [ "develop" ]

# develop 브랜치로의 푸시 시 CD 실행
push:
branches: [ "deploy-#37" ]
branches: [ "develop" ]

jobs:
# 공통 설정 및 Gradle 빌드용 Setup job
Expand Down Expand Up @@ -82,25 +82,30 @@ jobs:
- name: Push Docker image to Docker Hub
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }}

# EC2 서버에 Docker Compose로 배포
- name: Deploy to server
uses: appleboy/ssh-action@master
id: deploy
# SSH 비밀 키 설정
- name: Install SSH Key
uses: webfactory/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_KEY }}
script: |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

# EC2 서버에 Docker Compose로 배포
- name: Deploy on EC2
env:
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ${{ secrets.EC2_USER }}
run: |
ssh -o StrictHostKeyChecking=no $EC2_USER@$EC2_HOST << EOF
cd /home/ubuntu # docker-compose.yml 파일 위치로 이동
# 기존 컨테이너 중지
sudo docker-compose down
docker-compose down
# 사용 중인 이미지 제거 (캐시 무효화를 위해)
sudo docker images -q ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }} | xargs -r sudo docker rmi
docker images -q ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }} | xargs -r sudo docker rmi
# 최신 이미지 pull
sudo docker-compose pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }}
docker-compose pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }}
# 모든 서비스 다시 실행
sudo docker-compose up -d
docker-compose up -d
EOF

0 comments on commit 9f444ba

Please sign in to comment.