41 lines
1.1 KiB
Docker
41 lines
1.1 KiB
Docker
# soul-api Docker 镜像
|
||
# 多阶段构建:编译 Go 二进制 → 精简运行镜像
|
||
# 构建:在 soul-api 根目录执行 docker build -f deploy/Dockerfile -t soul-api:latest .
|
||
# 运行:见 docker-compose.production.yml
|
||
|
||
# ========== 阶段 1:编译 ==========
|
||
# 使用本地已缓存的 golang:1.25;deploy.py 加 --pull=false 避免拉取
|
||
FROM golang:1.25 AS builder
|
||
|
||
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates git && rm -rf /var/lib/apt/lists/*
|
||
|
||
WORKDIR /build
|
||
COPY go.mod go.sum ./
|
||
RUN go mod download
|
||
|
||
COPY . .
|
||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
|
||
-ldflags="-w -s" -o /build/soul-api ./cmd/server
|
||
|
||
# ========== 阶段 2:运行 ==========
|
||
# 使用标准引用 alpine:3.19,配合 --pull=false 可使用本地已缓存的镜像
|
||
FROM alpine:3.19
|
||
|
||
RUN apk add --no-cache ca-certificates tzdata wget
|
||
ENV TZ=Asia/Shanghai
|
||
|
||
RUN adduser -D -g '' appuser
|
||
WORKDIR /app
|
||
|
||
COPY --from=builder /build/soul-api .
|
||
COPY certs/ /app/certs/
|
||
|
||
ARG ENV_FILE=.env.production
|
||
COPY ${ENV_FILE} /app/.env
|
||
|
||
RUN mkdir -p /app/uploads && chown -R appuser:appuser /app
|
||
USER appuser
|
||
|
||
EXPOSE 8080
|
||
ENTRYPOINT ["./soul-api"]
|