athunderx / Dockerfile
Mr.L
refactor: optimize Dockerfile build cache by separating dependency download
ff2ab3b
# 用于 Hugging Face Space 部署的alists主Dockerfile
FROM golang:1.21-alpine AS build
WORKDIR /build
# 复制 go.mod 和 go.sum 以利用 Docker 缓存
COPY go.mod go.sum ./
RUN apk add --no-cache git && go mod download
# 复制剩余源码并编译
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /app/alist main.go
# 生产阶段
FROM alpine:3.19
WORKDIR /app
# 拷贝可执行文件和入口脚本
COPY --from=build /app/alist /app/alist
COPY entrypoint.sh /app/entrypoint.sh
# 可选:拷贝必要的静态资源等,如果需要可用以下行
# COPY public /app/public
# COPY config /app/config
# 必须赋予启动脚本可执行
RUN chmod +x /app/entrypoint.sh
# 端口,Hugging Face Space 默认探测
EXPOSE 7860
# HEALTHCHECK:确保平台探测健康,默认 get /ping (alist部分版本支持)可按需调整
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 CMD wget -qO- http://localhost:7860/ping || exit 1
# 入口
ENTRYPOINT ["/app/entrypoint.sh"]