lolly/Dockerfile
xfy ada7357f7d feat(docker,server): 改进容器信号处理和优雅关闭
- 使用 tini 作为 PID 1 init 进程,处理僵尸进程回收和信号转发
- 多次 SIGINT (3次) 支持强制退出
- GoroutinePool.Stop() 添加 5s 超时等待,防止无限阻塞
- GracefulUpgrade 启动 goroutine 等待子进程,避免僵尸进程
- 关闭父进程文件描述符副本,防止泄漏

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 18:30:28 +08:00

59 lines
1.5 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ---- Builder stage ----
FROM golang:1.26-alpine AS builder
WORKDIR /build
# 安装构建依赖
RUN apk add --no-cache git make
# 依赖缓存层
COPY go.mod go.sum ./
RUN go mod download
# 构建参数(版本信息)
ARG VERSION=0.2.0
ARG GIT_COMMIT=unknown
ARG GIT_BRANCH=unknown
ARG BUILD_TIME=unknown
ARG GO_VERSION=unknown
ARG BUILD_PLATFORM=linux/amd64
# 构建
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build \
-ldflags="-s -w \
-X 'rua.plus/lolly/internal/app.Version=${VERSION}' \
-X 'rua.plus/lolly/internal/app.GitCommit=${GIT_COMMIT}' \
-X 'rua.plus/lolly/internal/app.GitBranch=${GIT_BRANCH}' \
-X 'rua.plus/lolly/internal/app.BuildTime=${BUILD_TIME}' \
-X 'rua.plus/lolly/internal/app.GoVersion=${GO_VERSION}' \
-X 'rua.plus/lolly/internal/app.BuildPlatform=${BUILD_PLATFORM}'" \
-trimpath \
-o /build/lolly \
main.go
# ---- Tini stage ----
FROM alpine:3.19 AS tini-stage
RUN apk add --no-cache tini-static
# ---- Runtime stage ----
FROM scratch
# CA 证书(出站 HTTPS 代理需要)
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# 二进制文件
COPY --from=builder /build/lolly /lolly
# tini 静态版本(处理 PID 1 僵尸进程回收和信号转发)
COPY --from=tini-stage /sbin/tini-static /tini
# 优雅关闭SIGQUIT 触发 30s graceful stop
STOPSIGNAL SIGQUIT
# HTTP/1.1, HTTP/2, HTTP/3 (QUIC)
EXPOSE 8080/tcp 443/tcp 443/udp
# 使用 tini 作为 init 进程PID 1
ENTRYPOINT ["/tini", "--"]
CMD ["/lolly", "-c", "/etc/lolly/lolly.yaml"]