name: Deploy on: push: branches: - alpha - beta - main jobs: deploy: runs-on: self-hosted steps: - name: Checkout uses: actions/checkout@v2 # Because Semantic Realese deleted the .npmrc file, it was necessary to insert two steps to backup the file. - name: BKP .npmrc Step 1 run: | cp .npmrc .npmrcbkp - name: Semantic Release uses: cycjimmy/semantic-release-action@v2 id: semantic with: semantic_version: 16 extra_plugins: | @saithodev/semantic-release-backmerge conventional-changelog-eslint branches: | [ 'main', { name: 'alpha', prerelease: true }, { name: 'beta', prerelease: true } ] env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} # Because Semantic Realese deleted the .npmrc file, it was necessary to insert two steps to backup the file. - name: BKP .npmrc Step 2 run: | cp .npmrcbkp .npmrc - name: Update Pip if: steps.semantic.outputs.new_release_published == 'true' run: | python3 -m pip install --upgrade pip - name: Install Docker Compose if: steps.semantic.outputs.new_release_published == 'true' run: | python3 -m pip install docker-compose --upgrade - name: Install AWS CLI if: steps.semantic.outputs.new_release_published == 'true' run: | python3 -m pip install awscli --upgrade - name: Install AWS Elastic Beanstalk CLI if: steps.semantic.outputs.new_release_published == 'true' run: | python3 -m pip install awsebcli --upgrade - name: Configure AWS Region if: steps.semantic.outputs.new_release_published == 'true' uses: aws-actions/configure-aws-credentials@v1 with: aws-region: us-east-1 - name: Extract Environment if: steps.semantic.outputs.new_release_published == 'true' shell: bash run: | if [ ${GITHUB_REF} == "refs/heads/main" ]; then echo "##[set-output name=result;]$(echo "prd")" elif [ ${GITHUB_REF} == "refs/heads/alpha" ]; then echo "##[set-output name=result;]$(echo "alpha")" elif [ ${GITHUB_REF} == "refs/heads/beta" ]; then echo "##[set-output name=result;]$(echo "stg")" fi id: extract_environment - name: Login to AWS ECR if: steps.semantic.outputs.new_release_published == 'true' id: login_ecr uses: aws-actions/amazon-ecr-login@v1 - name: Build, Tag, and Push Image to AWS ECR if: steps.semantic.outputs.new_release_published == 'true' env: ENV: ${{ steps.extract_environment.outputs.result }} IMAGE_TAG: ${{ steps.semantic.outputs.new_release_version }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} run: | docker-compose -f build.docker-compose.yml build --build-arg NPM_TOKEN=${NPM_TOKEN} docker-compose -f build.docker-compose.yml push - name: Create ZIP file to Deploy AWS Beanstalk if: steps.semantic.outputs.new_release_published == 'true' env: ENV: ${{ steps.extract_environment.outputs.result }} IMAGE_TAG: ${{ steps.semantic.outputs.new_release_version }} run: | sed -i -e "s/\${ENV}/$ENV/g" docker-compose.yml sed -i -e "s/\${IMAGE_TAG}/$IMAGE_TAG/g" docker-compose.yml zip deploy.zip docker-compose.yml -r .ebextensions - name: Deploy AWS Beanstalk if: steps.semantic.outputs.new_release_published == 'true' env: ENV: ${{ steps.extract_environment.outputs.result }} AWS_REGION: us-east-1 APP_NAME: maestro run: | eb use $APP_NAME-$ENV eb deploy - name: Remove Docker's Trash continue-on-error: true run: | docker system prune docker rmi -f $(docker images -aq)