Skip to content

Commit

Permalink
deploy: CI/CD Workflow 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
LJH098 committed Nov 10, 2024
1 parent 3827cf6 commit a00e543
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 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: [ "develop" ]
branches: [ "deploy-#37" ]

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

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

# SSH 비밀 키 설정
- name: Install SSH Key
uses: webfactory/[email protected]
with:
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
- name: Deploy to server
uses: appleboy/ssh-action@master
id: deploy
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
script: |
cd /home/ubuntu # docker-compose.yml 파일 위치로 이동
# 기존 컨테이너 중지
docker-compose down
# 사용 중인 이미지 제거 (캐시 무효화를 위해)
docker images -q ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }} | xargs -r sudo docker rmi
# 최신 이미지 pull
docker-compose pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }}
# 모든 서비스 다시 실행
docker-compose up -d
EOF

0 comments on commit a00e543

Please sign in to comment.