OXYGENHUB
# a63d3dcd2aef oxygenflow / images / rust / Dockerfile
4.7 KiB · last changed The WASM tier: WASI modules run by wasmtime on any runner (closes #75) 10 days 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
# Test reports (oxygenflow#81): cargo-nextest writes JUnit XML, which the
47
# hub reads as a job's `junit` artifact; `cargo llvm-cov nextest` gives the
48
# LCOV coverage and the JUnit report from one run of the tests.
49
RUN cargo install --locked --version 0.9.148 --root /opt/cargo-nextest cargo-nextest \
50
 && ln -sf /opt/cargo-nextest/bin/cargo-nextest /usr/local/bin/cargo-nextest \
51
 && rm -rf /usr/local/cargo/registry /usr/local/cargo/git
52
53
ARG NODE_VERSION
54
ARG NODE_SHA256
55
ADD https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz /tmp/node.tar.xz
56
RUN echo "${NODE_SHA256}  /tmp/node.tar.xz" | sha256sum -c - \
57
 && tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1 --exclude='*/include' --exclude='*/share/doc' \
58
 && rm /tmp/node.tar.xz
59
60
# npm's cache for the Oxygen extensions' lock files: `npm ci --offline
61
# --cache /opt/npm-cache` installs from it, read-only as it is.
62
COPY npm-cache /opt/npm-cache
63
64
# Cargo reads /.cargo/config.toml for anything under /, so /src uses the
65
# vendored crates; CARGO_HOME stays the default $HOME/.cargo (/tmp).
66
COPY vendor /opt/vendor
67
COPY cargo-config.toml /.cargo/config.toml
68
69
# Dependencies prebuilt (backlog F6b2): each workspace's recipe (its
70
# manifests and lock file with the sources stubbed out, made by recipe.py)
71
# is built at /src, where jobs build, with the environment its pipeline's
72
# rust sandbox sets, for the release build, the tests and clippy. The
73
# target directory is kept in /opt/warm/NAME; a job copies it onto its
74
# empty target disk and compiles only its own crates. A lock file that
75
# has moved on since only costs the crates that changed.
76
COPY warm /tmp/warm
77
RUN set -e; \
78
    for ws in /tmp/warm/*; do \
79
        name=$(basename "$ws"); rm -rf /src; cp -a "$ws" /src; cd /src; \
80
        export CARGO_INCREMENTAL=0 CARGO_PROFILE_DEV_DEBUG=0 CARGO_PROFILE_TEST_DEBUG=0 CARGO_PROFILE_RELEASE_DEBUG=0; \
81
        cargo build --release --locked; \
82
        cargo test --workspace --locked --no-run; \
83
        cargo clippy --workspace --all-targets --locked; \
84
        mkdir -p /opt/warm; mv /src/target "/opt/warm/$name"; cd /; \
85
    done; \
86
    rm -rf /src /tmp/warm /root/.cargo/registry /root/.cargo/git; mkdir /src