# syntax = docker/dockerfile:1.11-labs

FROM input AS lychee
ARG rust_toolchain="nightly"
ARG RUSTUP_HOME
ARG CARGO_HOME
ARG lychee_cache_age="7d"
ARG lychee_mode="color"
# .lycheecache is hardcoded as path to reg file in the cwd so we execute lychee
# in cache directory itself. all paths here should be absolute paths
ARG lychee_args="/usr/src/tuwunel/docs /usr/src/tuwunel/*.md"

WORKDIR /
COPY --link --from=input . .

WORKDIR /usr/src/
RUN \
--mount=type=cache,dst=${RUSTUP_HOME}/downloads,sharing=shared \
--mount=type=cache,dst=${CARGO_HOME}/registry,sharing=shared \
--mount=type=cache,dst=${CARGO_HOME}/git,sharing=shared \
--mount=type=cache,dst=lychee,sharing=locked \
<<EOF
    set -eux
    cd lychee
    rustup run ${rust_toolchain} \
        lychee \
            --verbose \
            --no-progress \
            --offline \
            --cache \
            --max-cache-age "${lychee_cache_age}" \
            --mode "${lychee_mode}" \
            --exclude /usr/src/tuwunel/contributing.md \
            --exclude /usr/src/tuwunel/development/testing.md \
            ${lychee_args}
EOF
