From e5cf1c348c75885c01f68a07aa2c56e815efa4c5 Mon Sep 17 00:00:00 2001 From: Hua Date: Sun, 27 Apr 2025 10:55:38 +0800 Subject: [PATCH] docker --- .dockerignore | 4 ++++ Dockerfile | 35 +++++++++++++++++++++++++++++++++++ docker-compose.yml | 17 +++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b7dab24 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +config.yaml +config.yaml.bak +.idea/ +.git/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e9f68bc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +FROM golang:1.22-alpine AS builder + +WORKDIR /app + +# 复制go.mod和go.sum文件 +COPY go.mod go.sum ./ + +# 下载依赖 +RUN go mod download + +# 复制源代码 +COPY . . + +# 构建应用 +RUN CGO_ENABLED=0 GOOS=linux go build -o /app/ai-code-review + +# 使用轻量级的基础镜像 +FROM alpine:latest + +WORKDIR /app + +# 从构建阶段复制二进制文件 +COPY --from=builder /app/ai-code-review /app/ + +# 创建默认配置文件到临时位置 +RUN echo 'port: 53321\nadmin_token: "token"\n\nauto_disable:\n enabled: true\n max_failures: 3\n reset_after: 30\n\nais: []\n\ngit: []' > /app/config.default.yaml + +# 暴露端口 +EXPOSE 53321 + +# 设置卷挂载点 +VOLUME ["/app/config.yaml"] + +# 运行应用,如果配置文件不存在则使用默认配置 +CMD ["sh", "-c", "if [ ! -f /app/config.yaml ]; then cp /app/config.default.yaml /app/config.yaml; fi && /app/ai-code-review"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..606bcf7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: '3.8' + +services: + ai-code-review: +# image: ai-code-review:lasted + build: + context: . + dockerfile: Dockerfile + container_name: ai-code-review + ports: + - "53321:53321" +# volumes: +# # 如果需要使用自定义配置文件,取消下面的注释并修改路径 +# - ./config.yaml:/app/config.yaml + restart: unless-stopped + environment: + - TZ=Asia/Shanghai \ No newline at end of file