FROM oven/bun:1@sha256:9114c058aeae42162ee16dd5084b95fe9473970bb6bcb5b232ab1630f0546895

WORKDIR /app

# Install the shared @celilo/registry-server package.
# Both this e2e stand-in and the celilo-registry module run the same code —
# packages/registry-server is the single source of truth.
COPY registry-server/package.json ./package.json
COPY registry-server/tsconfig.json ./tsconfig.json
COPY registry-server/src ./src

RUN bun install --production

# Bootstrap mode: the shared-infra stand-in serves modules directly from the
# repo's modules/ directory (volume-mounted read-only). This preserves the
# pre-unification convenience where tests can `celilo module import
# namecheap` without having to publish namecheap first.
#
# The production celilo-registry module does NOT set BOOTSTRAP_MODULES_DIR
# and only serves pre-published packages.
ENV DATA_DIR=/var/lib/celilo-registry \
    BOOTSTRAP_MODULES_DIR=/modules \
    BOOTSTRAP_UPLOADS_DIR=/uploads \
    BOOTSTRAP_CACHE_DIR=/cache \
    PATH_PREFIX= \
    PORT=80

# /uploads is the drop-zone for .netapps that tests push via
# `docker compose cp`. Create the dir at build time so `docker cp` has
# somewhere to put files before the server runs.
RUN mkdir -p /uploads

# Route the customer's public prefix via the ISP edge, like every other host
# on internet-external. See config/routing/public-sim-entrypoint.sh.
RUN apt-get update \
 && apt-get install -y --no-install-recommends iproute2 \
 && rm -rf /var/lib/apt/lists/*
COPY config/routing/public-sim-entrypoint.sh /usr/local/bin/public-sim-entrypoint.sh

EXPOSE 80
ENTRYPOINT ["/bin/sh", "/usr/local/bin/public-sim-entrypoint.sh"]
CMD ["bun", "run", "src/index.ts"]
