From c13c049111d061a973d553bd55e93a10fd793bae Mon Sep 17 00:00:00 2001 From: Gabriel Reis Date: Mon, 2 Dec 2024 09:08:03 -0300 Subject: [PATCH] Create deploy.yaml --- .github/workflows/deploy.yaml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/deploy.yaml diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..5cb83a8 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,34 @@ +name: Deploy + +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set permissions for private key + run: | + echo "${{ secrets.KEYAWS }}" > key.pem + chmod 600 key.pem + + - name: Stop running containers + run: | + ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@98.80.44.121 'if [ -d /home/ubuntu/tupan-back/ ]; then cd /home/ubuntu/tupan-back/ && sudo docker-compose down; fi' + + - name: Deploy to EC2 + run: | + rsync -av --delete ./ ubuntu@98.80.44.121:/home/ubuntu/tupan-back + + - name: Run Docker Compose + run: | + ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@98.80.44.121 'cd /home/ubuntu/tupan-back && sudo docker-compose up -d' + + - name: Cleanup + run: | + rm -f key.pem