FROM ubuntu:22.04

# Set timezone and avoid interactive prompts
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Shanghai

# Update package list and install required packages
RUN apt-get update && \
    apt-get install -y \
    bind9 \
    bind9utils \
    bind9-doc \
    supervisor \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Create supervisor configuration directory
RUN mkdir -p /etc/supervisor/conf.d

# Copy supervisor configuration
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Copy BIND9 configuration files
COPY named.conf.local /etc/bind/named.conf.local
COPY db.argus.com /etc/bind/db.argus.com

# Copy startup and reload scripts
COPY startup.sh /usr/local/bin/startup.sh
COPY reload-bind9.sh /usr/local/bin/reload-bind9.sh

# Make scripts executable
RUN chmod +x /usr/local/bin/startup.sh /usr/local/bin/reload-bind9.sh

# Set proper ownership for BIND9 files
RUN chown bind:bind /etc/bind/named.conf.local /etc/bind/db.argus.com

# Expose DNS port
EXPOSE 53/tcp 53/udp

# Use root user as requested
USER root

# Start with startup script
CMD ["/usr/local/bin/startup.sh"]