Skip to content

Commit 600dafa

Browse files
committed
Move blue/green to a new page
1 parent 5f4729b commit 600dafa

File tree

2 files changed

+1
-102
lines changed

2 files changed

+1
-102
lines changed

docs/deploying.md

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -72,105 +72,3 @@ docker compose pull
7272
docker compose up -d
7373
docker compose exec postgres migrate
7474
```
75-
76-
## Blue/Green Deployments
77-
78-
This is a deployment method where two complete stacks are running side-by-side.
79-
One is serving production traffic, while the other is idle. You deploy to the
80-
idle stack, test it, and when you’re ready you swap roles — the idle stack
81-
becomes production instantly, and the old production becomes idle. This
82-
provides near-zero downtime and an easy rollback path.
83-
84-
We’ll bring up two stacks, `blue` and `green`, with no ports exposed. A
85-
separate lightweight front proxy binds to `:80` and `:443` and routes traffic
86-
to whichever stack is active.
87-
88-
### 1. Caddyfile
89-
90-
Remove the exposed ports from the Caddy service. Also set `CADDY_SITE_ADDRESS`
91-
to only `:80` (leaving TLS termination to the front proxy):
92-
93-
```yaml title="compose.yaml"
94-
caddy:
95-
environment:
96-
CADDY_SITE_ADDRESS: :80
97-
```
98-
99-
To share data between the two stacks (database, uploads, etc.), give volumes
100-
explicit names:
101-
102-
```yaml title="compose.yaml"
103-
volumes:
104-
postgres_data:
105-
name: postgres-data
106-
user_data:
107-
name: user-data
108-
```
109-
110-
### 2. Start two Stacks
111-
112-
On the server, bring up two stacks, `blue` and `green`:
113-
114-
```sh
115-
docker compose -p blue up -d
116-
docker compose -p green up -d
117-
```
118-
119-
### 3. Front Proxy
120-
121-
The front proxy is a single Caddy container that binds `:80` and `:443` on the
122-
server and routes requests into either the Blue or Green stack.
123-
124-
On the server, create a simple `Caddyfile`:
125-
126-
```caddyfile title="Caddyfile"
127-
api.myapp.com reverse_proxy blue_caddy:80
128-
129-
# Optionally point a second hostname to the idle stack for testing
130-
next.myapp.com reverse_proxy blue_caddy:80
131-
```
132-
133-
The front proxy manages TLS, so give it a persistent volume for certificates:
134-
135-
```sh
136-
docker volume create caddy_data
137-
```
138-
139-
Start the proxy and attach it to both networks:
140-
141-
```sh
142-
docker run -d \
143-
--name front-proxy \
144-
-p 80:80 -p 443:443 \
145-
-v ./Caddyfile:/etc/caddy/Caddyfile \
146-
-v caddy_data:/data \
147-
--network blue_default \
148-
--network green_default \
149-
caddy:2
150-
```
151-
152-
### 4. Deploying
153-
154-
Update the idle stack:
155-
156-
```sh
157-
docker compose pull
158-
docker compose -p green up -d
159-
```
160-
161-
Edit the front proxy's config to flip traffic:
162-
163-
```caddyfile title="Caddyfile"
164-
api.myapp.com reverse_proxy green_caddy:80
165-
next.myapp.com reverse_proxy blue_caddy:80
166-
```
167-
168-
Restart Caddy:
169-
170-
```sh
171-
docker exec front-proxy caddy reload
172-
```
173-
174-
Cutover is instant. Green is now live, and Blue is the idle stack.
175-
176-
And rollback is simple: flip the `Caddyfile` back and `caddy reload`.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ nav:
5252
- Postgres Extensions: extensions.md
5353
- Psql: psql.md
5454
- Deploying to Remote Environments: deploying.md
55+
- Blue/Green Deployments: bluegreen.md
5556
- Upgrading SuperStack: upgrading.md

0 commit comments

Comments
 (0)