# stack-laravel — the container image a `runners.<role>.sandbox: container`
# role runs in when the project composes this pack and sets no
# runners.<role>.sandbox_image (STORY-348 T-PB-348b, AC-2). lib/sandbox.sh
# builds it on first use as `harness-stack-laravel:<content hash>`; editing
# this file changes the tag, so a stale image is never reused.
#
# What it carries: PHP 8.3 CLI (the official image already compiles in every
# extension a Laravel 11/12 skeleton requires — ctype, curl, dom, fileinfo,
# mbstring, openssl, pdo_sqlite, tokenizer, xml), Composer 2, and Node 22
# copied from the official image — a Laravel application builds its front end
# with Vite, so a Laravel + Vue repository (stack-laravel then stack-vue-ts)
# resolves to THIS image and still has its node toolchain. Plus the engine's
# GNU userland and the agent client.
#
# HOME is a world-writable /home/agent (the container runs as the operator's
# uid on Linux hosts), and Composer's cache lives under it. AGENT_CLIENT_NPM=''
# builds without a client.
ARG PHP_VERSION=8.3
ARG NODE_VERSION=22
ARG COMPOSER_VERSION=2
FROM composer:${COMPOSER_VERSION} AS composer
FROM node:${NODE_VERSION}-alpine AS node
FROM php:${PHP_VERSION}-cli-alpine

ARG AGENT_CLIENT_NPM=@anthropic-ai/claude-code

ENV HOME=/home/agent \
    COMPOSER_HOME=/home/agent/.composer \
    COREPACK_ENABLE_DOWNLOAD_PROMPT=0 \
    USE_BUILTIN_RIPGREP=0

COPY --from=composer /usr/bin/composer /usr/local/bin/composer
COPY --from=node /usr/local/bin/node /usr/local/bin/node
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules

RUN apk add --no-cache bash git jq ca-certificates coreutils findutils grep sed gawk \
      diffutils util-linux tar unzip libgcc libstdc++ ripgrep \
 && ln -s ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
 && ln -s ../lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx \
 && ln -s ../lib/node_modules/corepack/dist/corepack.js /usr/local/bin/corepack \
 && if [ -n "$AGENT_CLIENT_NPM" ]; then npm install -g --no-fund --no-audit $AGENT_CLIENT_NPM; fi \
 && npm cache clean --force \
 && rm -rf "$HOME" && mkdir -p "$HOME" && chmod 1777 "$HOME"

WORKDIR /workspace
CMD ["bash"]
