kevin commited on
Commit
3e5d5c9
·
1 Parent(s): 96afcc9
Files changed (1) hide show
  1. Dockerfile +30 -18
Dockerfile CHANGED
@@ -1,37 +1,49 @@
1
- ARG TARGETARCH
2
- FROM --platform=linux/amd64 rust:1.84.0-slim-bookworm as builder
3
-
4
- ARG TARGETARCH
5
-
6
  WORKDIR /app
7
  RUN apt-get update && \
8
  apt-get install -y --no-install-recommends \
9
  build-essential protobuf-compiler pkg-config libssl-dev nodejs npm openssl \
10
  && rm -rf /var/lib/apt/lists/*
11
-
12
  COPY . .
13
- #RUN case "${TARGETARCH}" in \
14
- # amd64) TARGET_CPU="x86-64-v3" ;; \
15
- # arm64) TARGET_CPU="neoverse-n1" ;; \
16
- # *) echo "Unsupported architecture: ${TARGETARCH:-amd64}" && exit 1 ;; \
17
- # esac && \
18
- RUN TARGET_CPU="x86-64-v3" && \
19
- RUSTFLAGS="-C link-arg=-s -C target-cpu=$TARGET_CPU" cargo build --release && \
20
  cp target/release/cursor-api /app/cursor-api
21
 
22
- # 运行阶段
23
- FROM --platform=linux/amd64 debian:bookworm-slim
 
 
 
 
 
 
 
 
 
24
 
 
 
25
  WORKDIR /app
26
  ENV TZ=Asia/Shanghai
27
-
28
  RUN apt-get update && \
29
  apt-get install -y --no-install-recommends \
30
- ca-certificates tzdata openssl \
31
  && rm -rf /var/lib/apt/lists/*
 
32
 
33
- COPY --from=builder /app/cursor-api .
 
 
 
 
 
 
 
 
34
 
 
 
35
  ENV PORT=3000
36
  EXPOSE ${PORT}
37
  RUN apt-get update && \
 
1
+ # AMD64 构建阶段
2
+ FROM --platform=linux/amd64 rust:1.84.0-slim-bookworm as builder-amd64
 
 
 
3
  WORKDIR /app
4
  RUN apt-get update && \
5
  apt-get install -y --no-install-recommends \
6
  build-essential protobuf-compiler pkg-config libssl-dev nodejs npm openssl \
7
  && rm -rf /var/lib/apt/lists/*
 
8
  COPY . .
9
+ ENV RUSTFLAGS="-C link-arg=-s -C target-cpu=x86-64-v3"
10
+ RUN cargo build --release && \
 
 
 
 
 
11
  cp target/release/cursor-api /app/cursor-api
12
 
13
+ # ARM64 构建阶段
14
+ FROM --platform=linux/arm64 rust:1.84.0-slim-bookworm as builder-arm64
15
+ WORKDIR /app
16
+ RUN apt-get update && \
17
+ apt-get install -y --no-install-recommends \
18
+ build-essential protobuf-compiler pkg-config libssl-dev nodejs npm openssl \
19
+ && rm -rf /var/lib/apt/lists/*
20
+ COPY . .
21
+ ENV RUSTFLAGS="-C link-arg=-s -C target-cpu=neoverse-n1"
22
+ RUN cargo build --release && \
23
+ cp target/release/cursor-api /app/cursor-api
24
 
25
+ # AMD64 运行阶段
26
+ FROM --platform=linux/amd64 debian:bookworm-slim as run-amd64
27
  WORKDIR /app
28
  ENV TZ=Asia/Shanghai
 
29
  RUN apt-get update && \
30
  apt-get install -y --no-install-recommends \
31
+ ca-certificates tzdata \
32
  && rm -rf /var/lib/apt/lists/*
33
+ COPY --from=builder-amd64 /app/cursor-api .
34
 
35
+ # ARM64 运行阶段
36
+ FROM --platform=linux/arm64 debian:bookworm-slim as run-arm64
37
+ WORKDIR /app
38
+ ENV TZ=Asia/Shanghai
39
+ RUN apt-get update && \
40
+ apt-get install -y --no-install-recommends \
41
+ ca-certificates tzdata \
42
+ && rm -rf /var/lib/apt/lists/*
43
+ COPY --from=builder-arm64 /app/cursor-api .
44
 
45
+ # 通用配置
46
+ FROM run-${TARGETARCH}
47
  ENV PORT=3000
48
  EXPOSE ${PORT}
49
  RUN apt-get update && \