Skip to content

Git tag-based deployment using AWS ECR and Elastic Beanstalk

License

Notifications You must be signed in to change notification settings

sealink/ci-deploy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deployment Scripts for CI

This project centralises the deployment scripts used by all the projects that use ECR, ECS and Elastic Beanstalk.

We use https://semaphoreci.com/ although it can work with other CI as long as the required environment variables are set and aws is authenticated.

  1. Check if the commit is tagged for release.
  2. If the Docker image doesn't exist in ECR, build it and push it.
  3. For Elastic Beanstalk:
    1. If the application version doesn't exist in Elastic Beanstalk, create it.
    2. Finally trigger the Elastic Beanstalk deployment.
  4. For ECS:
    1. Create the task revision.
    2. Update the service with the revision.
  5. If the tag name starts with base-, the image will be built and pushed but not deployed.

Experimental blue/green EB deployment automation

This is experimental because Elastic Beanstalk is unstable when this option is enabled.

The additional logic is as follows.

  1. Before deployment, clone the Elastic Beanstalk environment.
  2. Swap the URLs before the original environment and the cloned environment.
  3. Deploy to the original environment with the AllAtOnce option.
  4. Swap back the URL.
  5. Terminate the cloned environment.

Environment variables

Required variables:

AWS_ACCESS_KEY_ID=aws-access-key-id
AWS_SECRET_ACCESS_KEY=aws-secret-access-key
AWS_DEFAULT_REGION=ap-southeast-2

APP_ECR_IMAGE=dkr.ecr.ap-southeast-2.amazonaws.com/my-application
APP_ECR_REGION=ap-southeast-2

# These 2 are required if you have "base-*" tags, see above.
BASE_ECR_IMAGE=dkr.ecr.ap-southeast-2.amazonaws.com/my-application-base
BASE_ECR_REGION=ap-southeast-2

CI_DEPLOY_TYPE= # Either eb or ecs

If you're using Elastic Beanstalk:

EB_APP_NAME=MyApplication
EB_ENV_NAME=my-application

If you're using the automated blue/green deployment:

ENABLE_BLUE_GREEN_DEPLOY=1

If you're using ECS:

ECS_CLUSTER=production
ECS_FAMILY=my-application
ECS_SERVICE=my-application

If you're using Rollbar:

ROLLBAR_ACCESS_TOKEN=myPostToken

The following Semaphore environment variables are also used for rollbar

REVISION
SEMAPHORE_SERVER_NAME
DEPLOY_AUTHOR_NAME

If you're using Pact:

PACT_BROKER_URL=https://pact-broker.travellink.com.au
PACT_PARTICIPANT=Quicktravel
STAGE=next

Optional variables

You may override these if you know what you're doing.

SEMAPHORE_PROJECT_DIR=/home/runner/my-application
TAG=0.1.0
JQ_PATH=/usr/bin/jq
EB_WORKER_ENV_NAME=my-application-worker
CLONE_EB_ENV_NAME_SUFFIX=-clone