Skip to content

Commit 12e2557

Browse files
committed
Add github actions workflow for basic deployments
1 parent afb8cd9 commit 12e2557

File tree

2 files changed

+72
-5
lines changed

2 files changed

+72
-5
lines changed

docs/advanced.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ docker compose exec caddy caddy reload --config /etc/caddy/Caddyfile
256256

257257
## ⚡ GitHub Actions
258258

259-
Here's a Github Actions workflow you can use to automate deployments:
259+
Here's a Github Actions workflow you can use to automate deployments.
260+
261+
```sh
262+
mkdir -p .github/workflows
263+
```
260264

261265
<details>
262266
<summary>Show full workflow</summary>
@@ -306,7 +310,7 @@ jobs:
306310
307311
# Bring up stack and run healthchecks
308312
trap 'docker compose down' ERR
309-
docker compose up --detach
313+
docker compose up -d
310314
docker compose exec -T caddy curl -fsS http://caddy:80/healthz
311315
# Add more healthchecks here
312316
# docker compose exec -T caddy curl -fsS http://api:8080/healthz

docs/deploy.md

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@ Build and push your images:
2424
cd app
2525
docker compose build
2626
docker compose push
27-
cd ..
2827
```
2928

3029
## 📦 2. Copy to Server
3130

3231
Copy your `compose.yaml` to the remote host:
3332

3433
```sh
35-
scp app/compose.yaml youruser@yourserver:
34+
scp compose.yaml youruser@yourserver:
3635
```
3736

3837
## 3. Set Secrets
@@ -59,7 +58,7 @@ Your backend is now live. 🚀
5958

6059
## Upgrading
6160

62-
To upgrade your app, simply increment the image tag versions in compose.yaml.
61+
To upgrade your app, simply increment the image tag versions in `compose.yaml`.
6362

6463
The rest is the same:
6564

@@ -72,3 +71,67 @@ The rest is the same:
7271

7372
If you want zero-downtime deployments, rollback support, or blue-green testing,
7473
continue to [Advanced Deployments](advanced.md).
74+
75+
## ⚡ GitHub Actions
76+
77+
Here's a Github Actions workflow you can use to automate deployments.
78+
79+
```sh
80+
mkdir -p .github/workflows
81+
```
82+
83+
<details>
84+
<summary>Show full workflow</summary>
85+
86+
```yaml title=".github/workflows/ci.yaml"
87+
name: Deploy
88+
89+
on:
90+
push:
91+
branches:
92+
- prod
93+
94+
jobs:
95+
deploy:
96+
runs-on: ubuntu-latest
97+
steps:
98+
- name: Checkout code
99+
uses: actions/checkout@v4
100+
101+
- name: Copy compose.yaml from repository to deployment dir
102+
uses: appleboy/scp-action@master
103+
with:
104+
host: ${{ secrets.VPS_HOST }}
105+
username: ${{ secrets.VPS_USER }}
106+
key: ${{ secrets.VPS_SSH_KEY }}
107+
source: "app/compose.yaml"
108+
target: "app/"
109+
110+
- name: Deploy with Docker Compose
111+
uses: appleboy/[email protected]
112+
env:
113+
GHCR_PAT: ${{ secrets.GHCR_PAT }}
114+
with:
115+
host: ${{ secrets.VPS_HOST }}
116+
username: ${{ secrets.VPS_USER }}
117+
key: ${{ secrets.VPS_SSH_KEY }}
118+
envs: GHCR_PAT
119+
script: |
120+
set -euo pipefail
121+
cp .env app/
122+
cd app
123+
124+
# Pull images
125+
echo "$GHCR_PAT" | docker login ghcr.io --username "${{ github.actor }}" --password-stdin
126+
DOCKER_CLIENT_TIMEOUT=300 COMPOSE_HTTP_TIMEOUT=300 docker compose pull --quiet
127+
128+
# Bring up stack and run healthchecks
129+
trap 'docker compose down' ERR
130+
docker compose up -d
131+
docker compose exec -T caddy curl -fsS http://caddy:80/healthz
132+
# Add more healthchecks here
133+
# docker compose exec -T caddy curl -fsS http://api:8080/healthz
134+
# docker compose exec -T caddy curl -fsS http://postgrest:3000/
135+
```
136+
137+
</details>

0 commit comments

Comments
 (0)