takatorury commited on
Commit
bcbf675
·
verified ·
1 Parent(s): cd00f98

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +28 -12
Dockerfile CHANGED
@@ -1,4 +1,3 @@
1
- # 使用固定架构的基础镜像而不是动态平台
2
  FROM rustlang/rust:nightly-bookworm-slim as builder
3
 
4
  WORKDIR /app
@@ -9,15 +8,26 @@ RUN apt-get update && \
9
  build-essential protobuf-compiler pkg-config libssl-dev nodejs npm openssl \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
- # 复制整个项目
13
- COPY . .
 
14
 
15
- # 检查项目结构并构建
16
- RUN if [ ! -f Cargo.toml ]; then \
17
- echo "Error: Cargo.toml not found in project root" && exit 1; \
18
- fi && \
19
- # 根据当前CPU架构选择优化标志
20
- ARCH=$(uname -m) && \
 
 
 
 
 
 
 
 
 
 
21
  if [ "$ARCH" = "x86_64" ]; then \
22
  TARGET_CPU="x86-64-v2"; \
23
  elif [ "$ARCH" = "aarch64" ]; then \
@@ -25,8 +35,11 @@ RUN if [ ! -f Cargo.toml ]; then \
25
  else \
26
  echo "Unsupported architecture: $ARCH" && exit 1; \
27
  fi && \
28
- RUSTFLAGS="-C link-arg=-s -C target-cpu=$TARGET_CPU" cargo +nightly build --release && \
29
- cp target/release/cursor-api /app/cursor-api
 
 
 
30
 
31
  # 运行阶段
32
  FROM debian:bookworm-slim
@@ -38,8 +51,11 @@ RUN apt-get update && \
38
  ca-certificates tzdata openssl \
39
  && rm -rf /var/lib/apt/lists/* && \
40
  groupadd -r cursorapi && useradd -r -g cursorapi cursorapi
 
41
  COPY --from=builder /app/cursor-api .
42
- RUN chown -R cursorapi:cursorapi /app
 
 
43
  ENV PORT=3000
44
  EXPOSE ${PORT}
45
  USER cursorapi
 
 
1
  FROM rustlang/rust:nightly-bookworm-slim as builder
2
 
3
  WORKDIR /app
 
8
  build-essential protobuf-compiler pkg-config libssl-dev nodejs npm openssl \
9
  && rm -rf /var/lib/apt/lists/*
10
 
11
+ # 先复制Cargo配置和构建相关文件
12
+ COPY Cargo.toml Cross.toml* build.rs* .gitattributes* ./
13
+ COPY .cargo /.cargo/
14
 
15
+ # 创建基本src目录结构以利用缓存
16
+ RUN mkdir -p src && \
17
+ echo "fn main() {println!(\"placeholder\");}" > src/main.rs
18
+
19
+ # 尝试获取依赖(如果可能)
20
+ RUN cargo fetch || true
21
+
22
+ # 现在复制真正的源代码
23
+ COPY src ./src/
24
+ COPY tests ./tests/
25
+ COPY scripts ./scripts/
26
+ COPY static ./static/
27
+ COPY tools ./tools/
28
+
29
+ # 构建
30
+ RUN ARCH=$(uname -m) && \
31
  if [ "$ARCH" = "x86_64" ]; then \
32
  TARGET_CPU="x86-64-v2"; \
33
  elif [ "$ARCH" = "aarch64" ]; then \
 
35
  else \
36
  echo "Unsupported architecture: $ARCH" && exit 1; \
37
  fi && \
38
+ RUSTFLAGS="-C link-arg=-s -C target-cpu=$TARGET_CPU" cargo +nightly build --release
39
+
40
+ # 查找生成的二进制文件并复制到/app/cursor-api
41
+ RUN find ./target/release -maxdepth 1 -type f -executable -not -name "*.d" -exec cp {} /app/cursor-api \; || \
42
+ (echo "No executable binary found in target/release" && ls -la ./target/release && exit 1)
43
 
44
  # 运行阶段
45
  FROM debian:bookworm-slim
 
51
  ca-certificates tzdata openssl \
52
  && rm -rf /var/lib/apt/lists/* && \
53
  groupadd -r cursorapi && useradd -r -g cursorapi cursorapi
54
+
55
  COPY --from=builder /app/cursor-api .
56
+ RUN chown -R cursorapi:cursorapi /app && \
57
+ chmod +x /app/cursor-api
58
+
59
  ENV PORT=3000
60
  EXPOSE ${PORT}
61
  USER cursorapi