Skip to content

Commit

Permalink
fix : change docker method
Browse files Browse the repository at this point in the history
  • Loading branch information
sycuuui committed Mar 21, 2024
1 parent 9d8bbea commit 5e3bc25
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ jobs:
docker build -t ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest .
docker push ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest
# EC2로 배포
- name: Deploy to EC2
if: github.ref == 'refs/heads/main' # 메인 브랜치에 푸시했을 때만 실행
Expand All @@ -54,9 +53,26 @@ jobs:
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
script: |
sudo docker login -u ${{ secrets.DOCKERHUB_NAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
sudo docker-compose stop ${{ secrets.DOCKER_SERVICE_NAME }}
sudo docker-compose rm -f ${{ secrets.DOCKER_SERVICE_NAME }}
# 실행 중인 동일한 컨테이너가 있으면 중지하고 제거
sudo docker stop $(sudo docker ps -aqf "name=${{ secrets.DOCKERHUB_REPOSITORY }}") || true
sudo docker rm $(sudo docker ps -aqf "name=${{ secrets.DOCKERHUB_REPOSITORY }}") || true
# 새로운 이미지를 pull 받음
sudo docker pull ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY}}
sudo docker tag ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY}} ${{ secrets.DOCKER_IMAGE_NAME }}
sudo docker-compose up -d
# 새로운 컨테이너를 실행
sudo docker run -d -p 5000:5000 --name ${{ secrets.DOCKERHUB_REPOSITORY }} ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY}}
# # EC2로 배포
# - name: Deploy to EC2
# if: github.ref == 'refs/heads/main' # 메인 브랜치에 푸시했을 때만 실행
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.HOST_PROD }} # EC2 퍼블릭 IPv4 DNS
# username: ubuntu
# key: ${{ secrets.PRIVATE_KEY }}
# script: |
# sudo docker login -u ${{ secrets.DOCKERHUB_NAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
# sudo docker-compose stop ${{ secrets.DOCKER_SERVICE_NAME }}
# sudo docker-compose rm -f ${{ secrets.DOCKER_SERVICE_NAME }}
# sudo docker pull ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY}}
# sudo docker tag ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY}} ${{ secrets.DOCKER_IMAGE_NAME }}
# sudo docker-compose up -d

0 comments on commit 5e3bc25

Please sign in to comment.