FROM ubuntu:20.04

# Avoid interactive prompts
ENV DEBIAN_FRONTEND=noninteractive

# Install system dependencies
RUN apt-get update && apt-get install -y \
    python3 \
    python3-pip \
    curl \
    wget \
    tar \
    gzip \
    qemu-kvm \
    && rm -rf /var/lib/apt/lists/*

# Create app directory
WORKDIR /app

# Copy requirements first for better caching
COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt

# Copy application files
COPY slop_with_terminal.py .
COPY vars.sh .
COPY static/ ./static/
COPY config/ ./config/

# Create necessary directories
RUN mkdir -p data bin firecracker downloads Scripts

# Make scripts executable
RUN chmod +x vars.sh

# Set up environment
ENV SLOP_DATA_DIR=/app/data

# Expose port
EXPOSE 31337

# Run setup and start server
CMD ["bash", "-c", "./vars.sh && python3 slop_with_terminal.py"]