65 lines
3.2 KiB
Docker
65 lines
3.2 KiB
Docker
ARG RUST_IMAGE=rust:1-bookworm
|
|
FROM --platform=$BUILDPLATFORM ${RUST_IMAGE} AS builder
|
|
|
|
ARG RUST_TARGET=x86_64-unknown-linux-gnu
|
|
ARG CARGO_REGISTRY=sparse+https://rsproxy.cn/index/
|
|
ARG APT_MIRROR=https://mirrors.ustc.edu.cn/debian
|
|
|
|
WORKDIR /app
|
|
|
|
RUN mkdir -p /usr/local/cargo \
|
|
&& printf '[source.crates-io]\nreplace-with = "mirror"\n\n[source.mirror]\nregistry = "%s"\n' "${CARGO_REGISTRY}" > /usr/local/cargo/config.toml
|
|
|
|
RUN find /etc/apt/sources.list.d -type f \( -name "*.list" -o -name "*.sources" \) -print0 2>/dev/null \
|
|
| xargs -0 -r sed -i \
|
|
-e "s|http://archive.ubuntu.com/ubuntu|${APT_MIRROR}|g" \
|
|
-e "s|https://archive.ubuntu.com/ubuntu|${APT_MIRROR}|g" \
|
|
-e "s|http://security.ubuntu.com/ubuntu|${APT_MIRROR}|g" \
|
|
-e "s|https://security.ubuntu.com/ubuntu|${APT_MIRROR}|g" \
|
|
-e "s|http://deb.debian.org/debian-security|${APT_MIRROR}-security|g" \
|
|
-e "s|https://deb.debian.org/debian-security|${APT_MIRROR}-security|g" \
|
|
-e "s|http://security.debian.org/debian-security|${APT_MIRROR}-security|g" \
|
|
-e "s|https://security.debian.org/debian-security|${APT_MIRROR}-security|g" \
|
|
-e "s|http://deb.debian.org/debian|${APT_MIRROR}|g" \
|
|
-e "s|https://deb.debian.org/debian|${APT_MIRROR}|g" \
|
|
&& if [ -f /etc/apt/sources.list ]; then \
|
|
sed -i \
|
|
-e "s|http://archive.ubuntu.com/ubuntu|${APT_MIRROR}|g" \
|
|
-e "s|https://archive.ubuntu.com/ubuntu|${APT_MIRROR}|g" \
|
|
-e "s|http://security.ubuntu.com/ubuntu|${APT_MIRROR}|g" \
|
|
-e "s|https://security.ubuntu.com/ubuntu|${APT_MIRROR}|g" \
|
|
-e "s|http://deb.debian.org/debian-security|${APT_MIRROR}-security|g" \
|
|
-e "s|https://deb.debian.org/debian-security|${APT_MIRROR}-security|g" \
|
|
-e "s|http://security.debian.org/debian-security|${APT_MIRROR}-security|g" \
|
|
-e "s|https://security.debian.org/debian-security|${APT_MIRROR}-security|g" \
|
|
-e "s|http://deb.debian.org/debian|${APT_MIRROR}|g" \
|
|
-e "s|https://deb.debian.org/debian|${APT_MIRROR}|g" \
|
|
/etc/apt/sources.list; \
|
|
fi \
|
|
&& apt-get update \
|
|
&& apt-get install -y --no-install-recommends ca-certificates \
|
|
&& case "${RUST_TARGET}" in \
|
|
aarch64-unknown-linux-gnu) \
|
|
apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu libc6-dev-arm64-cross ;; \
|
|
x86_64-pc-windows-gnu) \
|
|
apt-get install -y --no-install-recommends binutils-mingw-w64-x86-64 gcc-mingw-w64-x86-64-posix mingw-w64-x86-64-dev ;; \
|
|
esac \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
RUN rustup target add ${RUST_TARGET}
|
|
|
|
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
|
|
ENV CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=x86_64-w64-mingw32-gcc
|
|
ENV CARGO_TARGET_X86_64_PC_WINDOWS_GNU_AR=x86_64-w64-mingw32-ar
|
|
|
|
COPY Cargo.toml Cargo.lock ./
|
|
COPY src ./src
|
|
|
|
RUN cargo build --release --target ${RUST_TARGET} \
|
|
&& mkdir -p /out \
|
|
&& if [ "${RUST_TARGET}" = "x86_64-pc-windows-gnu" ]; then \
|
|
cp target/${RUST_TARGET}/release/cdxs.exe /out/cdxs.exe; \
|
|
else \
|
|
cp target/${RUST_TARGET}/release/cdxs /out/cdxs; \
|
|
fi
|