-
Notifications
You must be signed in to change notification settings - Fork 317
Expand file tree
/
Copy pathDockerfile
More file actions
59 lines (41 loc) · 1.79 KB
/
Copy pathDockerfile
File metadata and controls
59 lines (41 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# --- 阶段 1: 准备 Bun 运行时(使用构建平台架构,避免 QEMU)---
FROM --platform=$BUILDPLATFORM oven/bun:alpine AS bun-runtime
# --- 阶段 2: 构建阶段(使用构建平台架构,Go 交叉编译目标平台)---
FROM --platform=$BUILDPLATFORM golang:1.25-alpine AS builder
ARG VERSION
ARG TARGETOS
ARG TARGETARCH
WORKDIR /src
RUN apk add --no-cache bash git make nodejs libstdc++ libgcc
COPY --from=bun-runtime /usr/local/bin/bun /usr/local/bin/bun
COPY --from=bun-runtime /usr/local/bin/bunx /usr/local/bin/bunx
ENV PATH="/usr/local/bin:${PATH}"
# 先复制依赖清单,安装依赖(源码变动不会触发重装)
COPY frontend/package.json frontend/bun.lock ./frontend/
RUN --mount=type=cache,target=/root/.bun/install/cache \
cd frontend && bun install --frozen-lockfile
COPY backend-go/go.mod backend-go/go.sum ./backend-go/
RUN --mount=type=cache,target=/go/pkg/mod \
cd backend-go && go mod download
# 复制全部源码(变动频繁,放在依赖层之后)
COPY Makefile ./
COPY scripts/ ./scripts/
COPY frontend/ ./frontend/
COPY backend-go/ ./backend-go/
COPY shared/ ./shared/
COPY VERSION ./
# 构建:交叉编译目标平台,利用 Go build cache
RUN --mount=type=cache,target=/root/.cache/go-build \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 GOMAXPROCS=2 \
GOFLAGS="-buildvcs=false -p=1" VERSION=${VERSION} make build
# --- 阶段 3: 运行时 ---
FROM alpine:latest AS runtime
WORKDIR /app
RUN apk --no-cache add ca-certificates tzdata
COPY --from=builder /src/dist/ccx-go /app/ccx
RUN mkdir -p /app/.config/backups /app/logs
ENV TZ=Asia/Shanghai
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1
CMD ["/app/ccx"]