# The OxygenFlow build image (backlog F1b): Rust with rustfmt and clippy,
# Node, every crate the Oxygen projects use, vendored, and an npm cache for
# the Oxygen extensions, because jobs
# have no network. Built by ./build.sh, which vendors the crates first.
FROM rust:1.97.1-slim-bookworm

RUN rustup component add rustfmt clippy \
 && apt-get update \
 && apt-get install -y --no-install-recommends ca-certificates xz-utils make git pkg-config \
 && rm -rf /var/lib/apt/lists/*

# The guest's PATH is fixed and has no /usr/local/cargo/bin, and a rustup
# proxy would need RUSTUP_HOME: link the toolchain's own binaries instead.
RUN tc=$(ls -d /usr/local/rustup/toolchains/*/ | head -1) \
 && for b in cargo rustc rustdoc cargo-fmt rustfmt cargo-clippy clippy-driver; do ln -sf "$tc/bin/$b" /usr/local/bin/$b; done

ARG NODE_VERSION
ARG NODE_SHA256
ADD https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz /tmp/node.tar.xz
RUN echo "${NODE_SHA256}  /tmp/node.tar.xz" | sha256sum -c - \
 && tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1 --exclude='*/include' --exclude='*/share/doc' \
 && rm /tmp/node.tar.xz

# npm's cache for the Oxygen extensions' lock files: `npm ci --offline
# --cache /opt/npm-cache` installs from it, read-only as it is.
COPY npm-cache /opt/npm-cache

# Cargo reads /.cargo/config.toml for anything under /, so /src uses the
# vendored crates; CARGO_HOME stays the default $HOME/.cargo (/tmp).
COPY vendor /opt/vendor
COPY cargo-config.toml /.cargo/config.toml
