Files
tuwunel/docker/Dockerfile.cargo.install
2025-05-31 10:36:39 +00:00

82 lines
2.3 KiB
Docker

# syntax = docker/dockerfile:1.11-labs
FROM input AS installer
ARG sys_target
ARG rust_toolchain
ARG RUSTUP_HOME
ARG CARGO_HOME
ARG CARGO_TARGET
ARG CARGO_TARGET_DIR
ARG CARGO_TARGET_CACHE
ARG cargo_profile
ARG cargo_features
ARG cargo_spec_features
ARG cargo_args=""
ARG crate_path="src/main"
ARG crate_ident=""
ARG install_temp="/usr/src/tuwunel/install"
WORKDIR /
COPY --link --from=input . .
WORKDIR /usr/lib/${sys_target}
COPY --link --from=rocksdb . .
WORKDIR /usr/src/tuwunel
RUN \
--mount=type=cache,dst=${RUSTUP_HOME},sharing=locked \
--mount=type=cache,dst=${CARGO_HOME},sharing=locked \
--mount=type=cache,dst=${CARGO_TARGET_DIR},sharing=locked \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/deps,id=${CARGO_TARGET_CACHE}/deps,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/build,id=${CARGO_TARGET_CACHE}/build,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/incremental,id=${CARGO_TARGET_CACHE}/incremental,sharing=shared \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/.fingerprint,id=${CARGO_TARGET_CACHE}/fingerprint,sharing=shared \
<<EOF
set -eux
case "$cargo_profile" in
"dev") profile_dir="debug";;
"test") profile_dir="debug";;
"release") profile_dir="release";;
"bench") profile_dir="release";;
*) profile_dir="$cargo_profile";;
esac
rustup run ${rust_toolchain} \
cargo install \
--locked \
--no-track \
"${cargo_spec_features}" \
--features "${cargo_features}" \
--profile "${cargo_profile}" \
--target "${CARGO_TARGET}" \
--target-dir "${CARGO_TARGET_DIR}" \
--root "${install_temp}" \
--path "${crate_path}" \
${cargo_args} \
${crate_ident}
EOF
RUN [ -f "${install_temp}/bin/tuwunel" ]
FROM input AS install
ARG sys_target
ARG CARGO_INSTALL_ROOT
ARG install_temp="/usr/src/tuwunel/install"
WORKDIR /
COPY --link --from=input . .
RUN \
--mount=type=bind,from=output,src=${install_temp},dst=/mnt/install \
<<EOF
set -eux
cp -ndR --preserve=all -t ${CARGO_INSTALL_ROOT} /mnt/install/*
EOF
ENV bin_path="${CARGO_INSTALL_ROOT}/bin/tuwunel"
RUN <<EOF
set -eux
ldd -v ${bin_path} || echo "static"
du -h ${bin_path}
sha1sum ${bin_path}
EOF