Files
tuwunel/docker/Dockerfile.cargo.deps
Jason Volk 9507ce9d03 docker: Fix target mount cache paths; relax locks on cargo home.
docker: Persist lychee cache.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-06-02 02:49:14 +00:00

72 lines
2.8 KiB
Docker

# syntax = docker/dockerfile:1.11-labs
FROM input AS deps
ARG sys_target
ARG rust_toolchain
ARG RUSTUP_HOME
ARG CARGO_HOME
ARG CARGO_TARGET
ARG CARGO_TARGET_DIR
ARG cargo_tgt_dst
ARG cargo_tgt_sub
ARG cargo_tgt_cache
ARG CARGO_BUILD_RUSTFLAGS
ARG CARGO_PROFILE_TEST_DEBUG
ARG CARGO_PROFILE_BENCH_DEBUG
ARG CARGO_PROFILE_BENCH_LTO
ARG CARGO_PROFILE_BENCH_CODEGEN_UNITS
ARG CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_DEBUG
ARG cargo_profile
ARG cargo_features
ARG cargo_spec_features
ARG cook_args
ARG git_checkout
WORKDIR /
COPY --link --from=input . .
WORKDIR /usr/lib/${sys_target}
COPY --link --from=rocksdb . .
WORKDIR /usr/src/tuwunel
COPY --link --from=recipe recipe.json .
ENV CARGO_TARGET_DIR="${CARGO_TARGET_DIR}"
ENV CARGO_BUILD_RUSTFLAGS="${CARGO_BUILD_RUSTFLAGS}"
ENV CARGO_PROFILE_TEST_DEBUG="${CARGO_PROFILE_TEST_DEBUG}"
ENV CARGO_PROFILE_BENCH_DEBUG="${CARGO_PROFILE_BENCH_DEBUG}"
ENV CARGO_PROFILE_BENCH_LTO="${CARGO_PROFILE_BENCH_LTO}"
ENV CARGO_PROFILE_BENCH_CODEGEN_UNITS="${CARGO_PROFILE_BENCH_CODEGEN_UNITS}"
ENV CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_DEBUG="${CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_DEBUG}"
RUN \
--mount=type=cache,dst=${RUSTUP_HOME}/downloads,sharing=shared,ro \
--mount=type=cache,dst=${CARGO_HOME}/registry,sharing=shared,ro \
--mount=type=cache,dst=${CARGO_HOME}/git,sharing=shared,ro \
--mount=type=cache,dst=${CARGO_TARGET_DIR},id=${cargo_tgt_dst}/${cargo_tgt_sub},sharing=locked \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/${cargo_tgt_sub}/deps,id=${cargo_tgt_cache}/deps,sharing=locked \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/${cargo_tgt_sub}/build,id=${cargo_tgt_cache}/build,sharing=locked \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/${cargo_tgt_sub}/incremental,id=${cargo_tgt_cache}/incremental,sharing=locked \
--mount=type=cache,dst=${CARGO_TARGET_DIR}/${cargo_tgt_sub}/.fingerprint,id=${cargo_tgt_cache}/fingerprint,sharing=locked \
<<EOF
set -eux
rustup run ${rust_toolchain} \
cargo chef cook ${cook_args} \
--frozen \
--workspace \
"${cargo_spec_features}" \
--features "${cargo_features}" \
--profile "${cargo_profile}" \
--target "${CARGO_TARGET}" \
--target-dir "${CARGO_TARGET_DIR}" \
--manifest-path Cargo.toml \
--recipe-path recipe.json
# If this image is further reused with other cargo commands, all
# modifications made by cargo chef cook outside of target-dir have to be
# cleared. If not, resulting build artifacts will link incorrectly, even
# without error. For example, a target executable may be produced which
# does nothing except exit(0). If you have observed a smoketest failing in
# such a manner, investigate this as a cause of the issue.
git restore -W -S --source=${git_checkout} .
EOF