@@ -2,12 +2,12 @@ Blue/Green deployment runs two stacks side-by-side: one live, one idle. You
22deploy to the idle stack, test it, and when ready, swap roles — giving
33near-zero downtime and easy rollback.
44
5- ![ Blue/Green] ( ../ assets/bluegreen.png)
5+ ![ Blue/Green] ( assets/bluegreen.png )
66
7- ## 1. Adjustments to the Compose file
7+ ## 1. Adjust the Compose file
88
9- Remove the exposed ports by removing the Caddy ` ports: ` section in
10- ` compose.yaml ` .
9+ Remove the Caddy ` ports: ` section in ` compose.yaml ` . Instead of exposing ports
10+ in the stacks, a "front proxy" will expose ports and proxy to the active stack .
1111
1212Set ` CADDY_SITE_ADDRESS ` to only ` :80 ` (leaving TLS termination to the front
1313proxy):
@@ -31,8 +31,8 @@ volumes:
3131
3232## 2. Add a Front Proxy
3333
34- The front proxy is a single container that binds ` : 80` and `: 443` on the server
35- and routes requests into either the Blue or Green stack.
34+ The _front proxy_ is a single container that binds ports ` 80` and `443` on the
35+ server and routes requests into either the Blue or Green stack.
3636
3737On the server, create a simple `Caddyfile` :
3838
@@ -73,16 +73,33 @@ docker run -d \
7373 caddy:2
7474` ` `
7575
76- # # 4 . Deploying
76+ # # 3 . Deploying/Upgrading
7777
78- Update the idle stack :
78+ Deploying is the same as [before](deploying.md), but now we're deploying the
79+ _idle stack_. For this example, `green` is idle so that's the one we're
80+ deploying.
81+
82+ Create `blue` and `green` directories on the server and deploy `compose.yaml`
83+ into the idle stack's directory :
7984
8085` ` ` sh
86+ scp compose.yaml youruser@yourserver:green/compose.yaml
87+ ` ` `
88+
89+ Shell into the server and bring up the idle stack :
90+
91+ ` ` ` sh
92+ cd green
8193docker compose pull
82- docker compose -p green up -d
94+ docker compose up -d
8395` ` `
8496
85- Edit the front proxy's config to flip traffic :
97+ Docker will use the directory name `green` as the project name, creating
98+ different containers, volumes and networks than the `blue` stack.
99+
100+ # ## Flip traffic
101+
102+ Point traffic to the `green` stack, and make `blue` idle :
86103
87104` ` ` caddyfile title="Caddyfile"
88105api.myapp.com {
@@ -94,12 +111,12 @@ next.myapp.com {
94111}
95112` ` `
96113
97- Restart Caddy :
114+ Reload the front proxy's config :
98115
99116` ` ` sh
100117docker exec front-proxy caddy reload
101118` ` `
102119
103120Cutover is instant. Green is now live, and Blue is the idle stack.
104121
105- And rollback is simple : flip the `Caddyfile` back and `caddy reload`.
122+ And rollback is simple : flip the `Caddyfile` back and `caddy reload` again .
0 commit comments