Spaces:
Build error
Build error
File size: 1,815 Bytes
cd00f98 793bc3b acab921 793bc3b acab921 bcbf675 cd00f98 bcbf675 cd00f98 bcbf675 793bc3b cd00f98 793bc3b bcbf675 793bc3b bcbf675 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
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/*
# 先复制Cargo配置和构建相关文件
COPY Cargo.toml Cross.toml* build.rs* .gitattributes* ./
COPY .cargo /.cargo/
# 创建基本src目录结构以利用缓存
RUN mkdir -p src && \
echo "fn main() {println!(\"placeholder\");}" > src/main.rs
# 尝试获取依赖(如果可能)
RUN cargo fetch || true
# 现在复制真正的源代码
COPY src ./src/
COPY tests ./tests/
COPY scripts ./scripts/
COPY static ./static/
COPY tools ./tools/
# 构建
RUN 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
# 查找生成的二进制文件并复制到/app/cursor-api
RUN find ./target/release -maxdepth 1 -type f -executable -not -name "*.d" -exec cp {} /app/cursor-api \; || \
(echo "No executable binary found in target/release" && ls -la ./target/release && exit 1)
# 运行阶段
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 && \
chmod +x /app/cursor-api
ENV PORT=3000
EXPOSE ${PORT}
USER cursorapi
CMD ["./cursor-api"] |