FROM alpine:latest

# 安裝必要的工具
RUN apk add --no-cache --no-check-certificate bash ca-certificates curl git jq

# 設定安裝用的環境變數
ENV CODEX_NON_INTERACTIVE=1
ENV CODEX_INSTALL_DIR=/usr/local/bin
ENV CODEX_HOME=/root/.codex

# 安裝 Codex CLI 工具
RUN install_script="$(mktemp)" \
    && curl -fsSL --retry 3 --retry-delay 2 --max-time 120 \
        https://chatgpt.com/codex/install.sh \
        -o "$install_script" \
    && sh "$install_script" \
    && rm -f "$install_script"

# 安裝技能
RUN codex plugin marketplace add https://gitea.jsc.idv.tw/plugins/doc.git \
    && codex plugin add jsc@doc \
    && codex plugin marketplace add https://gitea.jsc.idv.tw/plugins/code-review.git \
    && codex plugin add jsc@code-review

COPY entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
