# syntax=docker/dockerfile:1
# Next.js local development — hot reload via volume mounts
# GENERATED by composable.env (ce init / scaffold:sync).
FROM node:24-alpine

# Corepack enabled; the actual pnpm version comes from package.json's
# packageManager field (via `corepack install` below), so Docker builds
# never drift from the host's pinned version.
RUN corepack enable

# Caddy for in-container TLS termination when profile.tls is true
# (unused for proxy: "caddy" profiles where a standalone Caddy fronts everything)
RUN apk add --no-cache caddy

WORKDIR /app

# Pre-install COPY: package.json drives the corepack install. .npmrc*
# is a glob — safe whether or not the project has one because the
# guaranteed-match sources keep the COPY non-empty.
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc* ./
RUN corepack install

# Workspace install: COPY apps/ + packages/ so pnpm can resolve every
# workspace dep, including pnpm dependenciesMeta.injected entries that
# turbo prune cannot serialize.
COPY apps/ ./apps/
COPY packages/ ./packages/

# Optional pnpm patches/ dir (pnpm patchedDependencies). Bind-mounting
# the build context lets us conditionally copy without erroring when
# the dir is absent. Must run BEFORE `pnpm install` so the patches are
# present at patchedDependencies resolution time.
RUN --mount=type=bind,source=.,target=/ctx,readonly \
    if [ -d /ctx/patches ]; then \
      mkdir -p ./patches && cp -r /ctx/patches/. ./patches/; \
    fi

RUN pnpm install --frozen-lockfile

# Entrypoint bypasses turbo so Docker env vars pass through to the app
COPY docker/app-entrypoint.sh /usr/local/bin/app-entrypoint.sh

# Source comes from volume mounts in dev — overlays the COPYed dirs
# docker-compose volumes: ["./apps/myapp:/app/apps/myapp"]

# command: in docker-compose passes the pnpm filter name as $1
ENTRYPOINT ["/usr/local/bin/app-entrypoint.sh"]
