From d48cc7c451aad86782288a2db36cc153f7e9cd7b Mon Sep 17 00:00:00 2001 From: Odboy Date: Sun, 15 Nov 2026 11:05:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20runtime-rust=20?= =?UTF-8?q?=E9=95=9C=E5=83=8F=EF=BC=88Rust=201.100.0=EF=BC=8CUSTC=20?= =?UTF-8?q?=E9=95=9C=E5=83=8F=E7=AB=99=E4=B8=8B=E8=BD=BD=E5=B9=B6=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=20sha256=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- image/runtime-rust/.dockerignore | 5 +++++ image/runtime-rust/.gitignore | 4 ++++ image/runtime-rust/Dockerfile | 25 +++++++++++++++++++++++++ image/runtime-rust/build.sh | 29 +++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 image/runtime-rust/.dockerignore create mode 100644 image/runtime-rust/.gitignore create mode 100644 image/runtime-rust/Dockerfile create mode 100755 image/runtime-rust/build.sh diff --git a/image/runtime-rust/.dockerignore b/image/runtime-rust/.dockerignore new file mode 100644 index 0000000..e584122 --- /dev/null +++ b/image/runtime-rust/.dockerignore @@ -0,0 +1,5 @@ +# 由 build.sh 预下载的 Rust 发行包经 ADD 解压进镜像, +# ADD 的源文件必须在构建上下文内,因此 *.tar.xz 不能在这里忽略 +build.sh +.git/ +.DS_Store diff --git a/image/runtime-rust/.gitignore b/image/runtime-rust/.gitignore new file mode 100644 index 0000000..75dd1f2 --- /dev/null +++ b/image/runtime-rust/.gitignore @@ -0,0 +1,4 @@ +# 构建产物 / 本地缓存 +*.tar.xz +*.sha256 +.DS_Store diff --git a/image/runtime-rust/Dockerfile b/image/runtime-rust/Dockerfile new file mode 100644 index 0000000..20f1cce --- /dev/null +++ b/image/runtime-rust/Dockerfile @@ -0,0 +1,25 @@ +FROM registry.cn-shanghai.aliyuncs.com/odboy/kenaito:system-alinux3 +LABEL MAINTAINER="tianjun@odboy.cn" +ENV TimeZone=Asia/Shanghai +ENV RUST_HOME=/usr/local/rust +ENV PATH="${RUST_HOME}/bin:$PATH" +WORKDIR /home/admin +# https://mirrors.ustc.edu.cn/rust-static/dist/rust-1.100.0-x86_64-unknown-linux-gnu.tar.xz +# 由 build.sh 预先下载到本目录,并校验官方 .sha256 +ADD rust-1.100.0-x86_64-unknown-linux-gnu.tar.xz /tmp/rust/ +# install.sh 把 rustc/cargo 等装进 --prefix;glibc 运行时库 alinux3 自带 +# 运行/编译镜像都不需要文档 rust-src rust-mingw 去掉可省下大半体积 +RUN set -e && yum install \ + gcc \ + ca-certificates \ + sysstat \ + net-tools -y; \ + cd /tmp/rust/rust-1.100.0-x86_64-unknown-linux-gnu; \ + ./install.sh \ + --prefix=${RUST_HOME} \ + --disable-ldconfig \ + --without=rust-docs,rust-docs-json-preview,rustc-docs,rust-src,rust-mingw,rust-analysis; \ + cd / && rm -rf /tmp/rust; \ + chmod -R a+rx ${RUST_HOME}; \ + rustc -V; \ + cargo -V; diff --git a/image/runtime-rust/build.sh b/image/runtime-rust/build.sh new file mode 100755 index 0000000..e85974d --- /dev/null +++ b/image/runtime-rust/build.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# 先下载 Rust 官方发行包并校验官方 .sha256,再基于本地文件构建镜像 +# compile-rust 复用本目录下载好的包(见 ../compile-rust/build.sh),因此这里也单独保留一份 +set -euo pipefail +cd "$(dirname "$0")" + +VERSION=1.100.0 +TRIPLE=x86_64-unknown-linux-gnu +PKG=rust-${VERSION}-${TRIPLE}.tar.xz +URL=https://mirrors.ustc.edu.cn/rust-static/dist/${PKG} +# 镜像站不可达时的官方源 +FALLBACK=https://static.rust-lang.org/dist/${PKG} + +if [ ! -f "${PKG}" ]; then + curl -fL -o "${PKG}" "${URL}" || curl -fL -o "${PKG}" "${FALLBACK}" +fi + +# 校验放在下载分支之外:包已存在时也校验;官方 .sha256 内容形如 +# rust-<版本>-x86_64-unknown-linux-gnu.tar.xz +# 直接用它校验(文件名与包名一致,不需要改写);校验通过后不保留 .sha256 +if [ ! -f "${PKG}.sha256" ]; then + curl -fL -o "${PKG}.sha256" "${URL}.sha256" || curl -fL -o "${PKG}.sha256" "${FALLBACK}.sha256" +fi +shasum -a 256 -c "${PKG}.sha256" +rm -f "${PKG}.sha256" + +IMAGE=registry.cn-shanghai.aliyuncs.com/odboy/kenaito:runtime-rust +docker build -t "${IMAGE}" . +docker push "${IMAGE}"