summaryrefslogtreecommitdiff
path: root/Deploy.md
blob: 22e96ee719a485c9ef054714e598044e5ad9ab22 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Deploy

Hetzner Cloud + Docker + Caddy (HTTPS) の共有インフラ。

## ディレクトリ構成

| ディレクトリ | 管理対象 |
|---|---|
| `caddy/` | リバースプロキシ(Caddyfile, docker-compose.yml, deploy.sh) |
| `git/` | ベアリポジトリ・フック(repos.txt, hooks/\*/post-receive, install.sh) |
| `claude/` | Claude Code セッション(sessions.txt, systemd unit, sync.sh) |

## リバースプロキシ(caddy/)

git push 時に post-receive フックが `caddy/deploy.sh` を実行する。

```bash
git push origin master
```

Caddyfile 変更時も同様。

## git リポジトリ管理(git/)

`git/repos.txt` と `git/hooks/` で全リポジトリのベアリポジトリとフックを管理する。
git push では**自動展開しない**。変更後は手動で実行する。

```bash
git push origin master
ssh root@localhost 'bash /app/infra/git/install.sh'
```

| ファイル | 役割 |
|---|---|
| `git/repos.txt` | `name:work-tree` 形式でリポジトリを定義 |
| `git/hooks/<repo>/post-receive` | 各リポジトリのフック内容 |
| `git/install.sh` | ベアリポジトリ作成 + フック展開 |

## Claude Code セッション管理(claude/)

`claude/sessions.txt` で管理し、手動で同期する。

```bash
git push origin master
ssh root@localhost 'bash /app/infra/claude/sync.sh'
```

| ファイル | 役割 |
|---|---|
| `claude/sessions.txt` | `user:repo` 形式でセッションを定義 |
| `claude/systemd/claude-code@.service` | サービステンプレート |
| `claude/sync.sh` | user service を同期 |

### サービス確認

```bash
systemctl --user status 'claude-code@*.service'
tmux ls
```

## リポジトリとデプロイ先

| リポジトリ | bare repo | work tree |
|---|---|---|
| hetzner-infra | /var/git/hetzner-infra.git | /app/infra |
| tokyo-livehouse-events | /var/git/tokyo-livehouse-events.git | /app/tokyo-livehouse-events |
| whois-band | /var/git/whois-band.git | /app/whois-band |

## Docker

```
web (external network)
  ├── caddy-caddy-1      (80/443)
  ├── tokyo-app          (golive.yyamashita.com → :3000)
  └── whois-app          (whoisband.yyamashita.com → :3000)
```

- **サーバー**: Hetzner CX22 (Helsinki, Ubuntu 24.04)
- **SSH**: `ssh root@localhost`

## 新アプリ追加手順

1. `git/repos.txt` に `<name>:<work-tree>` を追記
2. `git/hooks/<name>/post-receive` を作成
3. `caddy/Caddyfile` にホスト追加
4. `git push origin master` → `ssh root@localhost 'bash /app/infra/git/install.sh'`
5. 新アプリ側: `git remote add hetzner root@localhost:/var/git/<name>.git` → `git push hetzner master`

## 初回サーバーセットアップ(再構築時)

```bash
# 1. hetzner-infra をブートストラップ
scp git/server-setup.sh root@<server-ip>:~/
ssh root@<server-ip> 'bash server-setup.sh'

# 2. 最初の push(bootstrap hook で /app/infra に展開される)
git push origin master

# 3. 正式フックをインストール + 他リポジトリ作成
ssh root@<server-ip> 'bash /app/infra/git/install.sh'
```