cursor2api / Dockerfile
takatorury's picture
Update Dockerfile
cd00f98 verified
raw
history blame
1.38 kB
# 使用固定架构的基础镜像而不是动态平台
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"]