🎨 优化dockerfile编译,限制资源
This commit is contained in:
@@ -5,6 +5,14 @@ edition = "2024"
|
|||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = "thin"
|
lto = "thin"
|
||||||
|
codegen-units = 1
|
||||||
|
strip = true
|
||||||
|
|
||||||
|
# Docker 构建专用 profile:关闭 LTO、提高 codegen-units 并行度
|
||||||
|
[profile.docker-release]
|
||||||
|
inherits = "release"
|
||||||
|
lto = false
|
||||||
|
codegen-units = 16
|
||||||
strip = true
|
strip = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|||||||
20
Dockerfile
20
Dockerfile
@@ -10,8 +10,9 @@ RUN cargo chef prepare --recipe-path recipe.json
|
|||||||
|
|
||||||
FROM node:24-alpine AS frontend-builder
|
FROM node:24-alpine AS frontend-builder
|
||||||
WORKDIR /app/admin-ui
|
WORKDIR /app/admin-ui
|
||||||
COPY admin-ui/package.json ./
|
# 单独复制依赖文件,利用层缓存:只有依赖变化时才重新安装
|
||||||
RUN npm install -g pnpm && pnpm install
|
COPY admin-ui/package.json admin-ui/bun.lock* ./
|
||||||
|
RUN npm install -g pnpm && pnpm install --frozen-lockfile
|
||||||
COPY admin-ui ./
|
COPY admin-ui ./
|
||||||
RUN pnpm build
|
RUN pnpm build
|
||||||
|
|
||||||
@@ -20,11 +21,15 @@ FROM chef AS builder
|
|||||||
# 可选:启用敏感日志输出(仅用于排障)
|
# 可选:启用敏感日志输出(仅用于排障)
|
||||||
ARG ENABLE_SENSITIVE_LOGS=false
|
ARG ENABLE_SENSITIVE_LOGS=false
|
||||||
|
|
||||||
|
# 可按需在构建时覆盖:docker compose build --build-arg CARGO_BUILD_JOBS=48
|
||||||
|
ARG CARGO_BUILD_JOBS=8
|
||||||
|
ENV CARGO_BUILD_JOBS=${CARGO_BUILD_JOBS}
|
||||||
|
|
||||||
COPY --from=planner /app/recipe.json recipe.json
|
COPY --from=planner /app/recipe.json recipe.json
|
||||||
RUN if [ "$ENABLE_SENSITIVE_LOGS" = "true" ]; then \
|
RUN if [ "$ENABLE_SENSITIVE_LOGS" = "true" ]; then \
|
||||||
cargo chef cook --release --features sensitive-logs --recipe-path recipe.json; \
|
cargo chef cook --profile docker-release --features sensitive-logs --recipe-path recipe.json; \
|
||||||
else \
|
else \
|
||||||
cargo chef cook --release --recipe-path recipe.json; \
|
cargo chef cook --profile docker-release --recipe-path recipe.json; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
COPY Cargo.toml Cargo.lock* ./
|
COPY Cargo.toml Cargo.lock* ./
|
||||||
@@ -32,9 +37,9 @@ COPY src ./src
|
|||||||
COPY --from=frontend-builder /app/admin-ui/dist /app/admin-ui/dist
|
COPY --from=frontend-builder /app/admin-ui/dist /app/admin-ui/dist
|
||||||
|
|
||||||
RUN if [ "$ENABLE_SENSITIVE_LOGS" = "true" ]; then \
|
RUN if [ "$ENABLE_SENSITIVE_LOGS" = "true" ]; then \
|
||||||
cargo build --release --features sensitive-logs; \
|
cargo build --profile docker-release --features sensitive-logs; \
|
||||||
else \
|
else \
|
||||||
cargo build --release; \
|
cargo build --profile docker-release; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
FROM alpine:3.21
|
FROM alpine:3.21
|
||||||
@@ -42,7 +47,8 @@ FROM alpine:3.21
|
|||||||
RUN apk add --no-cache ca-certificates
|
RUN apk add --no-cache ca-certificates
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=builder /app/target/release/kiro-rs /app/kiro-rs
|
# docker-release profile 产物路径为 target/docker-release/
|
||||||
|
COPY --from=builder /app/target/docker-release/kiro-rs /app/kiro-rs
|
||||||
|
|
||||||
VOLUME ["/app/config"]
|
VOLUME ["/app/config"]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user