Skip to content

Commit d7b6ab6

Browse files
committed
container: permit locally-vendored sources
If vendored sources exist, use them automatically instead of downloading from the internet.
1 parent 3aa987c commit d7b6ab6

4 files changed

Lines changed: 28 additions & 11 deletions

File tree

.cargo/.directory_intentionally_empty

Whitespace-only changes.

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
**/*.rs.bk
33
*.iml
44
/.idea
5+
6+
# containerized build can use vendoring on the host side,
7+
# but we would prefer that this not be committed.
8+
.cargo
9+
/vendor

Dockerfile

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
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"
1016
ARG BUILD_RUST_TAG=1.67
@@ -24,8 +30,6 @@ ARG BUILD_OS_TAG=slim-buster
2430

2531
FROM docker.io/library/rust:${BUILD_RUST_TAG}-${BUILD_OS_TAG} AS samedec-build-deps
2632

27-
ARG CARGO_BUILD_TARGET=
28-
2933
ENV CARGO_INSTALL_ROOT=/usr/local \
3034
CARGO_TERM_COLOR=always \
3135
RUST_BACKTRACE=1 \
@@ -61,32 +65,40 @@ COPY Cargo.lock \
6165
COPY crates/sameold/Cargo.toml crates/sameold/Cargo.toml
6266
COPY 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
6979
RUN [ -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

7787
FROM samedec-build-deps AS samedec-build
7888

7989
ARG CARGO_BUILD_TARGET=
8090

91+
ENV CARGO_NET_OFFLINE=true
92+
8193
# Replace dummy crates with our sources
8294
COPY crates crates
8395

8496
# Build first-party code. Update timestamps to force new
8597
# build. samedec is installed to /usr/local/bin/samedec
8698
RUN [ -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
92104
RUN samedec --version

vendor/.directory_intentionally_empty

Whitespace-only changes.

0 commit comments

Comments
 (0)