# syntax=docker/dockerfile:1@sha256:ecfaec9ed6d810b56388c508f4121597bfbba70d41a6dfeee4d8cad5f295fc32
#
# Vallus (TypeScript) — the image built from a CUSTOMER PACKAGE.
#
# Not the same file as the one in the repository, and deliberately so. That one
# compiles the server and the frontend from source; a package contains neither.
# It ships `dist/` already built, so this image only has to provide the runtime
# around it. Building the repository's Dockerfile inside a package fails on a
# missing `server/src`, which is a confusing way to learn the difference.
#
# Build context is the PACKAGE ROOT (the directory holding dist/), not this
# folder — see docker-compose.yml.

ARG PLAYWRIGHT_VERSION=v1.60.0-jammy
FROM mcr.microsoft.com/playwright:${PLAYWRIGHT_VERSION}

# build-essential: test projects pull native npm dependencies that node-gyp has
# to compile, and the Playwright base carries browsers, not a C/C++ toolchain.
#
# The static Docker CLI is what the container executor talks to; there is no
# daemon in here, only a client for the socket mounted from the host.
RUN apt-get update \
 && apt-get install -y --no-install-recommends build-essential curl ca-certificates \
 && rm -rf /var/lib/apt/lists/* \
 && set -eux; \
    arch="$(dpkg --print-architecture)"; \
    case "$arch" in \
      amd64) tarball="x86_64" ;; \
      arm64) tarball="aarch64" ;; \
      *) echo "unsupported architecture: $arch" >&2; exit 1 ;; \
    esac; \
    curl -fsSL "https://download.docker.com/linux/static/stable/${tarball}/docker-27.3.1.tgz" \
      | tar -xz --strip-components=1 -C /usr/local/bin docker/docker; \
    docker --version

WORKDIR /app
COPY package.json package-lock.json ./
# better-sqlite3 is stripped from the package (it is native and ships per
# platform), so it is fetched here for linux/x64 — the platform this image runs
# on, whatever the machine that built the package was.
RUN --mount=type=cache,target=/root/.npm npm install --omit=dev --no-audit --no-fund

COPY dist ./dist

# The runner's own data directory, and the working directory it resolves
# relative paths against.
WORKDIR /data

ENTRYPOINT ["node", "/app/dist/index.js"]
CMD ["--serve", "--port", "3500"]
