OXYGENHUB
# c1a24672dbd5 oxygenflow / images / rust / Dockerfile
2.5 KiB · last changed The build image prebuilds a workspace's dependencies 1 month ago source blame history raw
1
# The OxygenFlow build image (backlog F1b): Rust with rustfmt and clippy,
2
# Node, every crate the Oxygen projects use, vendored, and an npm cache for
3
# the Oxygen extensions, because jobs
4
# have no network. Built by ./build.sh, which vendors the crates first.
5
FROM rust:1.97.1-slim-bookworm
6
7
RUN rustup component add rustfmt clippy \
8
 && apt-get update \
9
 && apt-get install -y --no-install-recommends ca-certificates xz-utils make git pkg-config \
10
 && rm -rf /var/lib/apt/lists/*
11
12
# The guest's PATH is fixed and has no /usr/local/cargo/bin, and a rustup
13
# proxy would need RUSTUP_HOME: link the toolchain's own binaries instead.
14
RUN tc=$(ls -d /usr/local/rustup/toolchains/*/ | head -1) \
15
 && for b in cargo rustc rustdoc cargo-fmt rustfmt cargo-clippy clippy-driver; do ln -sf "$tc/bin/$b" /usr/local/bin/$b; done
16
17
ARG NODE_VERSION
18
ARG NODE_SHA256
19
ADD https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz /tmp/node.tar.xz
20
RUN echo "${NODE_SHA256}  /tmp/node.tar.xz" | sha256sum -c - \
21
 && tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1 --exclude='*/include' --exclude='*/share/doc' \
22
 && rm /tmp/node.tar.xz
23
24
# npm's cache for the Oxygen extensions' lock files: `npm ci --offline
25
# --cache /opt/npm-cache` installs from it, read-only as it is.
26
COPY npm-cache /opt/npm-cache
27
28
# Cargo reads /.cargo/config.toml for anything under /, so /src uses the
29
# vendored crates; CARGO_HOME stays the default $HOME/.cargo (/tmp).
30
COPY vendor /opt/vendor
31
COPY cargo-config.toml /.cargo/config.toml
32
33
# Dependencies prebuilt (backlog F6b2): each workspace's recipe (its
34
# manifests and lock file with the sources stubbed out, made by recipe.py)
35
# is built at /src, where jobs build, with the environment its pipeline's
36
# rust sandbox sets, for the release build, the tests and clippy. The
37
# target directory is kept in /opt/warm/NAME; a job copies it onto its
38
# empty target disk and compiles only its own crates. A lock file that
39
# has moved on since only costs the crates that changed.
40
COPY warm /tmp/warm
41
RUN set -e; \
42
    for ws in /tmp/warm/*; do \
43
        name=$(basename "$ws"); rm -rf /src; cp -a "$ws" /src; cd /src; \
44
        export CARGO_INCREMENTAL=0 CARGO_PROFILE_DEV_DEBUG=0 CARGO_PROFILE_TEST_DEBUG=0 CARGO_PROFILE_RELEASE_DEBUG=0; \
45
        cargo build --release --locked; \
46
        cargo test --workspace --locked --no-run; \
47
        cargo clippy --workspace --all-targets --locked; \
48
        mkdir -p /opt/warm; mv /src/target "/opt/warm/$name"; cd /; \
49
    done; \
50
    rm -rf /src /tmp/warm /root/.cargo/registry /root/.cargo/git; mkdir /src