Blue Green Deployments
See original GitHub issueAfter some workshops within the team and with some customer feedback we have the following proposal and are seeking feedback from the Lagoon community.
Summary
Lagoon will provide a Blue/Green Deployment system which allows Developers to switch all custom routes from one production environment to another production environment. This allows:
- 0-Downtime production deployments: Production environment can be deployed, post-rollout tasks ran and tested before actual customers are visiting the site.
- Fast rollbacks: Switch the routes back to the previous production environment
- Deployment aborts: never switch the routes to the new production environment
Changes in Lagoon
- Allow two Environments be of type
production
- New GraphQL mutation for setting in production environment
active
while the other one isstandby
- this will also switching Custom Routes from the current active to the new active environment
- Switching the active production environment will do NOT trigger a redeploy of any environments
- New Drush Site alias with
production-active
andproduction-standby
(automatically filled with the real environments) - New
routes.production
key in.lagoon.yml
where custom routes can be defined for the production environment (only these will be switched by the new GraphQL Mutation)
Typical Blue-Green Deployment
Situation
- Two production environments already defined, in this example we call them
blue
green
, each of them is connected to a branch, also calledblue
andgreen
(same system as today, environment names = branch names) .lagoon.yml
contains routes:routes: insecure: Redirect active: - nginx: - www.example.com - www.example.net standby: - nginx: - standby.example.com - standby.example.net
.lagoon.yml
defined post-rollout tasks:post-rollout: - run: name: if this is production, sync from current active production environment command: | if [[ "$LAGOON_ENVIRONMENT_TYPE" == "production" ]]; then drush -y sql-sync @production-active @self drush -y rsync @production-active:%files @self:%files fi service: cli shell: bash - run: name: drush cim command: drush -y cim service: cli - run: name: drush updb command: drush -y updb service: cli - run: name: drush cr command: drush -y cr service: cli
- we assume that the environment
blue
was already deployed and is set as theactive
production environment
Deployment Workflow
- Developer pushes code update into
green
branch - Lagoon deploys the
green
environment Asgreen
environment is aLAGOON_ENVIRONMENT_TYPE=production
environment, drush will rundrush -y sql-sync @production-active @self
, whileproduction-active
is automatically set to theblue enviornment
. Therefore syncing the DB and Files fromblue
togreen
- After deployment finished, Developer tests the green deployment with accessing it via the automatically created routes like: varnish-myproject-green.us.amazee.io, also gives stakeholders possibility to test the site on these URLS (if needed also custom routes for green could be created, like green.example.com)
- Testing of green deployment is completed and approved
- Developer triggers a Production Environment switch via GraphQL API or Lagon UI
- Lagoon triggers:
6.1. Checks all defined routes with a specific annotation
routes.active
and moves them within Kubernets/OpenShift from theblue
namespace to thegreen
namespace 6.1. Checks all defined routes with a specific annotationroutes.standby
and moves them within Kubernets/OpenShift from thegreen
namespace to theblue
namespace 6.2. Lagoon switches internal environment status from:blue=active, green=standby
to:green=active, blue=standby
6.3. Lagoon informs Developer about successful switch
Rollback Scenario
This assumes that the deployment need to be switched back.
- Developer triggers another Production Environment switch:
- Lagoon Triggers:
3.1. Checks all defined routes under
routes.production
and moves them within Kubernets/OpenShift from theblue
namespace to thegreen
namespace 3.2. Lagoon switches internal environment status from:green=active, blue=standby
to:blue=active, green=standby
3.3. Lagoon informs Developer about successful switch
Next Deployment Workflow
Basically same procedure, but instead of pushing into green
environment/branch, developer pushes into blue
environment/branch
Additional ideas:
- Should we prevent Lagoon from deploying a change into the current active production environment? This could force the developers to always use the blue/green deployment system, but maybe could cause some issues if they want for example push a hotfix into the current active production environment without touching the standby environment
- Technically we could have multiple standby production environments, but this maybe makes it too complex to understand? Is there a use case to have multiple standby production environments?
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (12 by maintainers)
Top Results From Across the Web
What is blue green deployment? - Red Hat
Blue green deployment is an application release model that gradually transfers user traffic from a previous version of an app or microservice to...
Read more >Blue/Green Deployments - AWS Documentation
A blue/green deployment is a deployment strategy in which you create two separate, but identical environments. One environment (blue) is running the current ......
Read more >BlueGreenDeployment - Martin Fowler
The blue-green deployment approach does this by ensuring you have two production environments, as identical as possible. At any time one of them ......
Read more >Blue-green deployment - Wikipedia
In software engineering, blue-green (also blue/green) deployment is a method of installing changes to a web, app, or database server by swapping alternating ......
Read more >What Is Blue-Green Deployment? - Semaphore CI
Blue -green deployment is a release management technique that reduces risk and minimizes downtime. It uses two production environments, known as ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A few thoughts after reading this thread.
LAGOON_ENVIRONMENT_TYPE=production
sounds like a sensible idea. This way they are treated like both being production (e.g. monitoring, database location, etc)nginx-php
pod ofIS_ACTIVE_PRODUCTION
(or similar) would be extremely useful - it would also mandate a redeploy of Nginx to apply. This way (for instance) you could tie Shield being being enabled on the standby environment, and not enabled on the active environment. Integration with the environment indicator module would also be possible. This could be considered a security and editor UX issue.staging
andtest
are the 2 production environments.Correct, I’m suggesting no change to solution here, just the definition of the problem. Content deployment strategy (one type) is a by product of blue/green.