44# ## BUILD OPTIONS
55# ##
66# ## See <https://hub.docker.com/_/rust> for current
7- # ## list of tags.
7+ # ## list of tags. You may use vendored sources by
8+ # ## running
9+ # ##
10+ # ## cargo vendor --versioned-dirs --locked >.cargo/config.toml
11+ # ##
12+ # ## on the HOST. When building with vendored sources,
13+ # ## set --build-arg CARGO_NET_OFFLINE=true
814
915# Rust version, like "1" or "1.67.0"
1016ARG BUILD_RUST_TAG=1.67
@@ -24,8 +30,6 @@ ARG BUILD_OS_TAG=slim-buster
2430
2531FROM docker.io/library/rust:${BUILD_RUST_TAG}-${BUILD_OS_TAG} AS samedec-build-deps
2632
27- ARG CARGO_BUILD_TARGET=
28-
2933ENV CARGO_INSTALL_ROOT=/usr/local \
3034 CARGO_TERM_COLOR=always \
3135 RUST_BACKTRACE=1 \
@@ -61,32 +65,40 @@ COPY Cargo.lock \
6165COPY crates/sameold/Cargo.toml crates/sameold/Cargo.toml
6266COPY crates/samedec/Cargo.toml crates/samedec/Cargo.toml
6367
64- # Download dependencies
65- RUN [ -n "$CARGO_BUILD_TARGET" ] || unset CARGO_BUILD_TARGET && \
66- cargo fetch --locked
68+ # Add vendored sources
69+ COPY vendor vendor
70+ COPY . cargo .cargo
6771
68- # Build dependencies
72+ # Target platform triple. Leave unset to autodetect.
73+ ARG CARGO_BUILD_TARGET=
74+
75+ # Set to true if using vendored sources
76+ ARG CARGO_NET_OFFLINE=false
77+
78+ # Fetch and build dependencies
6979RUN [ -n "$CARGO_BUILD_TARGET" ] || unset CARGO_BUILD_TARGET && \
70- cargo build --offline -- tests --frozen --release --workspace
80+ cargo build --tests --locked --release --workspace
7181
7282# ##
7383# ## FIRST-PARTY BUILD IMAGE
74- # ## Build's samedec itself
84+ # ## Builds samedec itself
7585# ##
7686
7787FROM samedec-build-deps AS samedec-build
7888
7989ARG CARGO_BUILD_TARGET=
8090
91+ ENV CARGO_NET_OFFLINE=true
92+
8193# Replace dummy crates with our sources
8294COPY crates crates
8395
8496# Build first-party code. Update timestamps to force new
8597# build. samedec is installed to /usr/local/bin/samedec
8698RUN [ -n "$CARGO_BUILD_TARGET" ] || unset CARGO_BUILD_TARGET && \
8799 touch crates/sameold/src/lib.rs crates/samedec/src/main.rs && \
88- cargo test --offline -- frozen --release --workspace && \
89- cargo install --offline -- frozen --path=crates/samedec
100+ cargo test --frozen --release --workspace && \
101+ cargo install --frozen --path=crates/samedec
90102
91103# Perform tests
92104RUN samedec --version
0 commit comments