Spaces:
Build error
Build error
Update Dockerfile
Browse files- Dockerfile +7 -9
Dockerfile
CHANGED
|
@@ -1,6 +1,10 @@
|
|
| 1 |
-
ARG
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
| 3 |
|
|
|
|
| 4 |
ARG TARGETARCH
|
| 5 |
|
| 6 |
WORKDIR /app
|
|
@@ -8,28 +12,22 @@ 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 amd64) TARGET_CPU="x86-64-v2" ;; arm64) TARGET_CPU="neoverse-n1" ;; *) echo "Unsupported architecture: $TARGETARCH" && exit 1 ;; esac && RUSTFLAGS="-C link-arg=-s -C target-cpu=$TARGET_CPU" cargo +nightly build --release && cp target/release/cursor-api /app/cursor-api
|
| 14 |
|
| 15 |
# 运行阶段
|
| 16 |
-
|
| 17 |
-
FROM --platform=linux/${TARGETARCH} debian:bookworm-slim
|
| 18 |
|
| 19 |
WORKDIR /app
|
| 20 |
ENV TZ=Asia/Shanghai
|
| 21 |
-
|
| 22 |
RUN apt-get update && \
|
| 23 |
apt-get install -y --no-install-recommends \
|
| 24 |
ca-certificates tzdata openssl \
|
| 25 |
&& rm -rf /var/lib/apt/lists/* && \
|
| 26 |
groupadd -r cursorapi && useradd -r -g cursorapi cursorapi
|
| 27 |
-
|
| 28 |
COPY --from=builder /app/cursor-api .
|
| 29 |
RUN chown -R cursorapi:cursorapi /app
|
| 30 |
-
|
| 31 |
ENV PORT=3000
|
| 32 |
EXPOSE ${PORT}
|
| 33 |
-
|
| 34 |
USER cursorapi
|
| 35 |
CMD ["./cursor-api"]
|
|
|
|
| 1 |
+
# 移除这行,因为在FROM之前定义但没有默认值的ARG在FROM指令中可能不会被正确解析
|
| 2 |
+
# ARG TARGETARCH
|
| 3 |
+
|
| 4 |
+
# 使用预定义的构建参数TARGETARCH (Docker buildx会自动设置)
|
| 5 |
+
FROM --platform=$PLATFORM rustlang/rust:nightly-bookworm-slim as builder
|
| 6 |
|
| 7 |
+
# 在FROM之后重新声明ARG使其在此构建阶段可用
|
| 8 |
ARG TARGETARCH
|
| 9 |
|
| 10 |
WORKDIR /app
|
|
|
|
| 12 |
apt-get install -y --no-install-recommends \
|
| 13 |
build-essential protobuf-compiler pkg-config libssl-dev nodejs npm openssl \
|
| 14 |
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
| 15 |
COPY . .
|
| 16 |
RUN case "$TARGETARCH" in amd64) TARGET_CPU="x86-64-v2" ;; arm64) TARGET_CPU="neoverse-n1" ;; *) echo "Unsupported architecture: $TARGETARCH" && exit 1 ;; esac && RUSTFLAGS="-C link-arg=-s -C target-cpu=$TARGET_CPU" cargo +nightly build --release && cp target/release/cursor-api /app/cursor-api
|
| 17 |
|
| 18 |
# 运行阶段
|
| 19 |
+
FROM --platform=$PLATFORM debian:bookworm-slim
|
|
|
|
| 20 |
|
| 21 |
WORKDIR /app
|
| 22 |
ENV TZ=Asia/Shanghai
|
|
|
|
| 23 |
RUN apt-get update && \
|
| 24 |
apt-get install -y --no-install-recommends \
|
| 25 |
ca-certificates tzdata openssl \
|
| 26 |
&& rm -rf /var/lib/apt/lists/* && \
|
| 27 |
groupadd -r cursorapi && useradd -r -g cursorapi cursorapi
|
|
|
|
| 28 |
COPY --from=builder /app/cursor-api .
|
| 29 |
RUN chown -R cursorapi:cursorapi /app
|
|
|
|
| 30 |
ENV PORT=3000
|
| 31 |
EXPOSE ${PORT}
|
|
|
|
| 32 |
USER cursorapi
|
| 33 |
CMD ["./cursor-api"]
|