FROM python:3.12-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
 && rm -rf /var/lib/apt/lists/*

RUN ln -sf /usr/local/bin/python3 /usr/bin/python3

WORKDIR /app

COPY . /app/
RUN mkdir -p /app/cgi-bin \
 && cp /app/*.py /app/*.cgi /app/cgi-bin/ \
 && cp /app/words.txt /app/cgi-bin/ \ 
 && cp /app/*.html /app/cgi-bin/

RUN chmod +x /app/index.cgi
RUN chmod +x /app/cgi-bin/*.py /app/cgi-bin/*.cgi || true

EXPOSE 8000
CMD ["python", "-m", "http.server", "8000", "--cgi"]