-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
63 lines (45 loc) · 1.46 KB
/
Copy pathDockerfile
File metadata and controls
63 lines (45 loc) · 1.46 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
60
61
62
63
# ── 混天DB 统一 Docker 镜像 ──
# 单镜像多端口:
# 5408 — PostgreSQL Wire Protocol
# 5490 — Prometheus /metrics + /health + /ready
# 3000 — REST API + Web Portal (静态文件)
#
# 用法: docker run -p 5408:5408 -p 5490:5490 -p 3000:3000 huntiandb
# ── Stage 1: 后端构建 ──
FROM rust:1.88-alpine AS backend-builder
RUN apk add --no-cache musl-dev pkgconfig openssl-dev
WORKDIR /build
# 工作空间根配置
COPY Cargo.toml Cargo.lock ./
COPY backend/Cargo.toml backend/
COPY backend/src/ backend/src/
RUN cargo build --release --bin huntiandb && \
strip target/release/huntiandb
# ── Stage 2: 前端构建 ──
FROM oven/bun:1-alpine AS frontend-builder
WORKDIR /build
COPY frontend/package.json frontend/bun.lock ./
RUN bun install --frozen-lockfile
COPY frontend/ ./
RUN bun run build
# ── Stage 3: 运行时 ──
FROM alpine:3.21
RUN apk add --no-cache libgcc ca-certificates tzdata curl && \
adduser -D -h /app huntian
USER huntian
WORKDIR /app
# 后端二进制
COPY --from=backend-builder /build/target/release/huntiandb /app/
# 前端静态文件
COPY --from=frontend-builder /build/dist /app/static
RUN mkdir -p /app/data
ENV DATA_DIR=/app/data
ENV STATIC_DIR=/app/static
ENV REST_PORT=3000
ENV METRICS_PORT=5490
ENV POSTGRES_PORT=5408
ENV RUST_LOG=info
EXPOSE 5408 3000 5490
HEALTHCHECK --interval=10s --timeout=5s --retries=3 \
CMD curl -f http://localhost:3000/api/health || exit 1
CMD ["./huntiandb"]