#
# Ubuntu Dockerfile
#
# https://github.com/dockerfile/ubuntu
# 
# // first build the image based on this dockerfile. From the same dir of this file run
# docker build -t eae-ubuntu-generic .
# // now run the container based on the image eae-ubuntu-generic 
# docker run -d --name bucherer-dev -v /var/www/bucherer:/var/www -p 1027:22 -p 1028:80 eae-ubuntu-generic
#

# Pull base image.
FROM ubuntu:20.04

RUN apt-get -y update --fix-missing && \
    apt-get -y upgrade 

RUN apt-get install -y software-properties-common
RUN LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php
 
RUN apt-get -y update --fix-missing && \
    apt-get install -y cron && \
    apt-get install -y curl && \
    apt-get install -y git && \
    apt-get install -y vim && \
    apt-get install -y zip && \
    apt-get install -y unzip && \
    apt-get install -y imagemagick && \
    apt-get install -y mysql-client && \
    apt-get install -y apache2 php8.1 libapache2-mod-php

RUN apt-get install -y php8.1-cli
RUN apt-get install -y php8.1-common
RUN apt-get install -y openssh-server
RUN apt-get install -y php8.1-mysql
RUN apt-get install -y php8.1-curl
RUN apt-get install -y php8.1-zip
RUN apt-get install -y php8.1-dom
RUN apt-get install -y php8.1-mbstring
RUN apt-get install -y php8.1-gd
RUN apt-get install -y php8.1-imagick
RUN apt-get install -y php8.1-intl
RUN apt-get install -y php8.1-xml
RUN apt-get install -y php8.1-bcmath
RUN apt-get install -y rsyslog
RUN apt-get install -y php8.1-xdebug
RUN apt-get install -y python

RUN update-alternatives --set php /usr/bin/php8.1
RUN a2dismod php8.1
RUN a2enmod php8.1

# this is used to run multiple services
RUN apt-get install -y supervisor 
ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
   
RUN mkdir /var/run/sshd
RUN chmod 0755 /var/run/sshd
RUN useradd --create-home --shell /bin/bash --groups sudo eae ## includes 'sudo'
RUN echo "root:p4ssw0rd" | chpasswd
RUN echo "eae:p4ssw0rd" | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config

# Add authorized_keys
RUN mkdir /root/.ssh
RUN mkdir /home/eae/.ssh

# SSH login fix. Otherwise user is kicked off after login
#RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
RUN a2enmod rewrite
RUN a2enmod expires
RUN a2enmod headers

RUN mkdir /var/www/access
ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf
ADD mpm_prefork.conf /etc/apache2/mods-enabled/mpm_prefork.conf

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=2.1.14
RUN chown eae:eae /var/www/html

USER eae
ENV NVM_DIR /home/eae/.nvm
RUN mkdir /home/eae/.nvm
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
ENV NODE_VERSION v10
RUN bin/bash -c "source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm use --delete-prefix $NODE_VERSION"
ENV NODE_PATH $NVM_DIR/versions/node/$NODE_VERSION/lib/node_modules
ENV PATH      $NVM_DIR/versions/node/$NODE_VERSION/bin:$PATH

USER root
EXPOSE 22 80
CMD ["/usr/bin/supervisord"]
