-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathDockerfile
More file actions
84 lines (77 loc) · 3.07 KB
/
Copy pathDockerfile
File metadata and controls
84 lines (77 loc) · 3.07 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
77
78
79
80
81
82
83
84
# syntax=docker/dockerfile:1
ARG RUST_VERSION=1.93
ARG DEBIAN_RELEASE=bookworm
ARG BIN
ARG PORT
FROM rust:${RUST_VERSION}-slim-${DEBIAN_RELEASE} AS chef
# Disable incremental compilation: Docker normalises COPY timestamps, which
# breaks Rust's mtime-based fingerprinting and causes stale .rlib reuse.
# The /app/target cache still accelerates builds via pre-compiled dep .rlibs.
ENV CARGO_INCREMENTAL=0
# Install build dependencies. RocksDB is compiled from source by librocksdb-sys.
RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y --no-install-recommends \
llvm \
clang \
libclang-dev \
cmake \
pkg-config \
libssl-dev \
ca-certificates && \
rm -rf /var/lib/apt/lists/*
RUN cargo install cargo-chef
WORKDIR /app
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
ARG BIN
# Disable incremental compilation: Docker normalises COPY timestamps, which
# breaks Rust's mtime-based fingerprinting and causes stale .rlib reuse.
# The /app/target cache still accelerates builds via pre-compiled dep .rlibs.
ENV CARGO_INCREMENTAL=0
COPY --from=planner /app/recipe.json recipe.json
# Build dependencies while preserving Cargo artifacts across layer invalidations.
#
# Cache Cargo's git DB, but leave checkout worktrees ephemeral; shared checkout
# caches are fragile when concurrent CI builds race or a build is interrupted.
RUN --mount=type=cache,sharing=locked,target=/usr/local/cargo/registry \
--mount=type=cache,sharing=locked,target=/usr/local/cargo/git/db \
--mount=type=cache,sharing=locked,target=/app/target \
cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .
RUN --mount=type=cache,sharing=locked,target=/usr/local/cargo/registry \
--mount=type=cache,sharing=locked,target=/usr/local/cargo/git/db \
--mount=type=cache,sharing=locked,target=/app/target \
cargo build --release --locked --bin ${BIN} && \
mkdir -p /app/bin && \
cp /app/target/release/${BIN} /app/bin/${BIN}
# Baseline runtime image with runtime dependencies installed.
FROM debian:${DEBIAN_RELEASE}-slim AS runtime-base
RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y --no-install-recommends \
ca-certificates && \
rm -rf /var/lib/apt/lists/*
FROM runtime-base AS runtime
ARG BIN
ARG PORT
COPY --from=builder /app/bin/${BIN} /usr/local/bin/${BIN}
LABEL org.opencontainers.image.authors=devops@miden.team \
org.opencontainers.image.url=https://0xMiden.github.io/ \
org.opencontainers.image.documentation=https://github.com/0xMiden/node \
org.opencontainers.image.source=https://github.com/0xMiden/node \
org.opencontainers.image.vendor=Miden \
org.opencontainers.image.licenses=MIT
ARG CREATED
ARG VERSION
ARG COMMIT
LABEL org.opencontainers.image.created=$CREATED \
org.opencontainers.image.version=$VERSION \
org.opencontainers.image.revision=$COMMIT
EXPOSE ${PORT}
# Use exec to replace the shell so the binary runs as PID 1.
ENV MIDEN_BIN=${BIN}
CMD ["/bin/sh", "-c", "exec /usr/local/bin/$MIDEN_BIN"]