diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 2ada1f3..45cc4b2 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -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' # 메인 브랜치에 푸시했을 때만 실행 @@ -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 \ No newline at end of file + # 새로운 컨테이너를 실행 + 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 \ No newline at end of file