From ceea5a2e7308323291713b8fc07165b15b063f9a Mon Sep 17 00:00:00 2001 From: Henrique Melo Date: Tue, 24 Oct 2023 03:43:00 -0300 Subject: [PATCH] deploy ec2 --- .github/workflows/deploy.yml | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7e81b71..528528f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -5,9 +5,12 @@ on: branches: ['CD_test_branch'] tags: ['v*.*.*'] +env: + TARGET_DIR: '~/api/${{ github.event.repository.name }}' + jobs: - deploy: - name: Docker Hub + docker-hub: + name: Docker Hub Image Push runs-on: ubuntu-latest steps: - name: Check out code @@ -23,3 +26,23 @@ jobs: tags: latest username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + deploy-ec2: + name: Deploy EC2 + needs: docker-hub + runs-on: ubuntu-latest + steps: + - name: Checkout the files + uses: actions/checkout@v2 + + - name: Executing remote ssh commands using ssh key + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.EC2_HOST_DNS }} + username: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.EC2_SSH_KEY }} + script: | + cd ${{env.TARGET_DIR}} + git checkout CD_test_branch + git pull + docker-compose -f docker-compose.prod.yml up -V --force-recreate --build -d