Skip to content

Commit df476bc

Browse files
committed
Blue green deployment insight
1 parent f1e6203 commit df476bc

File tree

4 files changed

+112
-2
lines changed

4 files changed

+112
-2
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ This is a **Github Flow** boilerplate project using **Quarkus** GraalVM native i
99
- [Integration Tests](#integration-tests)
1010
- [Sonar](#sonar)
1111
- [Wrapping up developer responsabilities](#wrapping-up-developer-responsabilities)
12-
- [Heroku DEV environment](#heroku-dev-environment)
12+
- [Heroku DEV environment](#heroku-dev-environment)
1313
- [Database](#database)
1414
- [Api docs](#api-docs)
1515
- [Quarkus](#quarkus)
1616
- [Running the application in dev mode](#running-the-application-in-dev-mode)
1717
- [Packaging and running the application](#packaging-and-running-the-application)
1818
- [Creating a native executable](#creating-a-native-executable)
19+
- [Continuous Deployment](#continuous-deployment)
20+
- [How to do this?](#how-to-do-this)
1921

2022
## CICD Workflows in place
2123
[Github Actions](https://github.com/features/actions) is the CICD tool for this project. Under the directory `.github/worflows` 4 workflows are defined:
@@ -80,7 +82,7 @@ Even though the dashboard will always represent the quality status of master, is
8082
- Make sure integration tests still work. Introduce some if needed.
8183
- Make sure the technial debt in Sonar is the same or better when your code is merged.
8284

83-
### Heroku DEV environment
85+
## Heroku DEV environment
8486
As mentioned before, `master.yml` pipeline will deploy to a DEV heroku environment every time new features are merged into master branch using a `push` mechanism.
8587

8688
A so called `Add-on` is already active in Heroku, making a `PostgreSQL` database hosted in AWS available through a connection string provided as `DATABASE_URL` environment variable.
@@ -126,3 +128,23 @@ Or, if you don't have GraalVM installed, you can run the native executable build
126128
You can then execute your native executable with: `./target/quarkus-github-flow-1.0.0-SNAPSHOT-runner`
127129

128130
If you want to learn more about building native executables, please consult https://quarkus.io/guides/building-native-image.
131+
132+
## Continuous Deployment
133+
So the whole project is fine and the DEV environment looks very comfy and so, BUT, what if a real production deployment completely automated is needed, with zero downtime and a serious strategy?
134+
135+
Well, that's the reason why I'm adding this section here.
136+
137+
A very convenient strategy is the so called [BlueGreenDeployment](https://martinfowler.com/bliki/BlueGreenDeployment.html).
138+
139+
For our scenario we will have two exact replicas of the production environment, blue and green (active and inactive). New deployments will be performed over the green (inactive) environment (where the router is not pointing to at the moment), and ensure with our integration and load tests from pipeline that the new deployment is working correctly. Then, the swap can be performed (router points now to green, becoming the active one).
140+
141+
![BlueGreenDeployment](https://raw.githubusercontent.com/javieraviles/quarkus-github-flow/master/assets/blue_green_deployments.png)
142+
143+
Both rollback and stability should be fine following this pattern.
144+
145+
### How to do this?
146+
Your PROD environments can be created at Heroku in the same way you did for DEV. Deployment can be automated editing the `tag.yaml` workflow including the same heroku deployment stages `master.yaml` is using but for the prod release. Afterwards, you should include also the postman integration tests and locust load tests to ensure environment stability.
147+
148+
Now the end clients will not call Heroku prod environments directly, but using the **router** url. This router can be implemented using NGINX web server. Both the configuration and the swap script NGINX would use can be found at `bluegreendeployment` directory.
149+
150+
This is a very brief description to just give an insight of how this could be done, but don't hesitate to read further or contact me for more details about this specific approach.

assets/blue_green_deployments.png

48.8 KB
Loading

bluegreendeployment/nginx.config

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
##################################################################
2+
# Public URL p2cd.com. The green Nginx configuration will redirect
3+
# all calls to p2cd.com/api/ to the green app on Heroku and all
4+
# calls to p2cd.com/api-test/ to the blue app on Heroku.
5+
##################################################################
6+
7+
8+
################################################################
9+
# This would be a separate file nginx.conf within blue directory
10+
################################################################
11+
http {
12+
include mime.types;
13+
default_type application/octet-stream;
14+
sendfile on;
15+
keepalive_timeout 65;
16+
17+
server {
18+
listen 80;
19+
server_name p2cd.com;
20+
21+
location /api {
22+
proxy_pass https://heroku-blue.com/api;
23+
}
24+
25+
location /api-test {
26+
proxy_pass https://heroku-green.com/api;
27+
}
28+
}
29+
include servers/*;
30+
}
31+
32+
33+
#################################################################
34+
# This would be a separate file nginx.conf within green directory
35+
#################################################################
36+
http {
37+
include mime.types;
38+
default_type application/octet-stream;
39+
sendfile on;
40+
keepalive_timeout 65;
41+
42+
server {
43+
listen 80;
44+
server_name p2cd.com;
45+
46+
location /api {
47+
proxy_pass https://heroku-green.com/api;
48+
}
49+
50+
location /api-test {
51+
proxy_pass https://heroku-blue.com/api;
52+
}
53+
}
54+
include servers/*;
55+
}
56+
57+
##################################################
58+
# Folder structure at NGINX server should look something like
59+
##################################################
60+
--root
61+
|--- blue
62+
|--- nginx.conf.blue
63+
|--- green
64+
|--- nginx.conf.green
65+
|--- available -> ./green
66+
|--- inactive -> ./blue

bluegreendeployment/swap.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
inactive_now=$(ls -l ./ | grep inactive)
3+
if [[ "$inactive_now" == *blue ]]
4+
then
5+
inactive="blue"
6+
active="green"
7+
else
8+
inactive="green"
9+
active="blue"
10+
fi
11+
12+
#remove current links
13+
rm ./available
14+
rm ./inactive
15+
rm -f /etc/nginx/nginx.conf
16+
#create new links with the active/inactive reversed
17+
ln -s ./$inactive ./available
18+
ln -s ./$active ./inactive
19+
ln -s /home/ubuntu/p2cd/$active/nginx.conf /etc/nginx/nginx.conf
20+
#reload the http server
21+
service nginx reload
22+
echo swap completed $active is now available

0 commit comments

Comments
 (0)