File size: 2,021 Bytes
39c3a2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
FROM ubuntu:22.04

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV MAAS_DBUSER=maas
ENV MAAS_DBPASS=maas
ENV MAAS_DBNAME=maasdb

# Install system dependencies
RUN apt-get update && apt-get install -y \
    software-properties-common \
    postgresql \
    postgresql-contrib \
    python3 \
    python3-pip \
    python3-venv \
    nginx \
    supervisor \
    net-tools \
    bridge-utils \
    vlan \
    iptables \
    dnsmasq \
    openvswitch-switch \
    qemu-kvm \
    libvirt-daemon-system \
    libvirt-clients \
    curl \
    wget \
    gnupg2 \
    lsb-release \
    && rm -rf /var/lib/apt/lists/*

# Add MAAS PPA and install MAAS
RUN add-apt-repository ppa:maas/3.4 -y && \
    apt-get update && \
    apt-get install -y maas maas-dhcp maas-dns maas-proxy && \
    rm -rf /var/lib/apt/lists/*

# Create Python virtual environment
RUN python3 -m venv /opt/maas-env
ENV PATH="/opt/maas-env/bin:$PATH"

# Install Python dependencies
COPY requirements.txt /tmp/
RUN pip install --no-cache-dir -r /tmp/requirements.txt

# Create necessary directories
RUN mkdir -p /opt/maas-config /var/log/supervisor /opt/scripts

# Copy configuration files
COPY config/ /opt/maas-config/
COPY scripts/ /opt/scripts/
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Set up PostgreSQL
RUN service postgresql start && \
    sudo -u postgres createuser --createdb $MAAS_DBUSER && \
    sudo -u postgres psql -c "ALTER USER $MAAS_DBUSER WITH PASSWORD '$MAAS_DBPASS';" && \
    sudo -u postgres createdb $MAAS_DBNAME --owner $MAAS_DBUSER

# Initialize MAAS
RUN service postgresql start && \
    maas init region+rack --database-uri postgresql://$MAAS_DBUSER:$MAAS_DBPASS@localhost/$MAAS_DBNAME && \
    maas createadmin --username admin --password admin --email admin@example.com

# Expose ports
EXPOSE 5240 5241 5242 5243 5248 5250 67 53 80 443 8080 9090

# Set working directory
WORKDIR /opt/scripts

# Start supervisor
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]