forked from rustfs/operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
executable file
·76 lines (64 loc) · 2.57 KB
/
Copy pathDockerfile
File metadata and controls
executable file
·76 lines (64 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Base image for final stage (override with: docker build --build-arg BASE_IMAGE=...)
ARG BASE_IMAGE=debian:bookworm-slim
# Use rust:bookworm so the binary is linked against glibc 2.36, matching final image.
ARG RUST_BUILD_IMAGE=rust:bookworm
# Build image for the static Console frontend.
ARG NODE_BUILD_IMAGE=node:24-alpine
# cargo-chef version (pin for reproducible builds; override if needed)
ARG CARGO_CHEF_VERSION=0.1.77
ARG PNPM_VERSION=10.28.1
# When Docker build cannot reach crates.io (DNS/network), try:
# docker build --network=host -t rustfs/operator:dev .
# For China mirrors, mount or COPY a .cargo/config.toml (see docs) before cargo install.
# Shared Cargo settings for slow / flaky networks (applies to all Rust stages)
FROM ${RUST_BUILD_IMAGE} AS rust-base
RUN mkdir -p /usr/local/cargo && \
printf '%s\n' \
'[http]' \
'timeout = 300' \
'multiplexing = false' \
'' \
'[net]' \
'retry = 10' \
> /usr/local/cargo/config.toml
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
# Install cargo-chef once; planner + cacher only COPY the binary (avoids two slow installs)
FROM rust-base AS cargo-chef-installer
ARG CARGO_CHEF_VERSION
RUN cargo install cargo-chef --version "${CARGO_CHEF_VERSION}"
# Stage 1: Generate recipe for dependency caching
FROM rust-base AS planner
COPY --from=cargo-chef-installer /usr/local/cargo/bin/cargo-chef /usr/local/cargo/bin/cargo-chef
WORKDIR /app
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
# Stage 2: Build dependencies only (cached unless Cargo.lock changes)
FROM rust-base AS cacher
COPY --from=cargo-chef-installer /usr/local/cargo/bin/cargo-chef /usr/local/cargo/bin/cargo-chef
WORKDIR /app
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
# Stage 3: Build the binary
FROM rust-base AS builder
WORKDIR /app
COPY . .
COPY --from=cacher /app/target target
COPY --from=cacher /usr/local/cargo /usr/local/cargo
RUN cargo build --release
# Stage 4: Build the static Console frontend
FROM ${NODE_BUILD_IMAGE} AS console-web-builder
ARG PNPM_VERSION
WORKDIR /app/console-web
RUN npm install -g pnpm@${PNPM_VERSION}
COPY console-web/package.json console-web/pnpm-lock.yaml console-web/pnpm-workspace.yaml ./
RUN pnpm install --frozen-lockfile
COPY console-web/ ./
ARG NEXT_PUBLIC_API_BASE_URL=
ENV NEXT_PUBLIC_API_BASE_URL=${NEXT_PUBLIC_API_BASE_URL}
RUN pnpm build
# Final image
FROM ${BASE_IMAGE}
WORKDIR /app
COPY --from=builder /app/target/release/operator .
COPY --from=console-web-builder /app/console-web/out ./console-web
ENTRYPOINT ["./operator"]