-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate CI pipeline to github actions (#3120)
* feat: github actions CI * chore: do not use 3rd party github action * chore: no need pip * feat: dynamically configure environment * chore: update aws region env * chore: combine build and deploy * chore: add docker build file flag * chore: add docker tag * chore: docker push tag * chore: docker push all tags * fix: github run id variable name * feat: copy to s3 bucket, configure sentry * nit: indent * chore: use image_tag for eb version-label * chore: rename DEPLOY_ENV * chore: remove environment-specific naming * chore: remove app version step * chore: delete travis ci * chore: update docs * chore: correct tag variable for sentry * chore: drop sentry from CD * chore: split create app version and update eb steps * feat: add retry if deployment to eb fails * feat: add run attempt to image tag * chore: remove auto retry
- Loading branch information
Showing
5 changed files
with
104 additions
and
149 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
name: Deploy to AWS Elastic Beanstalk | ||
on: | ||
push: | ||
branches: # There should be 4 environments in github actions secrets: release, staging, staging-alt, uat. This is different from the DEPLOY_ENV secret which corresponds to elastic beanstalk environment name | ||
- release | ||
- staging | ||
- staging-alt | ||
- uat | ||
|
||
jobs: | ||
set_environment: | ||
outputs: | ||
current_env: ${{ steps.set-environment.outputs.current_env }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- id: set-environment | ||
run: echo "::set-output name=current_env::${{github.ref_name}}" | ||
|
||
build_deploy_application: | ||
needs: set_environment | ||
environment: | ||
name: ${{ needs.set_environment.outputs.current_env }} | ||
env: | ||
IMAGE_TAG: github-actions-${{ github.sha }}-${{ github.run_id }}-${{github.run_attempt}} | ||
BRANCH: ${{ needs.set_environment.outputs.current_env }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: '14' | ||
cache: 'npm' | ||
- name: Build | ||
env: | ||
NODE_OPTIONS: '--max-old-space-size=4096' | ||
run: | | ||
npm ci | ||
set -e | ||
npm_config_mode=yes npx lockfile-lint --type npm --path package.json --validate-https --allowed-hosts npm | ||
npm run lint-ci | ||
npm run build | ||
- 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: ${{ secrets.AWS_DEFAULT_REGION }} | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: Build, tag, and push image to Amazon ECR | ||
env: | ||
ECR_REPOSITORY: ${{ secrets.ECR_REPO }} | ||
run: | | ||
docker build -f Dockerfile.production -t $ECR_REPOSITORY:$IMAGE_TAG . | ||
docker tag $ECR_REPOSITORY:$IMAGE_TAG $ECR_REPOSITORY:$BRANCH | ||
docker push -a $ECR_REPOSITORY | ||
sed -i -e "s/@TAG/$IMAGE_TAG/g" Dockerrun.aws.json | ||
zip -r "$IMAGE_TAG.zip" .ebextensions Dockerrun.aws.json | ||
- name: Copy to S3 | ||
env: | ||
BUCKET_NAME: ${{ secrets.BUCKET_NAME }} | ||
run: | | ||
aws s3 cp $IMAGE_TAG.zip s3://$BUCKET_NAME/$IMAGE_TAG.zip | ||
- name: Create application version | ||
env: | ||
BUCKET_NAME: ${{ secrets.BUCKET_NAME }} | ||
APP_NAME: ${{ secrets.APP_NAME }} | ||
run: | | ||
aws elasticbeanstalk create-application-version --application-name $APP_NAME \ | ||
--version-label $IMAGE_TAG \ | ||
--source-bundle S3Bucket=$BUCKET_NAME,S3Key=$IMAGE_TAG.zip \ | ||
--description "${{ github.event.head_commit.message }}" | ||
- name: Update EB environment | ||
id: update-eb-1 | ||
env: | ||
APP_NAME: ${{ secrets.APP_NAME }} | ||
DEPLOY_ENV: ${{ secrets.DEPLOY_ENV }} | ||
run: | | ||
aws elasticbeanstalk update-environment --application-name $APP_NAME \ | ||
--environment-name $DEPLOY_ENV \ | ||
--version-label $IMAGE_TAG |
This file was deleted.
Oops, something went wrong.
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
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