From c6af7f7926755db97805f93db575082b3e3397e8 Mon Sep 17 00:00:00 2001 From: Bruno Rodrigues Date: Mon, 13 May 2024 21:40:40 +0100 Subject: [PATCH] chore: add deploy webhook --- .github/workflows/deploy.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..ee43522 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,32 @@ +name: Deploy to EC2 +on: + push: + branches: + - main +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: "16" + - name: Build and push Docker image + run: | + docker build -t ${{vars.PROJECT}} --build-arg PROJECT=server . + docker tag whatsapp-newsletter:latest ${{ vars.DOCKER_REPO}}:latest + docker login -u ${{ vars.DOCKER_USERNAME }} -p ${{secrets.DOCKER_TOEKEN}} + docker push ${{ vars.DOCKER_REPO}}:latest + - name: SSH into EC2 instance and deploy + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.MY_EC2_SSH_KEY }} + script: | + sudo docker pull ${{ vars.DOCKER_REPO }}:latest + sudo docker stop my-node-app || true + sudo docker rm my-node-app || true + sudo docker run -d -p 3000:3000 --name my-node-app ${{ vars.DOCKER_REPO }}:latest