diff options
| -rw-r--r-- | .dockerignore | 3 | ||||
| -rw-r--r-- | Dockerfile | 6 | ||||
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | docker-compose.yml | 17 | ||||
| -rw-r--r-- | server.py | 7 |
5 files changed, 36 insertions, 2 deletions
diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b0abfdd --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git +.env +__pycache__ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e03197d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.12-slim +WORKDIR /app +COPY . . +ENV HOST=0.0.0.0 PYTHONUNBUFFERED=1 +EXPOSE 8000 +CMD ["python3", "server.py", "8000"] @@ -25,3 +25,8 @@ python3 server.py # → http://localhost:8000 リンキィディンクは Reserve Mart(reserve1.jp)で予約を受けていて、空き枠を見るには会員ログインが必要。 ID とパスワードは `.env` などに置き、リポジトリには入れないこと。 + +## デプロイ + +`git push` で post-receive フックが `/app/studio-slots` にチェックアウトし、`docker compose up -d --build` する。 +コンテナ名は `studio-app`(web ネットワーク、ポート 8000)。設定は hetzner-infra 側(`git/repos.txt`、`git/hooks/studio-slots/`)。 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ef0b274 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +services: + app: + container_name: studio-app + build: . + expose: + - "8000" + volumes: + # 手入力の予約済み枠はリポジトリ外に置く + - ./manual_slots.json:/app/manual_slots.json + restart: unless-stopped + networks: + - web + +networks: + web: + external: true + name: web @@ -2,9 +2,11 @@ python3 server.py # http://localhost:8000 python3 server.py 8080 # ポート指定 + HOST=0.0.0.0 python3 server.py # コンテナ内など外から受ける場合 """ import json +import os import sys from datetime import date from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer @@ -59,5 +61,6 @@ class Handler(SimpleHTTPRequestHandler): if __name__ == "__main__": port = int(sys.argv[1]) if len(sys.argv) > 1 else 8000 - print(f"http://localhost:{port}") - ThreadingHTTPServer(("127.0.0.1", port), Handler).serve_forever() + host = os.environ.get("HOST", "127.0.0.1") + print(f"http://{host}:{port}", flush=True) + ThreadingHTTPServer((host, port), Handler).serve_forever() |
