# Shopify CLI addon image (contract G.1): installed in the toolbox (its Node runs the CLI), shipped
# as the installed tree only, mounted read-only at /opt/addons/shopify.
#
# Not pinned: every rebuild (`handler image rebuild addon:shopify`, or the web UI) installs the latest
# release; the build fails if the installed version cannot be read.
ARG TOOLBOX_IMAGE=localhost/handler-ai-toolbox:latest
FROM ${TOOLBOX_IMAGE} AS build
ARG PREFIX=/opt/addons/shopify

# npm skips install scripts by default: only an esbuild optimization is lost (checked: the CLI
# works without it). The rebuild's check (`shopify version`) catches a release that needs one.
RUN npm install --prefix "$PREFIX" --no-fund --no-audit @shopify/cli \
    && npm cache clean --force \
    && mkdir -p "$PREFIX/bin" \
    && ln -s ../node_modules/.bin/shopify "$PREFIX/bin/shopify" \
    && version="$(jq -er .version "$PREFIX/node_modules/@shopify/cli/package.json")" \
    && echo "Shopify CLI ${version}" > "$PREFIX/version" \
    && rm -rf /home/agent  # build-time npm logs (npm runs as root with HOME=/home/agent)

FROM scratch
COPY --from=build /opt/addons/shopify /
LABEL org.opencontainers.image.title="handler-ai-addon-shopify"
