From 9366c9210e403022486060ad6aebbfebf3b18e56 Mon Sep 17 00:00:00 2001 From: yw1573 Date: Thu, 9 Apr 2026 10:26:22 +0800 Subject: [PATCH] feat: add Docker deployment configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 Docker 部署支持: - Dockerfile: 多阶段构建,包含 ffmpeg 依赖 - docker-compose.yml: 配置端口映射和持久化目录 - .dockerignore: 优化构建上下文 Co-Authored-By: AI --- .dockerignore | 31 +++++++++++++++++++++++++++++++ Dockerfile | 43 +++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 24 ++++++++++++++++++++++++ 3 files changed, 98 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..edd77a4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,31 @@ +# 忽略构建产物 +build/ +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# 忽略开发文件 +.git/ +.gitignore +.vscode/ +.idea/ +*.md +!README.md + +# 忽略 node_modules +web/node_modules/ + +# 忽略数据文件 +data/ +downloads/ +*.db +*.db-journal + +# 忽略临时文件 +*.log +*.tmp +*.swp +*.swo +*~ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8f08c4d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +# 构建阶段 +FROM golang:1.23-alpine AS builder + +# 安装构建依赖 +RUN apk add --no-cache git gcc musl-dev + +WORKDIR /app + +# 复制 go mod 文件 +COPY go.mod go.sum ./ +RUN go mod download + +# 复制源代码 +COPY . . + +# 构建二进制文件 +RUN CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w" -o bilidown ./cmd/bilidown + +# 运行阶段 +FROM alpine:3.19 + +# 安装运行时依赖 +RUN apk add --no-cache ca-certificates tzdata ffmpeg + +# 设置时区(默认上海) +ENV TZ=Asia/Shanghai + +WORKDIR /app + +# 从构建阶段复制二进制文件 +COPY --from=builder /app/bilidown . + +# 创建数据目录 +RUN mkdir -p /app/data /app/downloads + +# 暴露端口 +EXPOSE 8098 + +# 设置环境变量 +ENV GIN_MODE=release + +# 启动服务 +CMD ["./bilidown"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..51e808e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +services: + bilidown: + build: + context: . + dockerfile: Dockerfile + image: bilidown:latest + container_name: bilidown + restart: unless-stopped + ports: + - "8098:8098" + volumes: + # 数据库持久化 + - ./data:/app/data + # 下载目录 + - ./downloads:/app/downloads + environment: + - TZ=Asia/Shanghai + - GIN_MODE=release + healthcheck: + test: ["CMD", "wget", "-q", "--spider", "http://127.0.0.1:8098/"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 10s