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}"