From 5097df821fe6725cdd8b7cc2758904808471a061 Mon Sep 17 00:00:00 2001 From: varsha1305nav <87652813+varsha1305nav@users.noreply.github.com> Date: Thu, 30 Nov 2023 17:19:18 +0530 Subject: [PATCH] update --- .github/workflows/deploy_api.yml | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/deploy_api.yml diff --git a/.github/workflows/deploy_api.yml b/.github/workflows/deploy_api.yml new file mode 100644 index 00000000..1d5d271b --- /dev/null +++ b/.github/workflows/deploy_api.yml @@ -0,0 +1,44 @@ +name: Deploy + +on: + push: + branches: [ main ] +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Get Github action IP + id: ip + uses: haythem/public-ip@v1.2 + - name: Setting environment variables.. + run: | + echo "AWS_DEFAULT_REGION=eu-west-2" >> $GITHUB_ENV + echo "AWS_SG_NAME=${{ secrets.AWS_SECURITY_GROUP_ID }}" >> $GITHUB_ENV + + - name: Add Github Actions IP to Security group + run: | + aws ec2 authorize-security-group-ingress --group-id ${{ env.AWS_SG_NAME }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }} + + - name: Steps + uses: appleboy/ssh-action@master + continue-on-error: false + with: + host: ${{ secrets.DEVSERVER }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.SECRETKEY }} + command_timeout: 50m + script: | + cd xfluencer + + - name: Remove Github Actions IP from security group + if: always() + run: | + aws ec2 revoke-security-group-ingress --group-id ${{ env.AWS_SG_NAME }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }}