Go + PostgreSQL + Valkey backend (cmd/internal/migrations), uni-app mobile frontend, PC web (web/), admin console (admin/), Android WebView container (android_project/). Build artifacts, node_modules, local env and debug screenshots excluded.
35 lines
1002 B
Docker
35 lines
1002 B
Docker
# ── 构建阶段 ──
|
||
FROM golang:1.26-alpine AS builder
|
||
|
||
WORKDIR /src
|
||
|
||
# 先只拷依赖清单,让 module 缓存层在代码变更时失效
|
||
COPY go.mod go.sum ./
|
||
RUN go env -w GOPROXY=https://goproxy.cn,direct && go mod download
|
||
|
||
COPY . .
|
||
|
||
# CGO_ENABLED=0 产出静态二进制,运行时不需要任何系统库
|
||
# -trimpath 去掉绝对路径,-ldflags "-s -w" 去符号表,镜像小 30%
|
||
RUN CGO_ENABLED=0 GOOS=linux go build \
|
||
-trimpath -ldflags="-s -w" -o /out/api ./cmd/api && \
|
||
CGO_ENABLED=0 GOOS=linux go build \
|
||
-trimpath -ldflags="-s -w" -o /out/worker ./cmd/worker
|
||
|
||
# ── 运行阶段 ──
|
||
FROM alpine:3.20
|
||
|
||
# ca-certificates 用于访问对象存储/搜索服务的 HTTPS
|
||
RUN apk add --no-cache ca-certificates tzdata && \
|
||
adduser -D -u 10001 app
|
||
|
||
WORKDIR /app
|
||
COPY --from=builder /out/api /app/api
|
||
COPY --from=builder /out/worker /app/worker
|
||
|
||
USER app
|
||
EXPOSE 8080
|
||
|
||
# 默认跑 API;worker 通过 compose 的 command 覆盖
|
||
ENTRYPOINT ["/app/api"]
|