FROM node:22-bookworm-slim

ARG KUBECTL_VERSION=v1.31.7
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright

RUN apt-get update && apt-get install -y --no-install-recommends \
      bash ca-certificates curl git gh jq python3 python3-pip \
    && curl --fail --silent --show-error --location \
      "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl" \
      --output /usr/local/bin/kubectl \
    && chmod 0755 /usr/local/bin/kubectl \
    && python3 -m pip install --break-system-packages --no-cache-dir \
      'playwright>=1.40,<2' 'pymysql>=1.1,<2' 'pyotp>=2.9,<3' 'qrcode[pil]>=7.4.2,<9' \
    && python3 -m playwright install --with-deps chromium \
    && rm -rf /var/lib/apt/lists/* /root/.cache/pip
RUN npm install --global @openai/codex@0.147.0

COPY output/bin/auto-oncall-optimizer /auto-oncall-optimizer
COPY services/auto-oncall-optimizer/bundled-skills /opt/optimizer-skills
COPY services/auto-oncall-optimizer/entrypoint.sh /entrypoint.sh

RUN chmod 0755 /entrypoint.sh \
      /opt/optimizer-skills/runtime-evidence/scripts/agent9-session-get.py \
      /opt/optimizer-skills/runtime-evidence/scripts/database-query.py \
      /opt/optimizer-skills/runtime-evidence/scripts/jira-get.sh

EXPOSE 8080

ENTRYPOINT ["/entrypoint.sh"]
