FROM nginx:latest

MAINTAINER Markus Willman

SHELL ["/bin/bash", "-c"]

# update the system, install python and create symlinks and directories
RUN apt-get update -qqy --fix-missing \
	&& apt-get upgrade -qqy \
	&& apt-get install -qqy --no-install-recommends \
	build-essential \
	python \
	python-dev \
	python-pip \
	python-setuptools \
	supervisor \
	unzip \
	&& apt-get clean \
	&& rm -f /etc/nginx/nginx.conf \
	&& rm -f /etc/nginx/conf.d/default.conf \
	&& mkdir -p /opt/services/smartbusstop \
	&& ln -s /opt/services/smartbusstop/conf/nginx/nginx.conf /etc/nginx/nginx.conf \
	&& ln -s /opt/services/smartbusstop/conf/nginx/default.conf /etc/nginx/conf.d/default.conf \
	&& ln -s /opt/services/smartbusstop/conf/supervisor/nginx.conf /etc/supervisor/conf.d/01_nginx.conf \
	&& ln -s /opt/services/smartbusstop/conf/supervisor/smartbusstop.conf /etc/supervisor/conf.d/02_smartbusstop.conf \
	&& apt-get autoremove -y

WORKDIR /opt/services/smartbusstop

COPY . /opt/services/smartbusstop
ADD http://data.foli.fi/gtfs/gtfs.zip /opt/services/smartbusstop/data/gtfs.zip

# install python dependencies opencv-python needs libgtk2.0-dev installed in the system, if we want to install it here (virtualenv pip)
RUN pip --no-cache-dir install -r /opt/services/smartbusstop/system-requirements.txt \
	&& rm -f /opt/services/smartbusstop/system-requirements.txt \
	&& virtualenv /opt/services/smartbusstop/.venv \
	&& source /opt/services/smartbusstop/.venv/bin/activate \
	&& pip --no-cache-dir install -r /opt/services/smartbusstop/requirements.txt \
	&& rm -f /opt/services/smartbusstop/requirements.txt \
	&& mkdir -p /opt/services/smartbusstop/data/gtfs \
	&& unzip /opt/services/smartbusstop/data/gtfs.zip -d /opt/services/smartbusstop/data/gtfs \
	&& rm /opt/services/smartbusstop/data/gtfs.zip \
	&& /opt/services/smartbusstop/scripts/babel_compile.sh

EXPOSE 80
STOPSIGNAL SIGTERM

CMD ["/usr/bin/supervisord", "-n"]
