OXYGENHUB
◆ main oxygenflow / images / rust / Dockerfile
5.6 KiB · last changed flow deps check: is every crate of a Cargo.lock in the image (closes #101) 1 day ago source blame history raw
eb5c4db6 Andy McCall ↶ 1
# The OxygenFlow build image (backlog F1b): Rust with rustfmt and clippy,
50354f57 Andy McCall ↶ 2
# Node, every crate the Oxygen projects use, vendored, and an npm cache for
3
# the Oxygen extensions, because jobs
eb5c4db6 Andy McCall ↶ 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
85ad9087 Andy McCall ↶ 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,
5544c899 Andy McCall ↶ 20
# .tar.gz and .zip; wasm32-wasip1 rebuilds the cheap checks' WASI module
21
# (scripts/checks-wasm.sh --check, #96). The rustup targets' standard libraries, zig checked
85ad9087 Andy McCall ↶ 22
# against its published SHA-256, and cargo-zigbuild, all linked onto the
23
# guest's fixed PATH.
24
ARG ZIG_VERSION
25
ARG ZIG_SHA256
5544c899 Andy McCall ↶ 26
RUN rustup target add x86_64-pc-windows-gnu aarch64-unknown-linux-gnu riscv64gc-unknown-linux-gnu x86_64-apple-darwin aarch64-apple-darwin wasm32-wasip1 \
85ad9087 Andy McCall ↶ 27
 && apt-get update \
28
 && apt-get install -y --no-install-recommends gcc-mingw-w64-x86-64 zip \
29
 && rm -rf /var/lib/apt/lists/*
30
ADD https://ziglang.org/download/${ZIG_VERSION}/zig-x86_64-linux-${ZIG_VERSION}.tar.xz /tmp/zig.tar.xz
31
RUN echo "${ZIG_SHA256}  /tmp/zig.tar.xz" | sha256sum -c - \
32
 && mkdir -p /opt/zig && tar -xJf /tmp/zig.tar.xz -C /opt/zig --strip-components=1 && rm /tmp/zig.tar.xz \
33
 && ln -sf /opt/zig/zig /usr/local/bin/zig \
34
 && cargo install --locked --version 0.23.4 --root /opt/cargo-zigbuild cargo-zigbuild \
35
 && ln -sf /opt/cargo-zigbuild/bin/cargo-zigbuild /usr/local/bin/cargo-zigbuild \
36
 && rm -rf /usr/local/cargo/registry /usr/local/cargo/git
37
fad61521 Andy McCall ↶ 38
# Coverage (oxygenhub#113): the toolchain's llvm-tools and cargo-llvm-cov,
39
# linked onto the guest's PATH. A job writes an LCOV report with
40
# `cargo llvm-cov --lcov --output-path /src/target/lcov.info` and declares it
41
# as its `coverage` artifact; the hub reads it.
42
RUN rustup component add llvm-tools-preview \
43
 && cargo install --locked --version 0.9.1 --root /opt/cargo-llvm-cov cargo-llvm-cov \
44
 && ln -sf /opt/cargo-llvm-cov/bin/cargo-llvm-cov /usr/local/bin/cargo-llvm-cov \
45
 && rm -rf /usr/local/cargo/registry /usr/local/cargo/git
46
28cc603f Andy McCall ↶ 47
# Test reports (oxygenflow#81): cargo-nextest writes JUnit XML, which the
48
# hub reads as a job's `junit` artifact; `cargo llvm-cov nextest` gives the
49
# LCOV coverage and the JUnit report from one run of the tests.
50
RUN cargo install --locked --version 0.9.148 --root /opt/cargo-nextest cargo-nextest \
51
 && ln -sf /opt/cargo-nextest/bin/cargo-nextest /usr/local/bin/cargo-nextest \
52
 && rm -rf /usr/local/cargo/registry /usr/local/cargo/git
53
eb5c4db6 Andy McCall ↶ 54
ARG NODE_VERSION
55
ARG NODE_SHA256
56
ADD https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz /tmp/node.tar.xz
57
RUN echo "${NODE_SHA256}  /tmp/node.tar.xz" | sha256sum -c - \
58
 && tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1 --exclude='*/include' --exclude='*/share/doc' \
59
 && rm /tmp/node.tar.xz
50354f57 Andy McCall ↶ 60
60d848f2 Andy McCall ↶ 61
# PostgreSQL (oxygenhub#211): OxygenHub's tests on Postgres start a server
62
# of their own on loopback inside the job (.flow/test-postgres.sh). Debian's
63
# server, its programs linked onto the guest's fixed PATH, and nss_wrapper:
64
# a job runs as the runner's builder, a user this image's /etc/passwd does
65
# not name, and initdb must look its user up.
66
RUN apt-get update \
67
 && apt-get install -y --no-install-recommends postgresql libnss-wrapper \
68
 && rm -rf /var/lib/apt/lists/* \
69
 && for b in initdb pg_ctl postgres; do ln -sf /usr/lib/postgresql/*/bin/$b /usr/local/bin/$b; done \
70
 && initdb --version
71
50354f57 Andy McCall ↶ 72
# npm's cache for the Oxygen extensions' lock files: `npm ci --offline
73
# --cache /opt/npm-cache` installs from it, read-only as it is.
74
COPY npm-cache /opt/npm-cache
eb5c4db6 Andy McCall ↶ 75
76
# Cargo reads /.cargo/config.toml for anything under /, so /src uses the
77
# vendored crates; CARGO_HOME stays the default $HOME/.cargo (/tmp).
78
COPY vendor /opt/vendor
f3b5b86e Andy McCall ↶ 79
# What it vendors, `NAME VERSION` a line: `flow deps check --list` (#101).
80
COPY crates.txt /opt/crates.txt
eb5c4db6 Andy McCall ↶ 81
COPY cargo-config.toml /.cargo/config.toml
eba589f8 Andy McCall ↶ 82
83
# Dependencies prebuilt (backlog F6b2): each workspace's recipe (its
84
# manifests and lock file with the sources stubbed out, made by recipe.py)
85
# is built at /src, where jobs build, with the environment its pipeline's
86
# rust sandbox sets, for the release build, the tests and clippy. The
87
# target directory is kept in /opt/warm/NAME; a job copies it onto its
88
# empty target disk and compiles only its own crates. A lock file that
89
# has moved on since only costs the crates that changed.
90
COPY warm /tmp/warm
91
RUN set -e; \
92
    for ws in /tmp/warm/*; do \
93
        name=$(basename "$ws"); rm -rf /src; cp -a "$ws" /src; cd /src; \
94
        export CARGO_INCREMENTAL=0 CARGO_PROFILE_DEV_DEBUG=0 CARGO_PROFILE_TEST_DEBUG=0 CARGO_PROFILE_RELEASE_DEBUG=0; \
95
        cargo build --release --locked; \
96
        cargo test --workspace --locked --no-run; \
97
        cargo clippy --workspace --all-targets --locked; \
98
        mkdir -p /opt/warm; mv /src/target "/opt/warm/$name"; cd /; \
99
    done; \
100
    rm -rf /src /tmp/warm /root/.cargo/registry /root/.cargo/git; mkdir /src
22007df2 Andy McCall ↶ 101
102
# Everything under /opt readable and its directories searchable by any
103
# user: jobs do not run as root, and their uid is the runner host's.
104
RUN chmod -R a+rX /opt