修改dockerfile
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 4m45s

This commit is contained in:
Song367 2025-06-18 13:23:08 +08:00
parent cae827e801
commit a632bc7332
4 changed files with 10 additions and 44 deletions

View File

@ -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 }}."

View File

@ -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"]
# 运行服务
CMD ["./main"]

View File

@ -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

View File

@ -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: