| 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 |
# PostgreSQL (oxygenhub#211): OxygenHub's tests on Postgres start a server |
| 61 |
# of their own on loopback inside the job (.flow/test-postgres.sh). Debian's |
| 62 |
# server, its programs linked onto the guest's fixed PATH, and nss_wrapper: |
| 63 |
# a job runs as the runner's builder, a user this image's /etc/passwd does |
| 64 |
# not name, and initdb must look its user up. |
| 65 |
RUN apt-get update \ |
| 66 |
&& apt-get install -y --no-install-recommends postgresql libnss-wrapper \ |
| 67 |
&& rm -rf /var/lib/apt/lists/* \ |
| 68 |
&& for b in initdb pg_ctl postgres; do ln -sf /usr/lib/postgresql/*/bin/$b /usr/local/bin/$b; done \ |
| 69 |
&& initdb --version |
| 70 |
|
| 71 |
# npm's cache for the Oxygen extensions' lock files: `npm ci --offline |
| 72 |
# --cache /opt/npm-cache` installs from it, read-only as it is. |
| 73 |
COPY npm-cache /opt/npm-cache |
| 74 |
|
| 75 |
# Cargo reads /.cargo/config.toml for anything under /, so /src uses the |
| 76 |
# vendored crates; CARGO_HOME stays the default $HOME/.cargo (/tmp). |
| 77 |
COPY vendor /opt/vendor |
| 78 |
COPY cargo-config.toml /.cargo/config.toml |
| 79 |
|
| 80 |
# Dependencies prebuilt (backlog F6b2): each workspace's recipe (its |
| 81 |
# manifests and lock file with the sources stubbed out, made by recipe.py) |
| 82 |
# is built at /src, where jobs build, with the environment its pipeline's |
| 83 |
# rust sandbox sets, for the release build, the tests and clippy. The |
| 84 |
# target directory is kept in /opt/warm/NAME; a job copies it onto its |
| 85 |
# empty target disk and compiles only its own crates. A lock file that |
| 86 |
# has moved on since only costs the crates that changed. |
| 87 |
COPY warm /tmp/warm |
| 88 |
RUN set -e; \ |
| 89 |
for ws in /tmp/warm/*; do \ |
| 90 |
name=$(basename "$ws"); rm -rf /src; cp -a "$ws" /src; cd /src; \ |
| 91 |
export CARGO_INCREMENTAL=0 CARGO_PROFILE_DEV_DEBUG=0 CARGO_PROFILE_TEST_DEBUG=0 CARGO_PROFILE_RELEASE_DEBUG=0; \ |
| 92 |
cargo build --release --locked; \ |
| 93 |
cargo test --workspace --locked --no-run; \ |
| 94 |
cargo clippy --workspace --all-targets --locked; \ |
| 95 |
mkdir -p /opt/warm; mv /src/target "/opt/warm/$name"; cd /; \ |
| 96 |
done; \ |
| 97 |
rm -rf /src /tmp/warm /root/.cargo/registry /root/.cargo/git; mkdir /src |
| 98 |
|
| 99 |
# Everything under /opt readable and its directories searchable by any |
| 100 |
# user: jobs do not run as root, and their uid is the runner host's. |
| 101 |
RUN chmod -R a+rX /opt |