Skip to content

Commit 2110f17

Browse files
committed
2 parents a319719 + bf22d07 commit 2110f17

File tree

2 files changed

+43
-34
lines changed

2 files changed

+43
-34
lines changed

docs/assets/extra.css

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@
3838
}
3939

4040
/* Change header fonts */
41-
h1, h2, h3, h4, h5, h6 {
41+
h1,
42+
h2,
43+
h3,
44+
h4,
45+
h5,
46+
h6 {
4247
font-weight: 700;
4348
font-style: normal;
4449
letter-spacing: -0.5px;
@@ -59,13 +64,17 @@
5964
font-size: 0.9rem;
6065
}
6166

62-
p, ul, ol, pre {
67+
p,
68+
ul,
69+
ol,
70+
pre {
6371
font-size: 17px;
6472
margin-top: 1em;
6573
margin-bottom: 1em;
6674
}
6775

68-
ul, ol {
76+
ul,
77+
ol {
6978
margin-left: 3rem;
7079
padding-left: 3rem;
7180
}
@@ -103,4 +112,3 @@
103112
article {
104113
padding-bottom: 3rem;
105114
}
106-

docs/bluegreen.md

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,50 @@ near-zero downtime and easy rollback.
44

55
![Blue/Green](assets/bluegreen.png)
66

7-
## Network
7+
## 1. Create a Docker Network
88

9-
We'll have a few concerns:
9+
Blue/Green adds some complexity because where before there was just "the
10+
stack", now you have:
1011

11-
1. A blue stack
12-
2. A green stack
13-
3. A front proxy
14-
4. Postgres
12+
1. A `blue` stack
13+
2. A `green` stack
14+
3. A front proxy to direct traffic
15+
4. An external Postgres.
1516

1617
Create a network to link them:
1718

1819
```sh
19-
docker network create myapp
20+
docker network create app
2021
```
2122

2223
And add it to the Compose file:
2324

2425
```yaml title="compose.yaml"
2526
networks:
2627
default:
27-
name: myapp
28+
name: app
2829
external: true
2930
```
3031
31-
## 1. Adjust the Compose file
32+
## 2. Adjust Caddy
3233
33-
### Remove exposed ports
34+
### Name the Caddy containers
35+
36+
Naming the Caddy containers `blue_caddy` and `green_caddy` allows the front
37+
proxy to direct traffic to the correct stacks:
38+
39+
```yaml title="compose.yaml"
40+
caddy:
41+
container_name: ${STACK_NAME}_caddy
42+
```
3443

35-
Remove the `caddy` service's `ports:` section in `compose.yaml`.
44+
### Remove exposed ports
3645

37-
We'll no longer expose ports in the stacks, instead the front proxy will sit in
46+
We'll no longer expose ports in the stacks, instead a front proxy will sit in
3847
front of the two stacks, proxying to them.
3948

49+
So remove the `caddy` service's `ports:` section in `compose.yaml`.
50+
4051
### Serve HTTP-only in the stacks
4152

4253
Set `CADDY_SITE_ADDRESS` to only `:80`, removing `:443` (leaving TLS
@@ -48,24 +59,14 @@ caddy:
4859
CADDY_SITE_ADDRESS: :80
4960
```
5061

51-
### Set the Caddy container name explicitly
52-
53-
This allows us to switch between the two stacks:
54-
55-
```yaml title="compose.yaml"
56-
caddy:
57-
container_name: ${STACK_NAME}_caddy
58-
```
59-
60-
### Move Postgres to its own unique container
62+
## 2. Postgres
6163

62-
Running two separate PostgreSQL instances and having them both simultaneously
63-
access the same data directory within that shared volume is not recommended and
64-
can lead to data corruption.
64+
It's not advised to run two separate PostgreSQL instances and having them both simultaneously
65+
access the same shared volume.
6566

6667
So we need to move Postgres out of the compose file and start it separately.
6768

68-
### Share volumes between the stacks
69+
## 3. Volumes
6970

7071
To share data between the two stacks (uploads, etc.), give volumes explicit
7172
names:
@@ -76,7 +77,7 @@ volumes:
7677
name: user-data
7778
```
7879

79-
## 3. Bring up two Stacks
80+
## 4. Bring up two Stacks
8081

8182
Deploying is the same as [before](deploying.md), but now we're deploying the
8283
_idle stack_. For this example, `green` is idle so that's the one we're
@@ -94,13 +95,13 @@ Shell into the server and bring up the idle stack:
9495
```sh
9596
cd green
9697
docker compose pull
97-
docker compose up -d
98+
STACK_NAME=green docker compose up -d
9899
```
99100

100101
Docker will use the directory name `green` as the project name, creating
101102
different containers, volumes and networks than the `blue` stack.
102103

103-
## 3. Add a Front Proxy
104+
## 5. Add a Front Proxy
104105

105106
The _front proxy_ is a single container that binds ports `80` and `443` on the
106107
server and routes requests into either the Blue or Green stack.
@@ -135,7 +136,7 @@ docker run -d \
135136
caddy:2
136137
```
137138

138-
## 4. Upgrading
139+
## 6. Upgrading
139140

140141
## Flip traffic
141142

0 commit comments

Comments
 (0)