FROM python:3.12-slim

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

WORKDIR /app

COPY requirements-agent.txt /tmp/requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt

COPY runtime_adapters.py .
COPY engine_bootstrap.py template_engine_store.py template_engine_probe.py template_engine_control.py template-engine-api.json template-engine-publisher.pem ./
COPY agent.py .
COPY startup_commands.py .
COPY rust_rcon.py .
COPY sdtd_telnet.py .
COPY ark_rcon.py .
COPY palworld_rest.py .
COPY game_templates.py .
COPY game_launchers.py .
COPY generic_templates.py .
COPY custom_templates.py .
COPY custom_download.py .
COPY template_setup.py .
COPY manual_templates.py .
COPY manual_install.py .
COPY manual_ports.py .
COPY template_library.py .
COPY update_preservation.py .
COPY --chown=10001:10001 generic-game-templates ./generic-game-templates
RUN chmod 700 generic-game-templates && chmod 600 generic-game-templates/*.json
COPY game-templates ./game-templates
COPY game_launcher.sh .

RUN useradd --create-home --uid 10001 agent

USER agent

EXPOSE 8100

CMD ["gunicorn", "--bind", "0.0.0.0:8100", "--workers", "2", "agent:app"]
