From 159db44dad22ad890c65527deef7494ecb50ebcc Mon Sep 17 00:00:00 2001 From: Odboy Date: Sun, 15 Nov 2026 11:17:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20compile-rust=20?= =?UTF-8?q?=E9=95=9C=E5=83=8F=EF=BC=88=E7=BC=96=E8=AF=91=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E9=93=BE=20+=20=E9=98=BF=E9=87=8C=E4=BA=91=20crates=20?= =?UTF-8?q?=E6=BA=90=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- image/compile-rust/.dockerignore | 3 +++ image/compile-rust/.gitignore | 4 ++++ image/compile-rust/Dockerfile | 29 +++++++++++++++++++++++++++++ image/compile-rust/build.sh | 8 ++++++++ 4 files changed, 44 insertions(+) create mode 100644 image/compile-rust/.dockerignore create mode 100644 image/compile-rust/.gitignore create mode 100644 image/compile-rust/Dockerfile create mode 100755 image/compile-rust/build.sh diff --git a/image/compile-rust/.dockerignore b/image/compile-rust/.dockerignore new file mode 100644 index 0000000..1e8e122 --- /dev/null +++ b/image/compile-rust/.dockerignore @@ -0,0 +1,3 @@ +build.sh +.git/ +.DS_Store diff --git a/image/compile-rust/.gitignore b/image/compile-rust/.gitignore new file mode 100644 index 0000000..75dd1f2 --- /dev/null +++ b/image/compile-rust/.gitignore @@ -0,0 +1,4 @@ +# 构建产物 / 本地缓存 +*.tar.xz +*.sha256 +.DS_Store diff --git a/image/compile-rust/Dockerfile b/image/compile-rust/Dockerfile new file mode 100644 index 0000000..e44a911 --- /dev/null +++ b/image/compile-rust/Dockerfile @@ -0,0 +1,29 @@ +FROM registry.cn-shanghai.aliyuncs.com/odboy/kenaito:runtime-rust +LABEL MAINTAINER="tianjun@odboy.cn" +ENV TimeZone=Asia/Shanghai +# cargo 的 home 与缓存目录;运行时镜像不带 CARGO,编译镜像里保留即可 +ENV CARGO_HOME=/home/admin/.cargo +ENV PATH="${CARGO_HOME}/bin:$PATH" +WORKDIR /home/admin +# gcc/make:链接 C 库与部分 build.rs;openssl-devel/pkg-config:reqwest 等依赖; +# gcc-c++ 供少部分含 C++ 的依赖;git:从 git 源拉依赖 +RUN set -e && yum install \ + gcc \ + gcc-c++ \ + make \ + pkg-config \ + openssl-devel \ + ca-certificates \ + git \ + sysstat \ + net-tools -y; +# crates 源换阿里云镜像(sparse 协议),避免直连 crates.io 超时;与 Python/Node 镜像用同一家源 +RUN set -e && mkdir -p ${CARGO_HOME}; \ + printf '%s\n' \ + '[source.crates-io]' \ + 'replace-with = "aliyun"' \ + '' \ + '[source.aliyun]' \ + 'registry = "sparse+https://mirrors.aliyun.com/crates.io-index/"' \ + > ${CARGO_HOME}/config.toml; \ + cargo -V diff --git a/image/compile-rust/build.sh b/image/compile-rust/build.sh new file mode 100755 index 0000000..51a56e8 --- /dev/null +++ b/image/compile-rust/build.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# 编译镜像基于 runtime-rust:只需保证 runtime-rust 已构建,这里不再下载 Rust 发行包 +set -euo pipefail +cd "$(dirname "$0")" + +IMAGE=registry.cn-shanghai.aliyuncs.com/odboy/kenaito:compile-rust +docker build -t "${IMAGE}" . +docker push "${IMAGE}"