# 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//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` に `:` を追記 2. `git/hooks//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/.git` → `git push hetzner master` ## 初回サーバーセットアップ(再構築時) ```bash # 1. hetzner-infra をブートストラップ scp git/server-setup.sh root@:~/ ssh root@ 'bash server-setup.sh' # 2. 最初の push(bootstrap hook で /app/infra に展開される) git push origin master # 3. 正式フックをインストール + 他リポジトリ作成 ssh root@ 'bash /app/infra/git/install.sh' ```