-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.query-api
More file actions
57 lines (40 loc) · 1.6 KB
/
Dockerfile.query-api
File metadata and controls
57 lines (40 loc) · 1.6 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
# Stage 1: Build
FROM rust:1.88-slim-bookworm AS builder
# Install build dependencies
RUN apt-get update && apt-get install -y pkg-config libssl-dev python3 python3-dev && rm -rf /var/lib/apt/lists/*
WORKDIR /app
# ---------- 配置国内 Cargo 镜像 ----------
ENV RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
ENV RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
RUN mkdir -p /usr/local/cargo/registry && \
printf '[source.crates-io]\nreplace-with = "mirror"\n\n[source.mirror]\nregistry = "sparse+https://rsproxy.cn/index/"\n' > /usr/local/cargo/config.toml
# -----------------------------------------
# 告诉 PyO3 使用哪个 Python 解释器
ENV PYO3_PYTHON=python3
# Copy the entire workspace
COPY . .
# Build the query-api binary
RUN cargo build --release -p erc-query-api
# Stage 2: Runtime
FROM debian:bookworm-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y libssl3 ca-certificates curl && rm -rf /var/lib/apt/lists/*
# Copy the compiled binary
COPY --from=builder /app/target/release/erc-query-api /usr/local/bin/erc-query-api
# Copy public directory for static files
COPY --from=builder /app/public /usr/local/bin/public
# Create non-root user
RUN useradd -m -s /bin/bash erc
# Create data directory
RUN mkdir -p /home/erc/data && chown erc:erc /home/erc/data
# Switch to non-root user
USER erc
# Set working directory
WORKDIR /home/erc
# Expose port
EXPOSE 8082
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8082/health || exit 1
# Entry point
ENTRYPOINT ["erc-query-api"]