Merge pull request #1019 from AppQuality/develop #71
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: unguess-react | |
DEPLOY_PROD_BUCKET: unguess-app-production-source | |
DEPLOY_PROD_KEY: unguess-app-react-production-pipeline/source.zip | |
ASG_NAME: unguess-app-asg-unguess-app-react-production | |
PIPELINE: unguess-app-react-production-pipeline-pipeline | |
jobs: | |
push-to-ecr: | |
name: Push Image | |
environment: production | |
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@13d241b293754004c80624b5567555c4a39ffbe3 | |
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@aaf69d68aa3fb14c1d5a6be9ac61fe15b48453a2 | |
- name: Docker ECR | |
id: build-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ steps.extract_tag.outputs.ECR_REPOSITORY }} | |
IMAGE_TAG: ${{ steps.extract_tag.outputs.tag }} | |
run: | | |
# Build a docker container and | |
# push it to ECR so that it can | |
# be deployed to ECS. | |
docker build \ | |
--build-arg STRAPI_TOKEN=${{ secrets.STRAPI_TOKEN }} \ | |
--build-arg SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }} \ | |
--build-arg STAGE_ENV="production" \ | |
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
release-to-prod: | |
name: Release to production | |
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 |