diff --git a/.github/workflows/alpha.yml b/.github/workflows/alpha.yml index 4062b23..3ecad8a 100644 --- a/.github/workflows/alpha.yml +++ b/.github/workflows/alpha.yml @@ -52,6 +52,30 @@ jobs: needs: push_to_registry 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=ap-northeast-2" >> $GITHUB_ENV + echo "AWS_SG_NAME=launch-wizard-2" >> $GITHUB_ENV + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} + aws-region: ap-northeast-2 + + - name: Add Github Actions IP to Security group + run: | + aws ec2 authorize-security-group-ingress --group-name ${{ 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_KEY }} + AWS_DEFAULT_REGION: ap-northeast-2 + - name: Deploy to prod if: contains(github.ref, 'develop') uses: appleboy/ssh-action@master @@ -68,3 +92,11 @@ jobs: if docker images -f "dangling=true" -q | grep . > /dev/null; then docker rmi $(docker images -f "dangling=true" -q) fi + + - name: Remove Github Actions IP from security group + run: | + aws ec2 revoke-security-group-ingress --group-name ${{ 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_KEY }} + AWS_DEFAULT_REGION: ap-northeast-2