feat: add Docker deployment configuration

添加 Docker 部署支持:
- Dockerfile: 多阶段构建,包含 ffmpeg 依赖
- docker-compose.yml: 配置端口映射和持久化目录
- .dockerignore: 优化构建上下文

Co-Authored-By: AI
This commit is contained in:
2026-04-09 10:26:22 +08:00
parent e8f71b04ac
commit 9366c9210e
3 changed files with 98 additions and 0 deletions
+31
View File
@@ -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
*~
+43
View File
@@ -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"]
+24
View File
@@ -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