From cf81290ae773a851996fcda0f7110cafc4e6924b Mon Sep 17 00:00:00 2001 From: 1iaan Date: Fri, 10 Apr 2026 09:22:50 +0000 Subject: [PATCH] docker fix --- ai-chat-backend/Dockerfile | 48 +++++++++++++++++++++++++++----------- ai-chat-service/Dockerfile | 16 +++++++------ ai-chat-stack/compose.yaml | 12 +++++----- ai-chat-web/.dockerignore | 4 +++- ai-chat-web/Dockerfile | 16 +++++++++---- keywords-filter/Dockerfile | 47 +++++++++++++++++++++++++++---------- tokenizer/Dockerfile | 20 +++++++++++----- 7 files changed, 114 insertions(+), 49 deletions(-) diff --git a/ai-chat-backend/Dockerfile b/ai-chat-backend/Dockerfile index 7ff19c2..95fbfb9 100644 --- a/ai-chat-backend/Dockerfile +++ b/ai-chat-backend/Dockerfile @@ -1,19 +1,41 @@ # 编译阶段 -FROM golang:1.24 AS stage0 -RUN go env -w GOPROXY=https://proxy.golang.com.cn,https://goproxy.cn,direct -ADD ./ /src/ai-chat-backend -WORKDIR /src/ai-chat-backend -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ai-chat-backend cmd/*.go +FROM golang:1.24 AS builder -FROM alpine:3.18 AS stage1 -ADD ./curl-amd64 /usr/bin/curl +ENV CGO_ENABLED=0 \ + GOOS=linux \ + GOARCH=amd64 \ + GOPROXY=https://goproxy.cn|https://proxy.golang.google.cn|direct \ + GOSUMDB=sum.golang.google.cn + +WORKDIR /src/ai-chat-backend + +# 先复制依赖描述文件,最大化利用缓存 +COPY go.mod go.sum ./ + +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + go mod download -x + +# 再复制源码 +COPY . . + +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + go build -trimpath -ldflags="-s -w" -o /out/ai-chat-backend ./cmd + +# 运行阶段 +FROM alpine:3.18 AS runtime + +COPY ./curl-amd64 /usr/bin/curl RUN chmod +x /usr/bin/curl + LABEL maintainer="nick" + WORKDIR /app/ -ADD ./dev.config.yaml /app/config.yaml -ADD ./www /app/www -COPY --from=stage0 /src/ai-chat-backend/ai-chat-backend ./ -# 指定入口程序 + +COPY ./dev.config.yaml /app/config.yaml +COPY ./www /app/www +COPY --from=builder /out/ai-chat-backend ./ai-chat-backend + ENTRYPOINT ["./ai-chat-backend"] -# 指定容器的启动命令或者入口程序的参数 -CMD ["--config=config.yaml"] +CMD ["--config=config.yaml"] \ No newline at end of file diff --git a/ai-chat-service/Dockerfile b/ai-chat-service/Dockerfile index 7314e9b..563f546 100644 --- a/ai-chat-service/Dockerfile +++ b/ai-chat-service/Dockerfile @@ -1,22 +1,24 @@ FROM golang:1.25 AS builder -ENV GOPROXY=https://proxy.golang.com.cn,https://goproxy.cn,direct \ - GOSUMDB=sum.golang.google.cn \ - CGO_ENABLED=0 \ +ENV CGO_ENABLED=0 \ GOOS=linux \ - GOARCH=amd64 + GOARCH=amd64 \ + GOPROXY=https://goproxy.cn|https://proxy.golang.google.cn|direct \ + GOSUMDB=sum.golang.google.cn WORKDIR /src/ai-chat-service COPY go.mod go.sum ./ + RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ - go mod download + go mod download -x COPY . . + RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ - go build -o /out/ai-chat-service ./chat-server + go build -trimpath -ldflags="-s -w" -o /out/ai-chat-service ./chat-server FROM alpine:3.18 @@ -31,4 +33,4 @@ COPY --from=builder /out/ai-chat-service ./ai-chat-service COPY ./docker.config.yaml /app/config.yaml ENTRYPOINT ["./ai-chat-service"] -CMD ["--config=config.yaml"] +CMD ["--config=config.yaml"] \ No newline at end of file diff --git a/ai-chat-stack/compose.yaml b/ai-chat-stack/compose.yaml index 6212e50..fc1694c 100644 --- a/ai-chat-stack/compose.yaml +++ b/ai-chat-stack/compose.yaml @@ -45,8 +45,8 @@ services: image: keywords-filter:1.0.0 container_name: sensitive-filter volumes: - - /home/lian/share/aichat/ai-chat-stack/configs/sensitive.yaml:/app/config.yaml:ro - - /home/lian/share/aichat/ai-chat-stack/configs/sensitive-dict.txt:/app/dict.txt:ro + - ./configs/sensitive.yaml:/app/config.yaml:ro + - ./configs/sensitive-dict.txt:/app/dict.txt:ro command: - --config=/app/config.yaml - --dict=/app/dict.txt @@ -60,8 +60,8 @@ services: image: keywords-filter:1.0.0 container_name: keywords-filter volumes: - - /home/lian/share/aichat/ai-chat-stack/configs/keywords.yaml:/app/config.yaml:ro - - /home/lian/share/aichat/ai-chat-stack/configs/keywords-dict.txt:/app/dict.txt:ro + - ./configs/keywords.yaml:/app/config.yaml:ro + - ./configs/keywords-dict.txt:/app/dict.txt:ro command: - --config=/app/config.yaml - --dict=/app/dict.txt @@ -77,7 +77,7 @@ services: env_file: - .env volumes: - - /home/lian/share/aichat/ai-chat-stack/configs/ai-chat-service.yaml:/app/config.yaml:ro + - ./configs/ai-chat-service.yaml:/app/config.yaml:ro extra_hosts: - "host.docker.internal:host-gateway" ports: @@ -103,7 +103,7 @@ services: ports: - "7080:7080" volumes: - - /home/lian/share/aichat/ai-chat-stack/configs/ai-chat-backend.yaml:/app/config.yaml:ro + - ./configs/ai-chat-backend.yaml:/app/config.yaml:ro depends_on: - ai-chat-service restart: unless-stopped diff --git a/ai-chat-web/.dockerignore b/ai-chat-web/.dockerignore index 7d1a4cf..a7dd0ef 100644 --- a/ai-chat-web/.dockerignore +++ b/ai-chat-web/.dockerignore @@ -2,7 +2,9 @@ */node_modules node_modules Dockerfile -.* +*.pyc +*.pyo +*.log */.* !.env !.env.production diff --git a/ai-chat-web/Dockerfile b/ai-chat-web/Dockerfile index 8a26ba9..4c8a993 100644 --- a/ai-chat-web/Dockerfile +++ b/ai-chat-web/Dockerfile @@ -1,15 +1,23 @@ +# syntax=docker/dockerfile:1.7 + FROM quay.io/0voice/node:lts-alpine AS frontend -RUN npm install pnpm -g + WORKDIR /app +RUN npm install -g pnpm@8 + COPY package.json pnpm-lock.yaml .npmrc ./ -RUN pnpm install --frozen-lockfile + +RUN --mount=type=cache,target=/root/.local/share/pnpm/store \ + pnpm install --frozen-lockfile COPY . . + RUN pnpm run build-only FROM quay.io/0voice/nginx:1.25.4 AS web + COPY ./docker/nginx/default.conf /etc/nginx/conf.d/default.conf COPY --from=frontend /app/dist/ /usr/share/nginx/html/ -ENTRYPOINT ["/docker-entrypoint.sh"] -CMD ["nginx", "-g", "daemon off;"] + +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/keywords-filter/Dockerfile b/keywords-filter/Dockerfile index 922225a..160cf86 100644 --- a/keywords-filter/Dockerfile +++ b/keywords-filter/Dockerfile @@ -1,15 +1,38 @@ -# 编译阶段 -FROM quay.io/0voice/golang:1.20 as stage0 -RUN go env -w GOPROXY=https://proxy.golang.com.cn,https://goproxy.cn,direct -ADD ./ /src/keywords-filter -WORKDIR /src/keywords-filter -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o keywords-filter ./filter-server +# syntax=docker/dockerfile:1.7 -FROM quay.io/0voice/alpine:3.18 as stage1 -ADD ./grpc_health_probe-linux-amd64 /usr/bin/grpc_health_probe +# 编译阶段 +FROM quay.io/0voice/golang:1.20 AS builder + +ENV CGO_ENABLED=0 \ + GOOS=linux \ + GOARCH=amd64 \ + GOPROXY=https://goproxy.cn|https://proxy.golang.google.cn|direct \ + GOSUMDB=sum.golang.google.cn + +WORKDIR /src/keywords-filter + +COPY go.mod go.sum ./ + +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + go mod download -x + +COPY . . + +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + go build -trimpath -ldflags="-s -w" -o /out/keywords-filter ./filter-server + +# 运行阶段 +FROM quay.io/0voice/alpine:3.18 AS runtime + +COPY ./grpc_health_probe-linux-amd64 /usr/bin/grpc_health_probe RUN chmod +x /usr/bin/grpc_health_probe -MAINTAINER nick + +LABEL maintainer="nick" + WORKDIR /app/ -COPY --from=stage0 /src/keywords-filter/keywords-filter ./ -# 指定入口程序 -ENTRYPOINT ["./keywords-filter"] + +COPY --from=builder /out/keywords-filter ./keywords-filter + +ENTRYPOINT ["./keywords-filter"] \ No newline at end of file diff --git a/tokenizer/Dockerfile b/tokenizer/Dockerfile index d319e95..8117db0 100644 --- a/tokenizer/Dockerfile +++ b/tokenizer/Dockerfile @@ -1,11 +1,19 @@ +# syntax=docker/dockerfile:1.7 + FROM quay.io/0voice/python:3.10-alpine + WORKDIR /app -ENV PORT 3002 -ADD ./tokenizer.py /app -ADD ./requirements.txt /app +ENV PORT=3002 \ + PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple \ + PIP_TRUSTED_HOST=pypi.tuna.tsinghua.edu.cn -RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn --upgrade pip -RUN pip install --root-user-action=ignore -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r requirements.txt +COPY requirements.txt ./ -CMD ["sh","-c","nuxt --port ${PORT} --module tokenizer.py --workers 2"] \ No newline at end of file +RUN --mount=type=cache,target=/root/.cache/pip \ + python -m pip install --upgrade pip && \ + python -m pip install --root-user-action=ignore -r requirements.txt + +COPY tokenizer.py ./ + +CMD ["sh", "-c", "nuxt --port ${PORT} --module tokenizer.py --workers 2"] \ No newline at end of file