-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathDockerfile
More file actions
67 lines (52 loc) · 2.42 KB
/
Dockerfile
File metadata and controls
67 lines (52 loc) · 2.42 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
# syntax=docker/dockerfile:1
# =============================================================================
# Stage 1: Chef - Install cargo-chef for dependency caching
# =============================================================================
FROM rust:bookworm AS chef
RUN cargo install --locked cargo-chef@0.1.77
WORKDIR /app
# =============================================================================
# Stage 2: Planner - Generate dependency recipe
# =============================================================================
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
# =============================================================================
# Stage 3: Builder - Build all workspace binaries
# =============================================================================
FROM chef AS builder
# libclang-dev: required by bindgen (build-dep of process crate)
RUN apt-get update && apt-get install -y --no-install-recommends \
libclang-dev \
&& rm -rf /var/lib/apt/lists/*
# Build dependencies first (cached layer)
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
# Build all workspace binaries
COPY . .
RUN cargo build --release
# Collect binaries into staging directory
RUN mkdir -p /app/staging/bin && \
find target/release -maxdepth 1 -type f -executable \
! -name '*.d' ! -name 'build-script-*' \
-exec cp {} /app/staging/bin/ \;
# =============================================================================
# Stage 4: Runtime - Minimal image with binaries
# =============================================================================
FROM ubuntu:24.04 AS runtime
LABEL org.opencontainers.image.source="https://github.com/rustcoreutils/posixutils-rs"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.description="Rust-native POSIX utilities (130+ commands)"
LABEL org.opencontainers.image.title="posixutils-rs"
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
RUN useradd --create-home --shell /bin/bash posixutils
COPY --from=builder /app/staging/bin/ /usr/local/bin/
# argv[0]-based symlinks (ex->vi, uncompress/zcat->compress)
RUN ln -sf vi /usr/local/bin/ex && \
ln -sf compress /usr/local/bin/uncompress && \
ln -sf compress /usr/local/bin/zcat
USER posixutils
WORKDIR /home/posixutils
CMD ["sh"]