From a632bc73327f768321b6d9089007cd6086ed3a5e Mon Sep 17 00:00:00 2001 From: Song367 <601337784@qq.com> Date: Wed, 18 Jun 2025 13:23:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/deploy.yaml | 2 -- Dockerfile | 49 ++++++++---------------------------- docker-compose.yml | 2 -- file_server.py | 1 - 4 files changed, 10 insertions(+), 44 deletions(-) diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index d3fa33a..d9535bb 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -39,8 +39,6 @@ jobs: fi docker run -d --rm --name gong-zheng-api \ -v /usr/share/fonts/opentype/noto:/usr/share/fonts \ - -v $(pwd)/audio:/app/audio \ -p 6211:8080 \ - -p 6212:8000 \ gong-zheng-api:${{ gitea.run_id }} - run: echo "🍏 This job's status is ${{ job.status }}." \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index af214b0..aa543ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # 构建 Go 服务 FROM golang:1.21-alpine AS go-builder -WORKDIR /app +WORKDIR /usr/src/app # 安装必要的构建工具 RUN apk add --no-cache gcc musl-dev @@ -12,45 +12,16 @@ COPY . . # 构建 Go 服务 RUN go build -o main ./main.go -# 构建 Python 服务 -FROM python:3.11-slim +# 运行阶段 +FROM alpine:latest -WORKDIR /app +WORKDIR /usr/src/app -# 安装必要的系统依赖 -RUN apt-get update && apt-get install -y \ - ca-certificates \ - && rm -rf /var/lib/apt/lists/* +# 从构建阶段复制编译好的二进制文件 +COPY --from=go-builder /usr/src/app/main . -# 创建音频目录 -RUN mkdir -p /app/audio +# 暴露端口(根据你的 API 服务端口修改) +EXPOSE 8080 -# 复制 Python 文件服务器 -COPY file_server.py . - -# 从 go-builder 阶段复制编译好的 Go 服务 -COPY --from=go-builder /app/main . - -# 复制配置文件(如果有的话) -COPY --from=go-builder /app/config.yaml . - -# 设置环境变量 -ENV PORT=8000 -ENV GO_PORT=8080 - -# 创建启动脚本 -RUN echo '#!/bin/bash\n\ -# 启动 Go 服务\n\ -./main &\n\ -# 启动 Python 文件服务器\n\ -python file_server.py -p $PORT\n\ -' > /app/start.sh && chmod +x /app/start.sh - -# 暴露端口 -EXPOSE 8000 8080 - -# 设置工作目录 -WORKDIR /app - -# 启动服务 -CMD ["/app/start.sh"] \ No newline at end of file +# 运行服务 +CMD ["./main"] diff --git a/docker-compose.yml b/docker-compose.yml index 438640c..945b01f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,11 +4,9 @@ services: app: build: . ports: - - "8000:8000" # Python 文件服务器端口 - "8080:8080" # Go 服务端口 volumes: - ./audio:/app/audio # 挂载音频目录 environment: - - PORT=8000 - GO_PORT=8080 restart: unless-stopped \ No newline at end of file diff --git a/file_server.py b/file_server.py index 6669296..163f486 100644 --- a/file_server.py +++ b/file_server.py @@ -62,7 +62,6 @@ class FileHandler(http.server.SimpleHTTPRequestHandler): with open(file_path, 'rb') as f: self.send_response(200) self.send_header('Content-type', content_type) - self.send_header('Content-Disposition', f'attachment; filename="{os.path.basename(file_path)}"') self.end_headers() self.wfile.write(f.read()) except Exception as e: