FROM ubuntu:22.04

# Install required packages
RUN apt-get update && apt-get install -y \
    curl \
    docker.io \
    bc \
    && rm -rf /var/lib/apt/lists/*

# Copy the monitoring script
COPY gpu_memory_monitor.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/gpu_memory_monitor.sh

# Create a non-root user
RUN useradd -m -s /bin/bash monitor

# Set environment variables with defaults
ENV CHECK_INTERVAL=60
ENV MIN_AVAILABLE_PERCENT=70
ENV AUTO_FIX=true

# Run as non-root user
USER monitor
WORKDIR /home/monitor

CMD ["/usr/local/bin/gpu_memory_monitor.sh"]
