mirror of
https://github.com/dockersrc/rust
synced 2026-06-24 20:01:06 -04:00
e36a6888dd
Install latest stable Rust at build time via rustup-init with SHA256 verification. Add 30 cross-compile targets, cargo-binstall, and a comprehensive set of cargo development tools. Match the official rust:alpine env-var convention (RUSTUP_HOME / CARGO_HOME) and declare those paths as Docker VOLUMEs. Add the Go-image pattern: rust-workflow runs automatically when the container is invoked with no args, while explicit commands pass through unchanged. Copy language-agnostic healthcheck, copy, and symlink utilities from the Go image. - Dockerfile: WORKDIR /app in final stage; add RUSTUP_HOME, CARGO_HOME, RUSTUP_TOOLCHAIN ENV vars; extend VOLUME to include cargo and rustup paths - rootfs/root/docker/setup/05-custom.sh: full Rust toolchain install — build deps (build-base musl-dev clang lld cmake openssl-dev), SHA256- verified rustup-init, stable toolchain with rust-src/rust-analyzer/ llvm-tools-preview, 30 cross-compile targets, cargo-binstall bootstrap, cargo tool suite via binstall, cross-linker config.toml, /usr/local/bin symlinks, ~/.cargo and ~/.rustup home symlinks, /etc/profile.d/rust.sh - rootfs/usr/local/bin/rust-workflow: default workflow script — fmt --check → clippy -D warnings → test --all → build --release; honours CARGO_WORKDIR and CARGO_BUILD_TARGET env vars - rootfs/usr/local/bin/entrypoint.sh: __no_exit guarded by $# -eq 0 in START_SERVICES block; * catch-all now calls rust-workflow on no args - rootfs/usr/local/bin/healthcheck: copied from Go image (HTTP/TCP/ process/file health probe) - rootfs/usr/local/bin/copy: copied from Go image (recursive copy utility) - rootfs/usr/local/bin/symlink: copied from Go image (symlink utility) Dockerfile rootfs/root/docker/setup/05-custom.sh rootfs/usr/local/bin/copy rootfs/usr/local/bin/entrypoint.sh rootfs/usr/local/bin/healthcheck rootfs/usr/local/bin/rust-workflow rootfs/usr/local/bin/symlink
89 lines
3.3 KiB
Bash
Executable File
89 lines
3.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# shellcheck shell=bash
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
##@Version : 202605311104-git
|
|
# @@Author : Jason Hempstead
|
|
# @@Contact : jason@casjaysdev.pro
|
|
# @@License : WTFPL
|
|
# @@ReadME : rust-workflow --help
|
|
# @@Copyright : Copyright: (c) 2026 Jason Hempstead, Casjays Developments
|
|
# @@Created : Sunday, May 31, 2026 11:04 EDT
|
|
# @@File : rust-workflow
|
|
# @@Description : Default Rust workflow: fmt → clippy → test → build
|
|
# @@Changelog : New script
|
|
# @@Other :
|
|
# @@Resource :
|
|
# @@Terminal App : no
|
|
# @@sudo/root : no
|
|
# @@Template : other/docker-workflow
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# Runs automatically when `docker run casjaysdev/rust` is called with no args.
|
|
# Working directory must be a Cargo workspace or crate root (Cargo.toml must exist).
|
|
set -euo pipefail
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# Resolve the working directory — prefer /app if mounted, then cwd
|
|
WORK_DIR="${CARGO_WORKDIR:-${PWD}}"
|
|
cd "$WORK_DIR"
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# Require a Cargo.toml so we fail fast with a clear message instead of
|
|
# cryptic cargo errors about missing manifests
|
|
if [ ! -f "Cargo.toml" ]; then
|
|
echo "Error: no Cargo.toml found in ${WORK_DIR}" >&2
|
|
echo "Mount your project with: docker run --rm -v \"\$(pwd)\":/app casjaysdev/rust" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# Resolve the crate or workspace name from the manifest
|
|
CRATE="$(awk -F'"' '/^\[package\]/{p=1} p && /^name[[:space:]]*=/{print $2; exit}' Cargo.toml)"
|
|
[ -z "$CRATE" ] && CRATE="$(basename "$WORK_DIR")"
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# Optional target override — set CARGO_BUILD_TARGET for cross-compilation or
|
|
# static musl builds (e.g. x86_64-unknown-linux-musl)
|
|
BUILD_TARGET="${CARGO_BUILD_TARGET:-}"
|
|
|
|
# Collect extra flags for steps that accept a target
|
|
build_flags=(--release)
|
|
test_flags=()
|
|
if [ -n "$BUILD_TARGET" ]; then
|
|
build_flags+=(--target "$BUILD_TARGET")
|
|
test_flags+=(--target "$BUILD_TARGET")
|
|
fi
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
echo ""
|
|
echo "▶ Rust workflow: ${CRATE}"
|
|
echo " Working dir: ${WORK_DIR}"
|
|
echo " Rust: $(rustc --version)"
|
|
echo " Cargo: $(cargo --version)"
|
|
[ -n "$BUILD_TARGET" ] && echo " Target: ${BUILD_TARGET}"
|
|
echo ""
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
run_step() {
|
|
local label="$1"; shift
|
|
echo "── ${label}"
|
|
"$@"
|
|
echo ""
|
|
}
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# 1. Check formatting — report violations but do not auto-modify source
|
|
run_step "cargo fmt --check" cargo fmt --all -- --check
|
|
|
|
# 2. Lint with clippy across all targets and features; treat warnings as errors
|
|
run_step "cargo clippy" cargo clippy --all-targets --all-features -- -D warnings
|
|
|
|
# 3. Run the full test suite before spending time on a release build
|
|
run_step "cargo test --all" cargo test --all "${test_flags[@]}"
|
|
|
|
# 4. Build the release binary (static if CARGO_BUILD_TARGET is set)
|
|
run_step "cargo build --release" cargo build --all "${build_flags[@]}"
|
|
|
|
echo "✅ Done."
|