# Tools are installed at the versions in .tool-versions.
# After changing that file, run coop build to rebuild this project's box.
# Coop's box image brings the agent CLIs and editor adapters, at the versions Coop qualifies.
ARG COOP_BASE_IMAGE=coop-box
FROM ${COOP_BASE_IMAGE}
@SYSTEM_PACKAGES@
# Coop's filtered client image keeps asdf's shims off PATH, so put them back — after the client
# launchers, which nothing may shadow.
ENV PATH="/opt/coop/bin:/home/node/.asdf/shims:${PATH}"@TOOLCHAIN_ENV@

# Install the tool versions declared by the project.
# Installation failures stop the build.
COPY --chown=node:node .tool-versions /home/node/.tool-versions
RUN cd /home/node \
 && awk 'NF && $1 !~ /^#/ {print $1}' .tool-versions | while read -r tool; do asdf plugin add "$tool" || exit 1; done \
 && MAKEFLAGS="-j$(nproc)" asdf install \
 && asdf reshim@TOOLCHAIN_SEED@

# Login shells reset PATH, so restore the same order after /etc/profile runs (this drop-in sorts
# after Coop's own, which leaves the shims out in a filtered box).
USER root
RUN printf 'export PATH="/opt/coop/bin:/home/node/.asdf/shims:$PATH"\n' > /etc/profile.d/zz-asdf.sh
USER node

WORKDIR /workspace
