File size: 1,381 Bytes
cd00f98
 
793bc3b
 
acab921
 
793bc3b
 
 
 
acab921
cd00f98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
acab921
 
793bc3b
 
cd00f98
793bc3b
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# 使用固定架构的基础镜像而不是动态平台
FROM rustlang/rust:nightly-bookworm-slim as builder

WORKDIR /app

# 安装依赖
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    build-essential protobuf-compiler pkg-config libssl-dev nodejs npm openssl \
    && rm -rf /var/lib/apt/lists/*

# 复制整个项目
COPY . .

# 检查项目结构并构建
RUN if [ ! -f Cargo.toml ]; then \
    echo "Error: Cargo.toml not found in project root" && exit 1; \
    fi && \
    # 根据当前CPU架构选择优化标志
    ARCH=$(uname -m) && \
    if [ "$ARCH" = "x86_64" ]; then \
        TARGET_CPU="x86-64-v2"; \
    elif [ "$ARCH" = "aarch64" ]; then \
        TARGET_CPU="neoverse-n1"; \
    else \
        echo "Unsupported architecture: $ARCH" && exit 1; \
    fi && \
    RUSTFLAGS="-C link-arg=-s -C target-cpu=$TARGET_CPU" cargo +nightly build --release && \
    cp target/release/cursor-api /app/cursor-api

# 运行阶段
FROM debian:bookworm-slim

WORKDIR /app
ENV TZ=Asia/Shanghai
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    ca-certificates tzdata openssl \
    && rm -rf /var/lib/apt/lists/* && \
    groupadd -r cursorapi && useradd -r -g cursorapi cursorapi
COPY --from=builder /app/cursor-api .
RUN chown -R cursorapi:cursorapi /app
ENV PORT=3000
EXPOSE ${PORT}
USER cursorapi
CMD ["./cursor-api"]