summaryrefslogtreecommitdiff
path: root/CLAUDE.md
blob: 28124bf43e8d7e3f51fdb858800c2b7217ebdade (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
74
75
76
# hetzner-infra

Hetzner VPS 上で動くサービス群のインフラ管理リポジトリ。

## ディレクトリ構成

```
caddy/    リバースプロキシ(Caddyfile, docker-compose.yml, deploy.sh)
cgit/     cgit Web UI(Dockerfile, lighttpd.conf, cgitrc, deploy.sh)
git/      ベアリポジトリ・フック管理(repos.txt, hooks/, install.sh)
claude/   Claude Code セッション管理(sessions.txt, systemd unit, sync.sh)
mail/     MTA(Postfix + OpenDKIM, docker-compose.yml, install.sh, dns/setup-route53.py)
server/   サーバー共通設定(authorized_keys, requirements.md)
```

## デプロイの仕組み

- `git push origin master` → post-receive フック → `caddy/deploy.sh` / `cgit/deploy.sh` / `mail/deploy.sh` を実行
- cgit の `lighttpd.conf` / `Dockerfile` 変更はイメージ再ビルドが必要(`deploy.sh` で `--build` するため push だけで反映される)
- cgit の `cgitrc` はボリュームマウントのため push だけで反映される
- フック・リポジトリの変更は push 後に `bash /app/infra/git/install.sh` を手動実行
- Claude セッションの変更は push 後に `bash /app/infra/claude/sync.sh` を手動実行
- mail ドメイン変更(`mail/domains.txt`)は push 後に `bash /app/infra/mail/install.sh` を手動実行

## 管理対象リポジトリ

`git/repos.txt` に定義。`git/hooks/<repo>/post-receive` がデプロイ内容。

| リポジトリ | work tree |
|---|---|
| hetzner-infra | /app/infra |
| tokyo-livehouse-events | /app/tokyo-livehouse-events |
| whois-band | /app/whois-band |

## よく使うコマンド

```bash
# Caddy 設定変更
vi caddy/Caddyfile && git push origin master

# cgit 設定変更(lighttpd.conf / cgitrc)
vi cgit/lighttpd.conf  # または cgit/cgitrc
git push origin master  # --build 付きで自動再デプロイ

# フック・リポジトリ定義変更
vi git/hooks/.../post-receive  # または git/repos.txt
git push origin master
ssh root@localhost 'bash /app/infra/git/install.sh'

# Claude セッション変更
vi claude/sessions.txt
git push origin master
ssh root@localhost 'bash /app/infra/claude/sync.sh'

# SSH 鍵追加
vi server/authorized_keys
git push origin master
ssh root@localhost 'bash /app/infra/git/install.sh'

# MTA(mail)初回セットアップ(サーバー上で root として実行)
ssh root@<server> 'bash /app/infra/mail/install.sh'
# → DKIM 鍵生成 + コンテナ起動。公開鍵が表示される。

# Route 53 DNS 設定(サーバー上で実行)
ssh root@<server>
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
export HOSTED_ZONE_ID=Z...
export SERVER_IP=<HetznerサーバーのパブリックIP>
python3 /app/infra/mail/dns/setup-route53.py

# mail ドメイン追加(golive → whoisband も追加する例)
vi mail/domains.txt
git push origin master
ssh root@localhost 'bash /app/infra/mail/install.sh'  # テーブル再生成 + 再起動
```