Release 2024-08-08 #59
Workflow file for this run
This file contains 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: Create release | |
on: | |
push: | |
tags: | |
- release-* | |
env: | |
ECR_REPOSITORY: appq-register-page | |
DEPLOY_PROD_BUCKET: tryber-production-source | |
DEPLOY_PROD_KEY: tryber-react-production-pipeline/source.zip | |
ASG_NAME: tryber-asg-tryber-react-production | |
PIPELINE: tryber-react-production-pipeline-pipeline | |
DEPLOY_PREPROD_BUCKET: tryber-preproduction-source | |
DEPLOY_PREPROD_KEY: tryber-react-preproduction-pipeline/source.zip | |
PREPROD_ASG_NAME: tryber-asg-tryber-react-preproduction | |
PREPROD_PIPELINE: tryber-react-preproduction-pipeline-pipeline | |
jobs: | |
push-to-ecr: | |
name: Push Image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Get tag name | |
shell: bash | |
run: | | |
TAG=${GITHUB_REF##*/} | |
echo "##[set-output name=tag;]$TAG" | |
echo "##[set-output name=ECR_REPOSITORY;]$ECR_REPOSITORY" | |
id: extract_tag | |
- 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_ACCESS_KEY }} | |
aws-region: eu-west-1 | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build, tag, and push image to Amazon ECR | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ env.ECR_REPOSITORY }} | |
IMAGE_TAG: ${{ steps.extract_tag.outputs.tag }} | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
run: | | |
DOCKER_BUILDKIT=1 docker build \ | |
--build-arg NPM_TOKEN=$NPM_TOKEN \ | |
--build-arg SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }} \ | |
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
release-to-preprod: | |
name: Release to PreProd | |
needs: push-to-ecr | |
runs-on: ubuntu-latest | |
environment: preproduction | |
outputs: | |
original_preprod_desired: ${{ steps.update-asg.outputs.original_desired }} | |
original_preprod_max: ${{ steps.update-asg.outputs.original_max }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Get tag name | |
shell: bash | |
run: | | |
TAG=${GITHUB_REF##*/} | |
echo "##[set-output name=tag;]$TAG" | |
echo "##[set-output name=ECR_REPOSITORY;]$ECR_REPOSITORY" | |
echo "##[set-output name=DEPLOY_PREPROD_BUCKET;]$DEPLOY_PREPROD_BUCKET" | |
echo "##[set-output name=DEPLOY_PREPROD_KEY;]$DEPLOY_PREPROD_KEY" | |
echo "##[set-output name=PREPROD_ASG_NAME;]$PREPROD_ASG_NAME" | |
echo "##[set-output name=PREPROD_PIPELINE;]$PREPROD_PIPELINE" | |
id: extract_tag | |
- name: "Generate dist zip" | |
run: | | |
cd deployment | |
echo -n "${ECR_REPOSITORY}:${{steps.extract_tag.outputs.tag}}" > docker-image.txt | |
zip dist.zip * | |
- uses: zdurham/s3-upload-github-action@master | |
env: | |
S3_BUCKET: ${{ steps.extract_tag.outputs.DEPLOY_PREPROD_BUCKET }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: "eu-west-1" | |
FILE: ./deployment/dist.zip | |
S3_KEY: ${{ steps.extract_tag.outputs.DEPLOY_PREPROD_KEY }} | |
- name: configure AWS creds | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: eu-west-1 | |
- name: Update asg capacity to 1 | |
uses: AppQuality/update-desired-asg-instances@v1.0.0 | |
id: update-asg | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: "eu-west-1" | |
ASG_NAME: ${{ steps.extract_tag.outputs.PREPROD_ASG_NAME }} | |
DESIRED_INSTANCES: 1 | |
MAX_INSTANCES: 1 | |
- name: Start CodePipeline | |
uses: moia-oss/aws-codepipeline-trigger@v1 | |
with: | |
pipeline: ${{ steps.extract_tag.outputs.PREPROD_PIPELINE }} | |
wait: true | |
prepare-release-for-prod: | |
name: Prepare release to Prod | |
needs: push-to-ecr | |
runs-on: ubuntu-latest | |
environment: production | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Get tag name | |
shell: bash | |
run: | | |
TAG=${GITHUB_REF##*/} | |
echo "##[set-output name=tag;]$TAG" | |
echo "##[set-output name=ECR_REPOSITORY;]$ECR_REPOSITORY" | |
echo "##[set-output name=DEPLOY_BUCKET;]$DEPLOY_BUCKET" | |
echo "##[set-output name=DEPLOY_PROD_BUCKET;]$DEPLOY_PROD_BUCKET" | |
echo "##[set-output name=DEPLOY_PROD_KEY;]$DEPLOY_PROD_KEY" | |
echo "##[set-output name=ASG_NAME;]$ASG_NAME" | |
echo "##[set-output name=PIPELINE;]$PIPELINE" | |
id: extract_tag | |
- name: "Generate dist zip" | |
run: | | |
cd deployment | |
echo -n "${{ steps.extract_tag.outputs.ECR_REPOSITORY }}:${{steps.extract_tag.outputs.tag}}" > docker-image.txt | |
zip dist.zip * | |
- uses: zdurham/s3-upload-github-action@master | |
env: | |
S3_BUCKET: ${{ steps.extract_tag.outputs.DEPLOY_PROD_BUCKET }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: "eu-west-1" | |
FILE: ./deployment/dist.zip | |
S3_KEY: ${{ steps.extract_tag.outputs.DEPLOY_PROD_KEY }} | |
- name: configure AWS creds | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: eu-west-1 | |
- name: Update asg capacity to 2 | |
uses: AppQuality/update-desired-asg-instances@v1.0.0 | |
id: update-asg | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: "eu-west-1" | |
ASG_NAME: ${{ steps.extract_tag.outputs.ASG_NAME }} | |
DESIRED_INSTANCES: 2 | |
MAX_INSTANCES: 2 | |
- name: Start CodePipeline | |
uses: moia-oss/aws-codepipeline-trigger@v1 | |
with: | |
pipeline: ${{ steps.extract_tag.outputs.PIPELINE }} | |
wait: true | |
- name: Restore asg capacity | |
uses: AppQuality/update-desired-asg-instances@v1.0.0 | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: "eu-west-1" | |
ASG_NAME: ${{ steps.extract_tag.outputs.ASG_NAME }} | |
DESIRED_INSTANCES: ${{ steps.update-asg.outputs.original_desired }} | |
MAX_INSTANCES: ${{ steps.update-asg.outputs.original_max }} | |
- name: Get deployment url | |
uses: AppQuality/get-codeploy-from-codepipeline@1.0.0 | |
id: codedeploy | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: "eu-west-1" | |
PIPELINE_NAME: ${{ steps.extract_tag.outputs.PIPELINE }} | |
- name: Update release with deployment url | |
uses: tubone24/update_release@v1.0 | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
with: | |
body: "[![](https://img.shields.io/badge/AWS-Redeploy-blueviolet)](${{ steps.codedeploy.outputs.codedeploy_url }})" | |
isAppendBody: true | |
disable-preprod-on-release: | |
name: Disable PreProd | |
needs: [prepare-release-for-prod, release-to-preprod] | |
runs-on: ubuntu-latest | |
environment: preproduction | |
steps: | |
- name: Restore asg capacity | |
uses: AppQuality/update-desired-asg-instances@v1.0.0 | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: "eu-west-1" | |
ASG_NAME: ${{ env.PREPROD_ASG_NAME }} | |
DESIRED_INSTANCES: ${{needs.release-to-preprod.outputs.original_preprod_desired }} | |
MAX_INSTANCES: ${{needs.release-to-preprod.outputs.original_preprod_max }} |