Skip to content

Commit becadc0

Browse files
committed
Update bluegreen
1 parent 74355da commit becadc0

File tree

1 file changed

+37
-42
lines changed

1 file changed

+37
-42
lines changed

docs/bluegreen.md

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ near-zero downtime and easy rollback.
88

99
### Remove exposed ports
1010

11+
Remove the `caddy` service's `ports:` section in `compose.yaml`.
12+
1113
We'll no longer expose ports in the stacks, instead a simple "front proxy" will
12-
sit in front of the two stacks, exposing ports and proxying to the active
13-
stack. So remove the Caddy service's `ports:` section in `compose.yaml`.
14+
sit in front of the two stacks, proxying to the active stack.
1415

1516
### Set the Caddy container name explicitly
1617

@@ -45,14 +46,38 @@ volumes:
4546
name: user-data
4647
```
4748

49+
## 3. Bring up two Stacks
50+
51+
Deploying is the same as [before](deploying.md), but now we're deploying the
52+
_idle stack_. For this example, `green` is idle so that's the one we're
53+
deploying.
54+
55+
Create `blue` and `green` directories on the server and copy `compose.yaml`
56+
into the idle stack's directory:
57+
58+
```sh
59+
scp compose.yaml youruser@yourserver:green/compose.yaml
60+
```
61+
62+
Shell into the server and bring up the idle stack:
63+
64+
```sh
65+
cd green
66+
docker compose pull
67+
docker compose up -d
68+
```
69+
70+
Docker will use the directory name `green` as the project name, creating
71+
different containers, volumes and networks than the `blue` stack.
72+
4873
## 3. Add a Front Proxy
4974

5075
The _front proxy_ is a single container that binds ports `80` and `443` on the
5176
server and routes requests into either the Blue or Green stack.
5277

5378
On the server, create a simple `Caddyfile`:
5479

55-
```caddyfile title="Caddyfile"
80+
```caddyfile title="caddy/Caddyfile"
5681
api.myapp.com {
5782
reverse_proxy blue_caddy:80
5883
}
@@ -73,38 +98,16 @@ be up first, so the networks exist:
7398
docker run -d \
7499
--name front-proxy \
75100
-p 80:80 -p 443:443 \
76-
-v ./Caddyfile:/etc/caddy/Caddyfile \
101+
-v ./caddy:/etc/caddy \
77102
-v caddy_data:/data \
78103
--network blue_default \
79104
--network green_default \
80105
caddy:2
81106
```
82107

83-
## 4. Deploying/Upgrading
108+
## 4. Upgrading
84109

85-
Deploying is the same as [before](deploying.md), but now we're deploying the
86-
_idle stack_. For this example, `green` is idle so that's the one we're
87-
deploying.
88-
89-
Create `blue` and `green` directories on the server and copy `compose.yaml`
90-
into the idle stack's directory:
91-
92-
```sh
93-
scp compose.yaml youruser@yourserver:green/compose.yaml
94-
```
95-
96-
Shell into the server and bring up the idle stack:
97-
98-
```sh
99-
cd green
100-
docker compose pull
101-
docker compose up -d
102-
```
103-
104-
Docker will use the directory name `green` as the project name, creating
105-
different containers, volumes and networks than the `blue` stack.
106-
107-
### Flip traffic
110+
## Flip traffic
108111

109112
Point traffic to the `green` stack:
110113

@@ -132,7 +135,7 @@ Here's a workflow for B/G deploys:
132135
<summary>Click to expand</summary>
133136

134137
```yaml title=".github/workflows/ci.yaml"
135-
name: Deploy to VPS
138+
name: Deploy
136139
137140
on:
138141
push:
@@ -142,8 +145,6 @@ on:
142145
jobs:
143146
deploy:
144147
runs-on: ubuntu-latest
145-
environment: production
146-
147148
steps:
148149
- name: Checkout code
149150
uses: actions/checkout@v4
@@ -177,28 +178,22 @@ jobs:
177178
source: "compose.yaml"
178179
target: "${{ steps.idle.outputs.IDLE }}/"
179180
180-
- name: Deploy with Docker Compose
181+
- name: Deploy idle stack
181182
uses: appleboy/ssh-action@v1.0.3
182183
with:
183184
host: ${{ secrets.VPS_HOST }}
184185
username: ${{ secrets.VPS_USER }}
185186
key: ${{ secrets.VPS_SSH_KEY }}
186-
envs: GHCR_PAT,JWT_SECRET,POSTGRES_USER,PGUSER,POSTGRES_PASSWORD,PGPASS,PGRST_AUTHENTICATOR_PASS
187+
envs: GHCR_PAT
187188
script: |
188189
set -euo pipefail
189-
echo $GHCR_PAT | docker login ghcr.io -u ${{ github.actor }} --password-stdin
190+
echo "${{ steps.idle.outputs.ACTIVE }}" > active_stack
190191
cd ${{ steps.idle.outputs.IDLE }}
191-
docker compose pull -q
192+
echo "$GHCR_PAT" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
193+
DOCKER_CLIENT_TIMEOUT=300 COMPOSE_HTTP_TIMEOUT=300 docker compose pull -q
192194
STACK_NAME=${{ steps.idle.outputs.IDLE }} docker compose up -d
193-
echo "${{ steps.idle.outputs.ACTIVE }}" > active_stack
194195
env:
195196
GHCR_PAT: ${{ secrets.GHCR_PAT }}
196-
JWT_SECRET: ${{ secrets.JWT_SECRET }}
197-
PGRST_AUTHENTICATOR_PASS: ${{ secrets.PGRST_AUTHENTICATOR_PASS }}
198-
PGUSER: ${{ secrets.PGUSER }}
199-
PGPASS: ${{ secrets.PGPASS }}
200-
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
201-
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
202197
```
203198

204199
</details>

0 commit comments

Comments
 (0)