from python:3.5

RUN apt-get update

RUN apt-get install -y \
    git \
    imagemagick \
    libmagickcore-dev \
    libxml2-dev \
    libxslt1-dev \
    ruby \
    ruby-dev

RUN gem install bundler

RUN apt-get install -y \
    build-essential \
    chrpath \
    libssl-dev \
    libxft-dev \
    libfreetype6 \
    libfreetype6-dev \
    libfontconfig1 \
    libfontconfig1-dev \
    wget \
    curl

# postgres client
RUN apt-get install -y \
    postgresql-client \
    postgresql-client-common \
    postgresql-contrib \
    libpq-dev

# redis client
RUN apt-get install -y redis-tools

# phantom.js
ENV PHANTOM_JS=phantomjs-2.1.1-linux-x86_64
RUN wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2
RUN tar xvjf $PHANTOM_JS.tar.bz2 && \
    mv $PHANTOM_JS /usr/local/share && \
    ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin

# nodejs
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs

# configure ssh
RUN apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:screencast' | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config

# 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 sed -ie 's/Port 22/Port 2222/g' /etc/ssh/sshd_config

# install python libs
ADD ./requirements.txt /requirements/
ADD ./requirements.test.txt /requirements/

WORKDIR /requirements

RUN pip install -r requirements.txt
RUN pip install -r requirements.test.txt

RUN pip3 install invoke


# install nodejs libs
ADD ./package.json /code/
WORKDIR /code
RUN npm install

CMD ["/usr/sbin/sshd", "-D"]
#CMD ["invoke", "serve_debug"]
