# Use an official Python runtime as a parent image
FROM ubuntu

# Define environment variable
ENV NAME WODA.localhost
ENV USERNAME freemiumUser
ENV WORKDIR /home/$USERNAME/$NAME
ENV PATH .:/home/$USERNAME/scripts:/root/scripts:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# Set the working directory to /app
WORKDIR $WORKDIR

# Install any needed packages specified in requirements.txt
#RUN pip install --trusted-host pypi.python.org -r requirements.txt
RUN apt-get update && apt-get install -y \
	apt-utils \
	git \
	curl \
	tree \
	vim \
	unzip \
	# install nginx and python pip
	net-tools \
	nginx \
	python-pip \
	&& rm -rf /var/lib/apt/lists/* \
	&& useradd -ms /bin/bash $USERNAME

# Copy the current directory contents into the container at /home/$USERNAME/$NAME
COPY . /home/$USERNAME/$NAME/Docker/Workspace
RUN chmod +x /home/$USERNAME/$NAME/Docker/Workspace/install.eamd.sh 
RUN export PATH=.:$PATH

# install uwsgi and supervisord
RUN pip install --upgrade pip
RUN pip install uwsgi flask supervisor

RUN useradd -ms /bin/bash aurora && \
    rm -f /etc/nginx/fastcgi.conf /etc/nginx/fastcgi_params && \
    rm -f /etc/nginx/snippets/fastcgi-php.conf /etc/nginx/snippets/snakeoil.conf

COPY ./app /home/aurora/app
# 
VOLUME [ "/home/aurora/web" ]

# Make port 80 available to the world outside this container
EXPOSE 80
EXPOSE 443

COPY nginx/ssl /etc/nginx/ssl
COPY nginx/snippets /etc/nginx/snippets
COPY nginx/sites-available /etc/nginx/sites-available

COPY supervisord/supervisord.conf /etc/supervisord.conf
COPY nginx/uwsgi/wsgi.ini /etc/uwsgi/wsgi.ini


# install WODA as EAMD.ucp repository
RUN bash /home/$USERNAME/$NAME/Docker/Workspace/install.eamd.sh .



# Run app.py when the container launches
#CMD ["python", "app.py"]
#CMD ["bash"]

# ENTRYPOINT ["/usr/sbin/nginx", "-g", "daemon off;"]
ENTRYPOINT ["/usr/local/bin/supervisord"]