OXYGENHUB
◆ newer-pipeline oxygenflow / images / rust / Dockerfile
4.4 KiB · last changed Build image: coverage tools; recipe copies any vendor/ 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
# Release builds (oxygen#59, oxygenhub#85): each project's scripts/dist.sh
18
# cross-builds Linux x86_64, arm64 and riscv64, macOS and Windows, with
19
# cargo-zigbuild and zig (no Apple SDK needed) and MinGW, and packs .deb,
20
# .tar.gz and .zip. The rustup targets' standard libraries, zig checked
21
# against its published SHA-256, and cargo-zigbuild, all linked onto the
22
# guest's fixed PATH.
23
ARG ZIG_VERSION
24
ARG ZIG_SHA256
25
RUN rustup target add x86_64-pc-windows-gnu aarch64-unknown-linux-gnu riscv64gc-unknown-linux-gnu x86_64-apple-darwin aarch64-apple-darwin \
26
 && apt-get update \
27
 && apt-get install -y --no-install-recommends gcc-mingw-w64-x86-64 zip \
28
 && rm -rf /var/lib/apt/lists/*
29
ADD https://ziglang.org/download/${ZIG_VERSION}/zig-x86_64-linux-${ZIG_VERSION}.tar.xz /tmp/zig.tar.xz
30
RUN echo "${ZIG_SHA256}  /tmp/zig.tar.xz" | sha256sum -c - \
31
 && mkdir -p /opt/zig && tar -xJf /tmp/zig.tar.xz -C /opt/zig --strip-components=1 && rm /tmp/zig.tar.xz \
32
 && ln -sf /opt/zig/zig /usr/local/bin/zig \
33
 && cargo install --locked --version 0.23.4 --root /opt/cargo-zigbuild cargo-zigbuild \
34
 && ln -sf /opt/cargo-zigbuild/bin/cargo-zigbuild /usr/local/bin/cargo-zigbuild \
35
 && rm -rf /usr/local/cargo/registry /usr/local/cargo/git
36
37
# Coverage (oxygenhub#113): the toolchain's llvm-tools and cargo-llvm-cov,
38
# linked onto the guest's PATH. A job writes an LCOV report with
39
# `cargo llvm-cov --lcov --output-path /src/target/lcov.info` and declares it
40
# as its `coverage` artifact; the hub reads it.
41
RUN rustup component add llvm-tools-preview \
42
 && cargo install --locked --version 0.9.1 --root /opt/cargo-llvm-cov cargo-llvm-cov \
43
 && ln -sf /opt/cargo-llvm-cov/bin/cargo-llvm-cov /usr/local/bin/cargo-llvm-cov \
44
 && rm -rf /usr/local/cargo/registry /usr/local/cargo/git
45
46
ARG NODE_VERSION
47
ARG NODE_SHA256
48
ADD https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz /tmp/node.tar.xz
49
RUN echo "${NODE_SHA256}  /tmp/node.tar.xz" | sha256sum -c - \
50
 && tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1 --exclude='*/include' --exclude='*/share/doc' \
51
 && rm /tmp/node.tar.xz
52
53
# npm's cache for the Oxygen extensions' lock files: `npm ci --offline
54
# --cache /opt/npm-cache` installs from it, read-only as it is.
55
COPY npm-cache /opt/npm-cache
56
57
# Cargo reads /.cargo/config.toml for anything under /, so /src uses the
58
# vendored crates; CARGO_HOME stays the default $HOME/.cargo (/tmp).
59
COPY vendor /opt/vendor
60
COPY cargo-config.toml /.cargo/config.toml
61
62
# Dependencies prebuilt (backlog F6b2): each workspace's recipe (its
63
# manifests and lock file with the sources stubbed out, made by recipe.py)
64
# is built at /src, where jobs build, with the environment its pipeline's
65
# rust sandbox sets, for the release build, the tests and clippy. The
66
# target directory is kept in /opt/warm/NAME; a job copies it onto its
67
# empty target disk and compiles only its own crates. A lock file that
68
# has moved on since only costs the crates that changed.
69
COPY warm /tmp/warm
70
RUN set -e; \
71
    for ws in /tmp/warm/*; do \
72
        name=$(basename "$ws"); rm -rf /src; cp -a "$ws" /src; cd /src; \
73
        export CARGO_INCREMENTAL=0 CARGO_PROFILE_DEV_DEBUG=0 CARGO_PROFILE_TEST_DEBUG=0 CARGO_PROFILE_RELEASE_DEBUG=0; \
74
        cargo build --release --locked; \
75
        cargo test --workspace --locked --no-run; \
76
        cargo clippy --workspace --all-targets --locked; \
77
        mkdir -p /opt/warm; mv /src/target "/opt/warm/$name"; cd /; \
78
    done; \
79
    rm -rf /src /tmp/warm /root/.cargo/registry /root/.cargo/git; mkdir /src
80
81
# Everything under /opt readable and its directories searchable by any
82
# user: jobs do not run as root, and their uid is the runner host's.
83
RUN chmod -R a+rX /opt