62 lines
1.8 KiB
YAML
62 lines
1.8 KiB
YAML
name: Deploy dzanan.net
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: behemoth
|
|
|
|
steps:
|
|
- name: Checkout
|
|
run: |
|
|
podman exec podman_gitea_1 git --git-dir=/data/git/repositories/v7/dzanan.net.git archive "${GITHUB_SHA}" | tar -x
|
|
|
|
- name: Build image
|
|
run: |
|
|
podman build --pull -t localhost/dzanan-net:${GITHUB_SHA} -t localhost/dzanan-net:latest .
|
|
|
|
- name: Replace container
|
|
run: |
|
|
podman stop dzanan-web || true
|
|
podman rm dzanan-web || true
|
|
podman run -d \
|
|
--name dzanan-web \
|
|
--restart=unless-stopped \
|
|
--network podman_proxy \
|
|
-e NODE_ENV=production \
|
|
-e PORT=3000 \
|
|
localhost/dzanan-net:latest
|
|
|
|
- name: Check application health
|
|
run: |
|
|
podman exec dzanan-web node -e "fetch('http://127.0.0.1:3000/').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
|
|
|
|
- name: Configure Caddy route
|
|
run: |
|
|
python3 - <<'PY'
|
|
from pathlib import Path
|
|
|
|
path = Path("/home/podman/configs/caddy/Caddyfile")
|
|
text = path.read_text()
|
|
static = """dzanan.net, www.dzanan.net {
|
|
root * /srv/dzanan.net
|
|
file_server
|
|
encode gzip zstd
|
|
}"""
|
|
proxy = """dzanan.net, www.dzanan.net {
|
|
encode gzip zstd
|
|
reverse_proxy dzanan-web:3000
|
|
}"""
|
|
if static in text:
|
|
path.write_text(text.replace(static, proxy))
|
|
elif proxy not in text:
|
|
raise SystemExit("Expected dzanan.net Caddy block was not found")
|
|
PY
|
|
|
|
- name: Reload Caddy
|
|
run: |
|
|
podman exec podman_caddy_1 caddy validate --config /etc/caddy/Caddyfile
|
|
podman exec podman_caddy_1 caddy reload --config /etc/caddy/Caddyfile
|