Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

139 changes: 139 additions & 0 deletions docs/create_docker_container_ja.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Claude Agent SDKをDockerコンテナ上で実行する

以下の手順は、[create_your_claude_agent_sdk_apps.md](./create_your_claude_agent_sdk_apps.md) を行った後の手順となります。

本手順では、docker composeを利用して、Claude Agent SDKをDockerコンテナ上で実行する方法を解説します。

## 必要ファイルをコピーする

[example_apps/claude_agent_sdk](../example_apps/claude_agent_sdk) にある以下のファイルを、コードのディレクトリにコピーします。

- [.dockerignore](../example_apps/claude_agent_sdk/.dockerignore)
- [Dockerfile](../example_apps/claude_agent_sdk/Dockerfile)
- [docker-compose.yml](../example_apps/claude_agent_sdk/docker-compose.yml)

## app.py のワークスペースのパスを修正する

app.py 内のワークスペースのパスは、コンテナ内のパスに書き換える必要があります。

コンテナ内のパスは `/app/workspace` となります。そのように、app.py 内の WORKSPACE_DIR の定義を書き換えてください。

```py
WORKSPACE_DIR = "/app/workspace"
```

## docker-compose ファイルの編集

### Google Cloudのサービスアカウントの秘密鍵のJSONファイルをマウントする

Google Cloudのサービスアカウントの秘密鍵のJSONファイルを、コンテナ内にマウントして、コンテナ内から参照可能にする必要があります。

以下にサービスアカウントの秘密鍵のJSONファイルがある例として、説明します。

> /Users/foobar/google_cloud_credentials/application_credentials.json

volumesの項目にある/path/to/your/google_cloud_credentials の部分を、置かれているディレクトリに書き換えてください。

```yaml
volumes:
# Google Cloud service account key JSON direcrory
- /Users/foobar/google_cloud_credentials:/secrets/google_cloud_credentials:ro
```

すると、そのディレクトリが /secrets/google_cloud_credentials としてコンテナ内にマウントされます。

environmentの項目にあるGOOGLE_APPLICATION_CREDENTIALSの値を、マウントしたディレクトリ内のJSONファイルのパスに書き換えてください。

```yaml
environment:
GOOGLE_APPLICATION_CREDENTIALS: /secrets/google_cloud_credentials/application_credentials.json
```

### ワークスペースのディレクトリをマウントする

ワークスペースのディレクトリをコンテナ内にマウントする必要があります。

以下にワークスペースのディレクトリがある例として、説明します。

> /Users/foobar/stackchan_workspace

volumesの項目にある ./workspace の部分を、置かれているディレクトリに書き換えてください。

```yaml
volumes:
# Workspace directory
- /Users/foobar/stackchan_workspace:/app/workspace
```

### VOICEVOXを使わない場合

VOICEVOXのコンテナを起動するようになっています。
VOICEVOXを使わない場合、services.voicevoxの記述を削除、もしくはコメントアウトしてください。

```yaml
services:
app:
...
# voicevox:
# image: voicevox/voicevox_engine:cpu-latest
# ports:
# - "50021:50021"
```

また、services.app.depends_on の項目も削除、もしくはコメントアウトしてください。

```yaml
services:
app:
...
# depends_on:
# - voicevox
```

## コンテナのビルド

このコンテナをビルドするには、コードのディレクトリにて、以下のコマンドを実行してください。

```
docker compose build
```

## コンテナの起動、終了、削除

このコンテナを起動するには、コードのディレクトリにて、以下のコマンドを実行してください。

```
docker compose up -d
```

起動を確認するには、以下のコマンド実行します。

```
docker compose ps -a
```

STATUSが「Up」になっていれば、起動しています。
「Exited」になっている場合は、コンテナが終了しています。

コンテナのログを確認するには、以下のコマンドを実行してください。

```
docker compose logs app
```

コンテナを一度起動した場合、異常終了したとしてもコンテナインスタンスは残り続けます。
設定やコンテナのビルドをやり直して、再度起動したい場合には、一度削除した上で起動する必要があります。

コンテナを停止するには以下のコマンドを実行します。

```
docker compose stop
```

コンテナを削除するには以下のコマンドを実行します。

```
docker compose rm -f
```

この後に、コンテナのビルドからやり直してください。
11 changes: 7 additions & 4 deletions docs/setup_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,13 @@ Pythonの環境構築の方法は、パッケージマネージャuvのページ

## Claude Agent SDKによるAIエージェントアプリケーションの開発

以下のページを参照して、ユーザ独自のコードで、Claude Agent SDKを利用したAIエージェントアプリケーションを起動する方法を確認してください
Claude Agent SDKを利用したAIエージェントアプリケーションの開発方法は、以下のページを参照してください

[docs/create_your_claude_agent_sdk_apps.md](../docs/create_your_claude_agent_sdk_apps.md)
[create_your_claude_agent_sdk_apps.md](./create_your_claude_agent_sdk_apps.md)

## Claude Agent SDKをDocker環境で実行する
## Claude Agent SDKをDockerコンテナ上で実行する

TODO
Dockerコンテナを使うと、ファイルシステムが隔離されるため、Claude Agent SDKを安全に実行できます。
以下のページを参照してください。

[create_docker_container_ja.md](./create_docker_container_ja.md)
3 changes: 3 additions & 0 deletions example_apps/claude_agent_sdk/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
__init__.py
workspace
30 changes: 30 additions & 0 deletions example_apps/claude_agent_sdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# syntax=docker/dockerfile:1.6
FROM node:25-bookworm-slim

RUN apt-get update && \
apt-get install -y --no-install-recommends git ca-certificates && \
rm -rf /var/lib/apt/lists/*

RUN npm install -g @anthropic-ai/claude-code

COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
ENV UV_PYTHON_INSTALL_DIR=/var/uv/python
ENV UV_CACHE_DIR=/var/uv/cache

WORKDIR /app

COPY uv.lock \
pyproject.toml \
.

RUN --mount=type=cache,target=/var/uv/cache,uid=0,gid=0,mode=0777 \
uv sync --frozen --no-install-project

COPY app.py .

USER node

ENV HOME=/home/node
ENV STACKCHAN_WORKSPACE_DIR=/app/workspace

ENTRYPOINT [".venv/bin/uvicorn", "app:app.fastapi", "--host=0.0.0.0", "--port=8000"]
22 changes: 22 additions & 0 deletions example_apps/claude_agent_sdk/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: stackchan-server
services:
app:
env_file:
- path: .env
required: false
environment:
STACKCHAN_VOICEVOX_URL: http://voicevox:50021
GOOGLE_APPLICATION_CREDENTIALS: /secrets/google_cloud_credentials/application_credentials.json
depends_on:
- voicevox
build: .
ports:
- "8000:8000"
volumes:
# Google Cloud service account key JSON direcrory
- /path/to/google_cloud_credentials:/secrets/google_cloud_credentials:ro
- ./workspace:/app/workspace
voicevox:
image: voicevox/voicevox_engine:cpu-latest
ports:
- "50021:50021"
13 changes: 13 additions & 0 deletions example_apps/claude_agent_sdk/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[project]
name = "stackchan-server"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"claude-agent-sdk>=0.1.56",
"websocket-control-stackchan-server",
]

[tool.uv.sources]
websocket-control-stackchan-server = { git = "https://github.com/74th/websocket-control-stackchan.git" }
Loading
Loading