FROM node:20.15-bullseye-slim

ARG DEPENDENCIES="                    \
        g++                           \
        make                          \
        python3"

RUN set -ex \
    && rm -f /etc/apt/apt.conf.d/docker-clean \
    && echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache \
    && apt-get update \
    && apt-get -y install --no-install-recommends ${DEPENDENCIES} \
    && echo "no" | dpkg-reconfigure dash

WORKDIR /data

COPY package.json yarn.lock ./

ARG NPM_MIRROR="https://registry.npmjs.org"
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn,sharing=locked,id=yarn-cache \
    sed -i "s|https://registry.npmmirror.com|${NPM_MIRROR}|g" yarn.lock \
    && yarn install
