Skip to content

Comments

Convert ccNexus to headless Docker service#61

Merged
lich0821 merged 1 commit intolich0821:masterfrom
ANIIAN91:docker-headless
Dec 15, 2025
Merged

Convert ccNexus to headless Docker service#61
lich0821 merged 1 commit intolich0821:masterfrom
ANIIAN91:docker-headless

Conversation

@ANIIAN91
Copy link
Contributor

将 ccNexus 转为无头 Docker 服务,反代后可跨平台

Copilot AI review requested due to automatic review settings December 14, 2025 16:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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..."
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines +36 to +38
volumes:
ccnexus-data:
driver: local
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
volumes:
ccnexus-data:
driver: local

Copilot uses AI. Check for mistakes.
COPY app/ ./

# Ensure module graph is complete (generates go.sum)
RUN go mod tidy
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
RUN go mod tidy

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +10
#!/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 "$@"
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

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 配置。
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in Chinese text: "示例 endpoint" should use consistent terminology. Consider using "端点" (endpoint) consistently in Chinese documentation or sticking with the English term throughout.

Suggested change
- 若存储中无任何 endpoint,会自动写入默认示例 endpoint,避免 “no endpoints configured” 直接退出。请尽快替换为真实 API 配置。
- 若存储中无任何 endpoint,会自动写入默认示例端点,避免 “no endpoints configured” 直接退出。请尽快替换为真实 API 配置。

Copilot uses AI. Check for mistakes.
@lich0821 lich0821 merged commit d74415e into lich0821:master Dec 15, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants