diff options
| author | yyamashita <yyamashita@hetzner.yyamashita.com> | 2026-05-17 11:30:09 +0900 |
|---|---|---|
| committer | yyamashita <yyamashita@hetzner.yyamashita.com> | 2026-05-17 11:30:09 +0900 |
| commit | 4a2def16fa9b66d0f7b3ce0812325365bb821287 (patch) | |
| tree | f1623659e121b97712cdaa66388e73dda0badf8e | |
| parent | ef6dbdd2ac273dc4a01c70437ee7984cea9f2a3c (diff) | |
Update Deploy.md for new directory structure
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| -rw-r--r-- | Deploy.md | 145 |
1 files changed, 61 insertions, 84 deletions
@@ -1,124 +1,101 @@ # 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` - -## リポジトリとデプロイ先 +| ディレクトリ | 管理対象 | +|---|---| +| `caddy/` | リバースプロキシ(Caddyfile, docker-compose.yml, deploy.sh) | +| `git/` | ベアリポジトリ・フック(repos.txt, hooks/\*/post-receive, install.sh) | +| `claude/` | Claude Code セッション(sessions.txt, systemd unit, sync.sh) | -| リポジトリ | 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 | +## リバースプロキシ(caddy/) -## デプロイ +git push 時に post-receive フックが `caddy/deploy.sh` を実行する。 ```bash -git push hetzner master +git push origin master ``` -Caddyfile 変更時も同様(push 後に自動 reload)。 +Caddyfile 変更時も同様。 -## サーバー操作 +## git リポジトリ管理(git/) -```bash -# 全コンテナ確認 -ssh golive 'docker ps' +`git/repos.txt` と `git/hooks/` で全リポジトリのベアリポジトリとフックを管理する。 +git push では**自動展開しない**。変更後は手動で実行する。 -# 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' +```bash +git push origin master +ssh root@localhost 'bash /app/infra/git/install.sh' ``` -## サーバー構成管理 - -ベアリポジトリ・ワークツリー・フックはすべてこのリポジトリで一元管理する。 -git push では**自動展開しない**(セキュリティ上の理由)。変更後は手動で `install.sh` を実行する。 - | ファイル | 役割 | |---|---| -| `repos.txt` | 全リポジトリの定義(`name:work-tree` 形式) | -| `server-hooks/<repo>/post-receive` | 各リポジトリのフック内容 | -| `scripts/install.sh` | ベアリポジトリ作成 + フック展開(要 root) | -| `scripts/server-setup.sh` | 初回のみ: Docker + hetzner-infra ブートストラップ | +| `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/scripts/install.sh' +ssh root@localhost 'bash /app/infra/claude/sync.sh' ``` -## 新アプリ追加手順 - -1. `repos.txt` に `<name>:<work-tree>` を追記 -2. `server-hooks/<name>/post-receive` を作成 -3. `Caddyfile` にホスト追加 -4. `git push origin master` → `ssh root@localhost 'bash /app/infra/scripts/install.sh'` -5. 新アプリ側: `git remote add hetzner root@localhost:/var/git/<name>.git` → `git push hetzner master` +| ファイル | 役割 | +|---|---| +| `claude/sessions.txt` | `user:repo` 形式でセッションを定義 | +| `claude/systemd/claude-code@.service` | サービステンプレート | +| `claude/sync.sh` | user service を同期 | -## Claude Code セッション管理 +### サービス確認 -`git push` 時に post-receive フック(root)が `yyamashita` ユーザーの systemd user service を自動同期する。 +```bash +systemctl --user status 'claude-code@*.service' +tmux ls +``` -| ファイル | 役割 | -|---|---| -| `systemd/user/claude-code@.service` | サービステンプレート | -| `claude-code-sessions.txt` | 有効にするセッション一覧(`user:repo` 形式) | -| `scripts/sync-claude-services.sh` | root が user service を同期するスクリプト | +## リポジトリとデプロイ先 -### セッション追加・削除 +| リポジトリ | 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 | -`claude-code-sessions.txt` を編集して `git push hetzner master`: +## Docker ``` -# 形式: user:repo -yyamashita:hetzner-infra -yyamashita:new-repo +web (external network) + ├── caddy-caddy-1 (80/443) + ├── tokyo-app (golive.yyamashita.com → :3000) + └── whois-app (whoisband.yyamashita.com → :3000) ``` -### 手動同期(サーバー上で) - -```bash -ssh root@localhost 'bash /app/infra/scripts/sync-claude-services.sh' -``` +- **サーバー**: Hetzner CX22 (Helsinki, Ubuntu 24.04) +- **SSH**: `ssh root@localhost` -### サービス確認 +## 新アプリ追加手順 -```bash -systemctl --user status 'claude-code@*.service' -tmux ls -``` +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 を最初にセットアップ(Docker + web network 作成) -scp scripts/server-setup.sh golive:~/ -ssh golive 'bash server-setup.sh' -git push hetzner master +# 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 -# 2. 各アプリをセットアップ -# (各リポジトリの scripts/server-setup.sh を参照) +# 3. 正式フックをインストール + 他リポジトリ作成 +ssh root@<server-ip> 'bash /app/infra/git/install.sh' ``` |
