FROM oven/bun:1.4-debian

RUN apt update
RUN apt install -y curl bash nano wget zip unzip

ENV NODE_ENV=production
ENV BUN_FEATURE_FLAG_DISABLE_STREAMING_INSTALL=1
ENV PAGE_LASTMOD_FILE=/data/page-lastmod.json

RUN mkdir /app

WORKDIR /app

RUN touch /root/.bashrc
RUN echo 'alias ll="ls -laF"' >/root/.bashrc

COPY . /app/.

RUN bun install

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENV NODE_ENV=production

HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
    CMD curl -fsS "http://localhost:${PORT:-3000}/api/health" || exit 1

ENTRYPOINT ["/entrypoint.sh"]
