Skip to content

Commit d03c9e3

Browse files
committed
Deploy static dashboard on push
1 parent 609f3a9 commit d03c9e3

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Deploy static site
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: read
10+
11+
concurrency:
12+
group: deploy-static-site
13+
cancel-in-progress: true
14+
15+
jobs:
16+
deploy:
17+
name: Build and deploy
18+
runs-on: ubuntu-latest
19+
20+
env:
21+
DEPLOY_HOST: ${{ secrets.DASHBOARD_DEPLOY_HOST }}
22+
DEPLOY_USER: ${{ secrets.DASHBOARD_DEPLOY_USER }}
23+
DEPLOY_KEY: ${{ secrets.DASHBOARD_DEPLOY_KEY }}
24+
DEPLOY_PATH: ${{ secrets.DASHBOARD_DEPLOY_PATH }}
25+
DEPLOY_PORT: ${{ secrets.DASHBOARD_DEPLOY_PORT || '22' }}
26+
27+
steps:
28+
- name: Check out repository
29+
uses: actions/checkout@v4
30+
31+
- name: Set up pnpm
32+
uses: pnpm/action-setup@v4
33+
with:
34+
version: 10.8.1
35+
36+
- name: Set up Node.js
37+
uses: actions/setup-node@v4
38+
with:
39+
node-version: 22
40+
cache: pnpm
41+
42+
- name: Install dependencies
43+
run: pnpm install --frozen-lockfile
44+
45+
- name: Build static files
46+
run: pnpm run build
47+
48+
- name: Configure SSH
49+
shell: bash
50+
run: |
51+
set -euo pipefail
52+
53+
test -n "$DEPLOY_HOST"
54+
test -n "$DEPLOY_USER"
55+
test -n "$DEPLOY_KEY"
56+
test -n "$DEPLOY_PATH"
57+
58+
mkdir -p ~/.ssh
59+
chmod 700 ~/.ssh
60+
printf '%s\n' "$DEPLOY_KEY" > ~/.ssh/deploy_key
61+
chmod 600 ~/.ssh/deploy_key
62+
ssh-keyscan -p "$DEPLOY_PORT" "$DEPLOY_HOST" >> ~/.ssh/known_hosts
63+
64+
- name: Replace Caddy static files
65+
shell: bash
66+
run: |
67+
set -euo pipefail
68+
69+
SSH_TARGET="${DEPLOY_USER}@${DEPLOY_HOST}"
70+
SSH_COMMAND="ssh -i ~/.ssh/deploy_key -p ${DEPLOY_PORT}"
71+
REMOTE_PATH="${DEPLOY_PATH%/}"
72+
73+
$SSH_COMMAND "$SSH_TARGET" "mkdir -p '$REMOTE_PATH'"
74+
75+
rsync -az --delete \
76+
--exclude 'links.json' \
77+
-e "$SSH_COMMAND" \
78+
dist/ "$SSH_TARGET:$REMOTE_PATH/"

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,16 @@ The static output is written to `dist/` and can be served by any static file ser
2121
To add links, edit `public/links.json`. That file is ignored by git; `public/links.example.json` is the safe
2222
committed template. Anyone who can load the deployed dashboard can also read `/links.json`, so only deploy it
2323
where those links can be visible to viewers.
24+
25+
## Deployment
26+
27+
Pushes to `main` rebuild the static files with GitHub Actions and sync `dist/` to the Caddy web root over SSH.
28+
The sync preserves `links.json` on the server, so keep the production copy at the root Caddy serves.
29+
30+
Required repository secrets:
31+
32+
- `DASHBOARD_DEPLOY_HOST`
33+
- `DASHBOARD_DEPLOY_USER`
34+
- `DASHBOARD_DEPLOY_KEY`
35+
- `DASHBOARD_DEPLOY_PATH`
36+
- `DASHBOARD_DEPLOY_PORT` optional, defaults to `22`

0 commit comments

Comments
 (0)