I was told that they easy way out is to have two production branches, master/blue and master/green, git merge action triggers CI to deploy to the matching stacks. Is that possible to do it with single master branch?
Some more details about our stacks.
- CloudFront, origin set to S3 bucket which serves all the front-end SPA (single page app) static assets.
- SPA app talks to AWS API Gateway, which connects AWS Lambda.
- AWS Lambda is responsible for db CRUD operations with DynamoDB.
- Front-end app and Lambda function each has their own Git repo, Git master branch merge action triggers 2 Circle CI jobs, one copy front-end assets to S3 bucket, the other deploys Lambda with serverless framework.
For blue-green deploy, I'm thinking to have 2 instances of S3, API gateway and Lambda function. To make the blue-green switch, we'll need to change origin from one S3 bucket to another, then create invalidations to clear the cache.
To make the single production git branch blue-green deployment to work, Circle CI needs to know is the current active stack is blue or green, copy & paste / deploy to the other stack, if Circle CI is not able to do that, the alternative that I could think of is to somehow put the checkout_current_active_stack action in the git precommit hook? To be specific:
- (in the git precommit hook) send out a HTTP request to the current active stack API (AWS lambda function, which keep track of the current stack information)
- deploy base on the return value ('blue' or 'green')