From ef6dbdd2ac273dc4a01c70437ee7984cea9f2a3c Mon Sep 17 00:00:00 2001 From: yyamashita Date: Sun, 17 May 2026 11:29:27 +0900 Subject: Reorganize repo into caddy/, git/, claude/ directories - caddy/: Caddyfile, docker-compose.yml, deploy.sh (hook runs this only) - git/: repos.txt, hooks/*/post-receive, install.sh, server-setup.sh - claude/: sessions.txt, systemd/claude-code@.service, sync.sh Post-receive hook is now: checkout + bash caddy/deploy.sh Co-Authored-By: Claude Sonnet 4.6 --- git/hooks/hetzner-infra/post-receive | 5 +++ git/hooks/tokyo-livehouse-events/post-receive | 8 ++++ git/hooks/whois-band/post-receive | 8 ++++ git/install.sh | 60 +++++++++++++++++++++++++++ git/repos.txt | 5 +++ git/server-setup.sh | 30 ++++++++++++++ 6 files changed, 116 insertions(+) create mode 100755 git/hooks/hetzner-infra/post-receive create mode 100755 git/hooks/tokyo-livehouse-events/post-receive create mode 100755 git/hooks/whois-band/post-receive create mode 100755 git/install.sh create mode 100644 git/repos.txt create mode 100755 git/server-setup.sh (limited to 'git') diff --git a/git/hooks/hetzner-infra/post-receive b/git/hooks/hetzner-infra/post-receive new file mode 100755 index 0000000..d41659b --- /dev/null +++ b/git/hooks/hetzner-infra/post-receive @@ -0,0 +1,5 @@ +#!/bin/bash +set -e +GIT_WORK_TREE=/app/infra git checkout -f +bash /app/infra/caddy/deploy.sh +echo "Deploy complete: hetzner-infra" diff --git a/git/hooks/tokyo-livehouse-events/post-receive b/git/hooks/tokyo-livehouse-events/post-receive new file mode 100755 index 0000000..ca64767 --- /dev/null +++ b/git/hooks/tokyo-livehouse-events/post-receive @@ -0,0 +1,8 @@ +#!/bin/bash +set -e +APP_DIR=/app/tokyo-livehouse-events +GIT_WORK_TREE=$APP_DIR git checkout -f +cd $APP_DIR +mkdir -p data +docker compose up -d --build +echo "Deploy complete: tokyo-livehouse-events" diff --git a/git/hooks/whois-band/post-receive b/git/hooks/whois-band/post-receive new file mode 100755 index 0000000..60b368f --- /dev/null +++ b/git/hooks/whois-band/post-receive @@ -0,0 +1,8 @@ +#!/bin/bash +set -e +APP_DIR=/app/whois-band +GIT_WORK_TREE=$APP_DIR git checkout -f +cd $APP_DIR +mkdir -p data +docker compose up -d --build +echo "Deploy complete: whois-band" diff --git a/git/install.sh b/git/install.sh new file mode 100755 index 0000000..12f561c --- /dev/null +++ b/git/install.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# サーバー上で root として手動実行する +# repos.txt に基づいてベアリポジトリとワークツリーを作成し、 +# git/hooks/ のフックを /var/git/*/hooks/ に展開する +set -euo pipefail + +APP_DIR="$(cd "$(dirname "$0")/.." && pwd)" +REPOS_FILE="$APP_DIR/git/repos.txt" +HOOKS_SRC="$APP_DIR/git/hooks" + +if [[ "$(id -u)" -ne 0 ]]; then + echo "ERROR: root として実行してください" >&2 + exit 1 +fi + +echo "=== Repositories ===" +while IFS=: read -r repo_name work_tree; do + [[ "$repo_name" =~ ^#.*$ || -z "$repo_name" ]] && continue + bare_repo="/var/git/${repo_name}.git" + + if [[ ! -d "$bare_repo" ]]; then + echo " create: $bare_repo" + mkdir -p "$bare_repo" + git init --bare "$bare_repo" + else + echo " exists: $bare_repo" + fi + + if [[ ! -d "$work_tree" ]]; then + echo " mkdir: $work_tree" + mkdir -p "$work_tree" + fi +done < "$REPOS_FILE" + +echo "" +echo "=== Hooks ===" +for repo_src in "$HOOKS_SRC"/*/; do + repo_name="$(basename "$repo_src")" + git_hooks_dir="/var/git/${repo_name}.git/hooks" + + if [[ ! -d "$git_hooks_dir" ]]; then + echo " SKIP: $git_hooks_dir not found ($repo_name)" + continue + fi + + for hook_file in "$repo_src"*; do + hook_name="$(basename "$hook_file")" + dst="$git_hooks_dir/$hook_name" + if diff -q "$hook_file" "$dst" >/dev/null 2>&1; then + echo " unchanged: $repo_name/$hook_name" + else + cp "$hook_file" "$dst" + chmod +x "$dst" + echo " installed: $repo_name/$hook_name" + fi + done +done + +echo "" +echo "Done." diff --git a/git/repos.txt b/git/repos.txt new file mode 100644 index 0000000..58ab877 --- /dev/null +++ b/git/repos.txt @@ -0,0 +1,5 @@ +# リポジトリ定義 +# 形式: : +hetzner-infra:/app/infra +tokyo-livehouse-events:/app/tokyo-livehouse-events +whois-band:/app/whois-band diff --git a/git/server-setup.sh b/git/server-setup.sh new file mode 100755 index 0000000..a575628 --- /dev/null +++ b/git/server-setup.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# Run once on a fresh Hetzner VPS (as root). +# hetzner-infra のみブートストラップとして作成する。 +# 他のリポジトリは最初の push 後に git/install.sh が作成する。 +set -e + +REPO_DIR=/var/git/hetzner-infra.git +APP_DIR=/app/infra + +curl -fsSL https://get.docker.com | sh +docker network create web || true + +mkdir -p "$REPO_DIR" "$APP_DIR" +git init --bare "$REPO_DIR" + +# 最初の push を受け取るための最小限のフック(git/install.sh 実行後に上書きされる) +cat > "$REPO_DIR/hooks/post-receive" << 'HOOK' +#!/bin/bash +set -e +GIT_WORK_TREE=/app/infra git checkout -f +bash /app/infra/caddy/deploy.sh +echo "Deploy complete: hetzner-infra" +HOOK +chmod +x "$REPO_DIR/hooks/post-receive" + +echo "" +echo "Next steps:" +echo " 1. git remote add origin root@:$REPO_DIR" +echo " 2. git push origin master" +echo " 3. ssh root@ 'bash $APP_DIR/git/install.sh'" -- cgit v1.2.3