FROM apache/airflow:2.8.1-python3.11

# 1. Switch to root to install system dependencies
USER root

# 2. Install Docker CLI (Required for your DAG to spawn containers)
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release && \
    curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg && \
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \
    apt-get update && \
    apt-get install -y docker-ce-cli && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# 3. Create the 'docker' group and add 'airflow' user to it
# This allows the airflow user to touch the mounted /var/run/docker.sock
RUN groupadd -g 999 docker && usermod -aG docker airflow

# 4. Switch back to airflow user for python packages
USER airflow

# 5. Install your Python dependencies
RUN pip install --no-cache-dir \
    psycopg2-binary \
    apache-airflow-providers-slack