From 5330c5e1dea35dd0c42aee31959cda4d7e0d6ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9B=90=EC=B0=AC?= Date: Tue, 5 Mar 2024 11:19:16 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[chore]=20hotfix=20workflow=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/hotfix.yml | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/hotfix.yml diff --git a/.github/workflows/hotfix.yml b/.github/workflows/hotfix.yml new file mode 100644 index 0000000..f22cd91 --- /dev/null +++ b/.github/workflows/hotfix.yml @@ -0,0 +1,50 @@ +name: Build And Deploy + +on: + push: + branches: + - main + +jobs: + hotfix: + # push 이벤트가 발생했을 때만 실행 + if: github.event_name == 'push' + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Docker login + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Docker Build and Push + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.REPOSITORY_NAME }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Deploy to EC2 + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST }} + username: ubuntu + key: ${{ secrets.SSH_PRIVATE_KEY }} + script: | + sudo sh -c 'truncate -s 0 /var/lib/docker/containers/*/*-json.log' + cd ~/${{ secrets.REPOSITORY_NAME }} + sudo echo "${{ secrets.DOT_ENT }}" > .env + sudo docker rm -f ${{ secrets.REPOSITORY_NAME }} || true + sudo docker rmi -f ${{ secrets.DOCKER_USERNAME }}/${{ secrets.REPOSITORY_NAME }}:latest || true + sudo docker run -d --name ${{ secrets.REPOSITORY_NAME }} -p 8001:8000 --env-file .env ${{ secrets.DOCKER_USERNAME }}/${{ secrets.REPOSITORY_NAME }}:latest + + sudo docker exec ${{ secrets.REPOSITORY_NAME }} python3 manage.py migrate \ No newline at end of file From 31f6c757a3465543e825d01e9aa69d60d53ff549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9B=90=EC=B0=AC?= Date: Tue, 5 Mar 2024 15:01:13 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[chore]=20docker=20compose=20=EB=A1=9C=20?= =?UTF-8?q?=EC=8B=A4=ED=96=89=EB=90=98=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2e150d5..bcf1fd5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -46,4 +46,4 @@ jobs: sudo echo "${{ secrets.DOT_ENT }}" > .env sudo docker rm -f ${{ secrets.REPOSITORY_NAME }} || true sudo docker rmi -f ${{ secrets.DOCKER_USERNAME }}/${{ secrets.REPOSITORY_NAME }}:latest || true - sudo docker run -d --name ${{ secrets.REPOSITORY_NAME }} -p 8001:8000 --env-file .env ${{ secrets.DOCKER_USERNAME }}/${{ secrets.REPOSITORY_NAME }}:latest \ No newline at end of file + sudo docker-compose up -d \ No newline at end of file