blob: 0ba98a271a2a64665ba4064954dd9f914a0ad801 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# Deploy
Hetzner Cloud + Docker + Caddy (HTTPS) の共有インフラ。
複数アプリを同一ホストで運用し、Caddy がホスト名でルーティングする。
## 構成
```
git push hetzner master (各リポジトリ)
└→ /var/git/<repo>.git/hooks/post-receive
└→ git checkout -f → /app/<name>/
└→ docker compose up -d (--build)
Docker network: web (external, 全アプリ共有)
├── infra-caddy-1 (80/443, HTTPS 自動証明書)
├── tokyo-app (golive.yyamashita.com → :3000)
└── whois-app (whois.band → :3000)
```
- **サーバー**: Hetzner CX22 (Helsinki, Ubuntu 24.04)
- **SSH**: `ssh golive`
## リポジトリとデプロイ先
| リポジトリ | bare repo | work tree |
|---|---|---|
| hetzner-infra | /var/git/hetzner-infra.git | /app/infra |
| tokyo-livehouse-events | /var/git/tokyo-livehouse-events.git | /app |
| whois-band | /var/git/whois-band.git | /app/whois-band |
## デプロイ
```bash
git push hetzner master
```
Caddyfile 変更時も同様(push 後に自動 reload)。
## サーバー操作
```bash
# 全コンテナ確認
ssh golive 'docker ps'
# Caddy ログ
ssh golive 'docker logs infra-caddy-1 -f'
# tokyo ログ
ssh golive 'docker logs tokyo-app -f'
# whois ログ
ssh golive 'docker logs whois-app -f'
```
## 新アプリ追加手順
1. `Caddyfile` にホスト追加 → `git push hetzner master`
2. 新アプリ側: `docker-compose.yml` で `external: true` の `web` network を使用、`container_name` を設定
3. 新アプリの bare repo をサーバに作成(`scripts/server-setup.sh` 参照)
4. `git remote add hetzner golive:/var/git/<name>.git`
5. `git push hetzner master`
## 初回サーバーセットアップ(再構築時)
```bash
# 1. hetzner-infra を最初にセットアップ(Docker + web network 作成)
scp scripts/server-setup.sh golive:~/
ssh golive 'bash server-setup.sh'
git push hetzner master
# 2. 各アプリをセットアップ
# (各リポジトリの scripts/server-setup.sh を参照)
```
|