From 5e0d479640975b94560e8fe9f053ba5c1c81c7e5 Mon Sep 17 00:00:00 2001 From: mlogclub Date: Sat, 23 May 2026 22:50:07 +0800 Subject: [PATCH] feat: add Dockerfile and update README with Docker usage instructions --- .dockerignore | 28 ++++++++++++++++++++++++++++ Dockerfile | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 16 ++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c44b5d0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,28 @@ +.git +.gitmodules +.DS_Store +.idea +.vscode +.worktrees +.superpowers + +Dockerfile +dist +data +qdrant +*.log +__debug_bin* + +config/config.yaml + +node_modules +.pnpm-store + +web/node_modules +web/.next +web/out +web/coverage +web/tsconfig.tsbuildinfo +web/next-env.d.ts +web/.env* +!web/.env.example diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8adfe90 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +# syntax=docker/dockerfile:1.7 + +FROM node:24-alpine AS web-builder +WORKDIR /src/web + +RUN corepack enable && corepack prepare pnpm@10.30.2 --activate +COPY web/package.json web/pnpm-lock.yaml web/pnpm-workspace.yaml ./ +RUN --mount=type=cache,target=/root/.local/share/pnpm/store \ + pnpm install --frozen-lockfile + +COPY web/ ./ +RUN pnpm build:sdk && pnpm build + +FROM golang:1.26-alpine AS server-builder +WORKDIR /src + +RUN apk add --no-cache git +COPY go.mod go.sum ./ +RUN --mount=type=cache,target=/go/pkg/mod \ + go mod download + +COPY . ./ +COPY --from=web-builder /src/web/out ./web/out + +ARG TARGETOS=linux +ARG TARGETARCH +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -v -trimpath -ldflags="-s -w" -o /out/cs-agent ./cmd/server + +FROM alpine:3.22 AS app +WORKDIR /app + +ENV TZ=Asia/Shanghai + +RUN apk add --no-cache ca-certificates tzdata wget \ + && mkdir -p /app/config /app/data/storage + +COPY --from=server-builder /out/cs-agent /app/cs-agent +COPY config/config.example.yaml /app/config/config.example.yaml +COPY config/config.example.yaml /app/config/config.yaml + +EXPOSE 8083 +VOLUME ["/app/data"] + +HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \ + CMD wget -qO- http://127.0.0.1:8083/ >/dev/null || exit 1 + +CMD ["/app/cs-agent", "-config", "/app/config/config.yaml"] diff --git a/README.md b/README.md index 9826a71..784fbcb 100644 --- a/README.md +++ b/README.md @@ -278,6 +278,22 @@ make enums # 生成前端枚举 make migration # 执行 migration ``` +## Docker + +```bash +docker build -t cs-agent . +docker run --rm -p 8083:8083 -v cs-agent-data:/app/data cs-agent +``` + +容器默认使用 `/app/config/config.yaml`,镜像内会基于 `config/config.example.yaml` 放置一份默认配置。生产环境建议通过挂载配置文件覆盖: + +```bash +docker run --rm -p 8083:8083 \ + -v $(pwd)/config/config.yaml:/app/config/config.yaml:ro \ + -v cs-agent-data:/app/data \ + cs-agent +``` + ## 系统视角 - 管理后台:负责 AI Agent、知识库、客服组、工单与运营配置