Repository navigation
feat: add Docker packaging support - #6
Conversation
There was a problem hiding this comment.
Pull request overview
Adds container packaging and run documentation for this Go service so it can be built and started via Docker/Docker Compose with a mounted config.json.
Changes:
- Added a multi-stage
Dockerfileto build and run thecmd/geminiweb2apibinary in a minimal runtime image - Added
docker-compose.yml,.dockerignore, and aconfig.json.examplefor container startup - Updated
README.mdandZH_CN.mdwith Docker build/run/compose instructions
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| Dockerfile | Multi-stage build and runtime image definition for the service |
| docker-compose.yml | Compose service definition to build and run the container with config bind-mount |
| .dockerignore | Reduces Docker build context (excludes git metadata, local config, etc.) |
| config.json.example | Provides a starter config for users to copy/mount into the container |
| README.md | Documents Docker build/run/compose usage (English) |
| ZH_CN.md | Documents Docker build/run/compose usage (Chinese) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 挂载本地 `config.json` 运行容器: | ||
|
|
||
| ```bash | ||
| docker run -d \ | ||
| --name geminiweb2api \ | ||
| -p 8080:8080 \ | ||
| -v $(pwd)/config.json:/app/config.json \ | ||
| geminiweb2api:latest |
There was a problem hiding this comment.
docker run 示例里直接挂载 ./config.json,但没有提示先创建该文件。如果宿主机上不存在 config.json,Docker 往往会在该路径创建一个“同名目录”并挂载到 /app/config.json,导致程序读取配置时报错。建议在运行命令前补充一步(例如从 config.json.example 复制)。
| @@ -0,0 +1,25 @@ | |||
| FROM golang:1.25-alpine AS builder | |||
There was a problem hiding this comment.
The builder image is pinned to golang:1.25-alpine, but go.mod declares go 1.25.5. Using different patch versions can lead to subtle build differences and makes reproducing builds harder. Consider pinning the Docker builder image to the same patch level (or introducing a single ARG GO_VERSION used by both tooling/docs).
| FROM golang:1.25-alpine AS builder | |
| FROM golang:1.25.5-alpine AS builder |
| RUN apk add --no-cache ca-certificates tzdata && update-ca-certificates | ||
|
|
||
| COPY --from=builder /out/geminiweb2api /app/geminiweb2api | ||
|
|
||
| EXPOSE 8080 | ||
|
|
||
| VOLUME ["/app"] | ||
|
|
There was a problem hiding this comment.
The runtime image runs as root by default. For a network-exposed service, it’s safer to create a dedicated user/group and USER it in the final stage (ensuring /app is readable/executable). This reduces impact if the process is compromised.
| RUN apk add --no-cache ca-certificates tzdata && update-ca-certificates | |
| COPY --from=builder /out/geminiweb2api /app/geminiweb2api | |
| EXPOSE 8080 | |
| VOLUME ["/app"] | |
| RUN apk add --no-cache ca-certificates tzdata && update-ca-certificates \ | |
| && addgroup -S app \ | |
| && adduser -S -G app -h /app app | |
| COPY --from=builder --chown=app:app /out/geminiweb2api /app/geminiweb2api | |
| EXPOSE 8080 | |
| VOLUME ["/app"] | |
| USER app:app |
| -e HTTP_PROXY=http://host.docker.internal:7890 \ | ||
| -e HTTPS_PROXY=http://host.docker.internal:7890 \ | ||
| geminiweb2api:latest |
There was a problem hiding this comment.
The proxy example uses host.docker.internal, which works on Docker Desktop but isn’t available by default on many Linux setups. Consider noting the Linux alternative (e.g., --add-host=host.docker.internal:host-gateway or using the host’s IP) so users don’t get a confusing proxy connection failure.
|
|
||
| COPY . . | ||
|
|
||
| RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o /out/geminiweb2api ./cmd/geminiweb2api |
There was a problem hiding this comment.
The build step hard-codes GOARCH=amd64. On ARM hosts (e.g., Apple Silicon), docker build will produce an amd64 binary but the final alpine stage will default to arm64, leading to an "exec format error" at runtime. Consider using BuildKit’s TARGETOS/TARGETARCH (and --platform) or removing the hard-coded GOARCH so the binary matches the target platform.
| VOLUME ["/app"] | ||
|
|
There was a problem hiding this comment.
VOLUME ["/app"] will create an anonymous volume on container start, which can leave orphaned volumes on repeated runs and can surprise users when inspecting/removing containers. Since the documented usage bind-mounts only /app/config.json, consider removing the VOLUME declaration (or scoping persistence to a dedicated data directory if needed).
| VOLUME ["/app"] |
| Run with a local `config.json` mounted into the container: | ||
|
|
||
| ```bash | ||
| docker run -d \ | ||
| --name geminiweb2api \ | ||
| -p 8080:8080 \ | ||
| -v $(pwd)/config.json:/app/config.json \ | ||
| geminiweb2api:latest |
There was a problem hiding this comment.
The docker run example bind-mounts ./config.json into the container, but it doesn’t mention creating that file first. If config.json doesn’t exist on the host, Docker will typically create a directory at that path and mount it to /app/config.json, causing the app’s config load to fail. Consider adding a short step before the run command (e.g., copy from config.json.example).
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: chanhanzhan <174212802+chanhanzhan@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: chanhanzhan <174212802+chanhanzhan@users.noreply.github.com>
Summary