Merge pull request #12 from kodustech/fix/add-stripe-customer-id #34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI/CD kodus-service-billing QA | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build_and_push_image: | |
| name: Build and push image | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4.1.1 | |
| # see: https://github.com/aws-actions/configure-aws-credentials | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v4.0.1 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: us-east-1 | |
| - name: Login to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v2.0.1 | |
| - name: Build, tag, and push image to Amazon ECR | |
| env: | |
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
| ECR_REPOSITORY: kodus-service-billing-qa | |
| IMAGE_TAG: ${{ github.sha }} | |
| run: | | |
| docker build -f DockerFiles/Dockerfile.qa -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
| - name: Log out of Amazon ECR | |
| if: always() | |
| run: docker logout ${{ steps.login-ecr.outputs.registry }} | |
| deploy_in_server: | |
| name: Deploy in server | |
| runs-on: ubuntu-latest | |
| needs: build_and_push_image | |
| steps: | |
| - name: Get runner IP | |
| run: | | |
| ip=`curl https://ipinfo.io/ip` | |
| echo $ip | |
| echo "runner_ip=$ip" >> $GITHUB_ENV | |
| - name: Add Github Actions IP to Security group as a Postgres inbound rule | |
| run: | | |
| aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SECURITY_GROUP }} --protocol tcp --port 22 --cidr ${{ env.runner_ip }}/32 | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }} | |
| - name: Execute start-app.sh on EC2 | |
| uses: appleboy/ssh-action@v1.0.0 | |
| with: | |
| host: ${{ secrets.AWS_QA_HOST }} | |
| username: ${{ secrets.AWS_QA_USERNAME }} | |
| key: ${{ secrets.AWS_QA_KEY_SSH }} | |
| script: | | |
| cd ~/kodus-service-billing | |
| ./start-app.sh qa ${{ github.sha }} ${{ github.ref }} | |
| - name: Remove Github Actions IP from security group | |
| run: | | |
| aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SECURITY_GROUP }} --protocol tcp --port 22 --cidr ${{ env.runner_ip }}/32 | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }} | |
| if: always() | |
| - name: Actions for Discord | |
| uses: sarisia/actions-status-discord@v1.13.0 | |
| with: | |
| webhook: ${{ secrets.DISCORD_WEBHOOK }} | |
| status: ${{ job.status }} | |
| content: ":clap: Build successful!" | |
| title: "Deploy QA: kodus-service-billing" | |
| username: GitHub Actions |