feat(docker): 添加容器化部署支持
- Dockerfile: 多阶段构建,最小化镜像体积(scratch) - docker-compose.yml: 开发环境配置,含健康检查 - .dockerignore: 排除不必要的构建上下文 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
2def9817d8
commit
55c05ec41d
78
.dockerignore
Normal file
78
.dockerignore
Normal file
@ -0,0 +1,78 @@
|
||||
# Build artifacts
|
||||
bin/
|
||||
dist/
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Go cache and modules
|
||||
vendor/
|
||||
|
||||
# Test artifacts
|
||||
*.test
|
||||
*.out
|
||||
coverage.html
|
||||
coverage.out
|
||||
|
||||
# IDE and editor
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# OS generated
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
._*
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
# Environment and secrets
|
||||
.env
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
logs/
|
||||
|
||||
# Temporary
|
||||
tmp/
|
||||
temp/
|
||||
|
||||
# Claude/OMC state
|
||||
.omc/
|
||||
.claude/
|
||||
CLAUDE.md
|
||||
|
||||
# Git submodule (large)
|
||||
lua-nginx-module/
|
||||
|
||||
# Development configs (use production configs in container)
|
||||
lolly.yaml
|
||||
config.yaml
|
||||
|
||||
# Compiled binary (will be built in container)
|
||||
lolly
|
||||
|
||||
# Benchmark and profiling data
|
||||
default.pgo
|
||||
benchmark-*.txt
|
||||
|
||||
# Documentation (not needed in runtime)
|
||||
docs/
|
||||
|
||||
# Scripts (not needed in runtime)
|
||||
scripts/
|
||||
|
||||
# HTML test directory
|
||||
html/
|
||||
|
||||
# Git
|
||||
.git/
|
||||
.gitignore
|
||||
51
Dockerfile
Normal file
51
Dockerfile
Normal file
@ -0,0 +1,51 @@
|
||||
# ---- 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
|
||||
|
||||
# ---- Runtime stage ----
|
||||
FROM scratch
|
||||
|
||||
# CA 证书(出站 HTTPS 代理需要)
|
||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
|
||||
# 二进制文件
|
||||
COPY --from=builder /build/lolly /lolly
|
||||
|
||||
# 优雅关闭:SIGQUIT 触发 30s graceful stop
|
||||
STOPSIGNAL SIGQUIT
|
||||
|
||||
# HTTP/1.1, HTTP/2, HTTP/3 (QUIC)
|
||||
EXPOSE 8080/tcp 443/tcp 443/udp
|
||||
|
||||
ENTRYPOINT ["/lolly"]
|
||||
CMD ["-c", "/etc/lolly/lolly.yaml"]
|
||||
41
docker-compose.yml
Normal file
41
docker-compose.yml
Normal file
@ -0,0 +1,41 @@
|
||||
services:
|
||||
lolly:
|
||||
build: .
|
||||
# 防止僵尸进程(lolly 无 PID 1 处理)
|
||||
init: true
|
||||
ports:
|
||||
- "8080:8080"
|
||||
# HTTP/3 (QUIC) - 需要 SSL 证书
|
||||
# - "443:443/tcp"
|
||||
# - "443:443/udp"
|
||||
volumes:
|
||||
- ./lolly.yaml:/etc/lolly/lolly.yaml:ro
|
||||
# 静态文件目录
|
||||
- ./html:/var/www/html:ro
|
||||
# SSL 证书(可选)
|
||||
# - ./certs:/etc/lolly/certs:ro
|
||||
# 日志持久化(可选)
|
||||
# - ./logs:/var/log/lolly
|
||||
environment:
|
||||
# 配合容器内存限制设置 GC 目标
|
||||
- GOMEMLIMIT=750MiB
|
||||
# 资源限制(可选)
|
||||
# deploy:
|
||||
# resources:
|
||||
# limits:
|
||||
# memory: 1G
|
||||
# reservations:
|
||||
# memory: 256M
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -q --spider http://localhost:8080/_status || exit 1"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 10s
|
||||
|
||||
# 示例后端服务(用于反向代理测试)
|
||||
# backend:
|
||||
# image: nginx:alpine
|
||||
# ports:
|
||||
# - "8000:80"
|
||||
Loading…
x
Reference in New Issue
Block a user