Convert ccNexus to headless Docker service#61
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request converts ccNexus from a Wails-based desktop application to a headless Docker service that exposes an HTTP API, enabling cross-platform deployment through containerization and reverse proxy.
Key Changes:
- Added a new headless server entry point in Go that runs without GUI, supporting graceful shutdown and environment-based configuration
- Created Docker infrastructure (Dockerfile, docker-compose.yml) for containerized deployment with SQLite support
- Established persistent data storage pattern using volume mounts and database migration from JSON to SQLite
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| app/cmd/server/main.go | New headless server entry point with signal handling, configuration loading from SQLite, environment variable overrides, and graceful shutdown |
| Dockerfile | Multi-stage build for Go binary with CGO-enabled SQLite support, runtime image based on Alpine with health checks |
| docker-compose.yml | Service definition with port mapping, volume mount for data persistence, health check endpoint, and environment configuration |
| docker-entrypoint.sh | Shell script for container initialization with data directory permission checks (currently unused) |
| README_DOCKER.md | Chinese documentation explaining the architectural changes, Docker setup, data migration, and usage instructions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| # Ensure data directory exists and has correct permissions | ||
| if [ ! -w "${CCNEXUS_DATA_DIR:-/data}" ]; then | ||
| echo "Warning: Data directory is not writable, attempting to fix..." |
There was a problem hiding this comment.
The docker-entrypoint.sh script displays a warning when the data directory is not writable but doesn't actually attempt to fix the permissions. The comment says "attempting to fix..." but no fix action is taken. Either remove the misleading message or implement the actual permission fix using chmod/chown.
| echo "Warning: Data directory is not writable, attempting to fix..." | |
| echo "Warning: Data directory is not writable, attempting to fix..." | |
| # Try to fix permissions: set ownership to current user and add write permission | |
| chown "$(id -u):$(id -g)" "${CCNEXUS_DATA_DIR:-/data}" 2>/dev/null || true | |
| chmod u+w "${CCNEXUS_DATA_DIR:-/data}" 2>/dev/null || true | |
| # Re-check if writable | |
| if [ ! -w "${CCNEXUS_DATA_DIR:-/data}" ]; then | |
| echo "Error: Failed to make data directory writable: ${CCNEXUS_DATA_DIR:-/data}" | |
| exit 1 | |
| fi |
| volumes: | ||
| ccnexus-data: | ||
| driver: local |
There was a problem hiding this comment.
A named volume 'ccnexus-data' is defined at the bottom of the file but is never used by any service. The ccnexus service uses a bind mount '/data/ccnexus/:/data' instead. Either remove the unused volume definition or update the service to use it.
| volumes: | |
| ccnexus-data: | |
| driver: local |
| COPY app/ ./ | ||
|
|
||
| # Ensure module graph is complete (generates go.sum) | ||
| RUN go mod tidy |
There was a problem hiding this comment.
Running 'go mod tidy' during the Docker build is problematic because it can modify go.mod and go.sum in unpredictable ways, potentially pulling different dependency versions on each build. This breaks build reproducibility and can cause the build to fail if go.mod and go.sum are out of sync. The go.sum should be committed to the repository and 'go mod tidy' should be run during development, not in the Dockerfile.
| RUN go mod tidy |
| #!/bin/sh | ||
| set -e | ||
|
|
||
| # Ensure data directory exists and has correct permissions | ||
| if [ ! -w "${CCNEXUS_DATA_DIR:-/data}" ]; then | ||
| echo "Warning: Data directory is not writable, attempting to fix..." | ||
| fi | ||
|
|
||
| # Run the server | ||
| exec /app/ccnexus-server "$@" |
There was a problem hiding this comment.
The docker-entrypoint.sh script is defined in the repository but is never used. The Dockerfile uses ENTRYPOINT to directly call the binary without going through this shell script. Either remove this unused file or update the Dockerfile to actually use it by copying it to the image and setting it as the entrypoint.
|
|
||
| 1. 新增无头入口 | ||
| - 新增 [app/cmd/server/main.go](app/cmd/server/main.go) 作为 headless 入口:仅启动 HTTP 代理(无 GUI),支持优雅退出,读取 `CCNEXUS_DATA_DIR`、`CCNEXUS_DB_PATH`、`CCNEXUS_PORT`、`CCNEXUS_LOG_LEVEL` 环境变量。 | ||
| - 若存储中无任何 endpoint,会自动写入默认示例 endpoint,避免 “no endpoints configured” 直接退出。请尽快替换为真实 API 配置。 |
There was a problem hiding this comment.
Typo in Chinese text: "示例 endpoint" should use consistent terminology. Consider using "端点" (endpoint) consistently in Chinese documentation or sticking with the English term throughout.
| - 若存储中无任何 endpoint,会自动写入默认示例 endpoint,避免 “no endpoints configured” 直接退出。请尽快替换为真实 API 配置。 | |
| - 若存储中无任何 endpoint,会自动写入默认示例端点,避免 “no endpoints configured” 直接退出。请尽快替换为真实 API 配置。 |
将 ccNexus 转为无头 Docker 服务,反代后可跨平台