FROM ubuntu:jammy

# Avoid user interaction while running apt
ENV DEBIAN_FRONTEND=noninteractive

# Update, upgrade and install packages, unminimize the Ubuntu image
RUN apt-get update && apt-get install -y\
    vim \
    systemd \
    openssh-server \
    sudo \
    php-fpm \
    php-xml \
    lsb-core \
    iproute2 \
    iputils-ping \
    python-is-python3 \
    python3-pip\
    nginx \
    golang \
    fdisk

RUN yes | unminimize

# Create low-priv user, set up passwords (for low-priv user and root)
RUN useradd john -m -s /bin/bash
RUN echo 'john:placeholder_password' | chpasswd
RUN echo 'root:placeholder_password' | chpasswd

${services}

RUN echo 'Available vhosts: ${hostnames}' >> /var/www/html/index.nginx-debian.html
RUN chown -R john: /var/www/*
COPY configs/nginx.conf /etc/nginx/nginx.conf
COPY configs/sshd_config /etc/ssh/sshd_config
${nginx_put_method}

# Fix perms on copied config files
RUN find /etc/nginx/ -type d -exec chmod 0755 {} \;
RUN find /etc/nginx/ -type f -exec chmod 0644 {} \;
RUN find /etc/php/ -type d -exec chmod 0755 {} \;
RUN find /etc/php/ -type f -exec chmod 0644 {} \;

# Enable systemctl services
RUN systemctl enable ssh
RUN systemctl enable nginx

# Forward ports
EXPOSE 22 80

# Set workdir
WORKDIR /root

# Run systemd
CMD ["/lib/systemd/systemd"]