# Runtime-only image — expects Theia to already be compiled on the host.
# Run `npm run build:local` first, then `docker build -f Dockerfile.runtime ...`

FROM node:20-bookworm-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
    git \
    curl \
    libsecret-1-0 \
    libx11-6 \
    libxkbfile1 \
    && rm -rf /var/lib/apt/lists/*

RUN mkdir -p /home/node/workspace /home/node/.theia && \
    chown -R node:node /home/node

WORKDIR /home/node

# Copy the pre-compiled output from the host
COPY --chown=node:node node_modules          ./node_modules
COPY --chown=node:node packages              ./packages
COPY --chown=node:node dev-packages          ./dev-packages
COPY --chown=node:node examples/browser      ./examples/browser
COPY --chown=node:node package.json          ./package.json

COPY startup-custom.sh /startup.sh
RUN chmod +x /startup.sh && chown node:node /startup.sh

USER node
EXPOSE 3000
ENTRYPOINT ["/startup.sh"]
