FROM ubuntu:14.04
MAINTAINER Roni Choudhury <roni.choudhury@kitware.com>

EXPOSE 3000

# Make a package source for Mongo 3.
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
RUN echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" >/etc/apt/sources.list.d/mongodb-org-3.2.list

RUN apt-get update

RUN apt-get install -y \
    python \
    python-pip \
    git \
    npm \
    mongodb-org \
    wget

RUN pip install \
    pymongo \
    tangelo

# Create a tangelo user
RUN useradd -c "tangelo user" -m -d /home/tangelo -s /bin/bash tangelo

# Need to symlink node to nodejs because Ubuntu names things in a way that npm
# doesn't expect.
RUN ln -s /usr/bin/nodejs /usr/bin/node

# Clone the repo.
RUN git clone https://gitlab.kitware.com/ronichoudhury/progeny-demo.git

# Install gulp.
RUN npm install -g gulp

# Change ownership of directory to tangelo.
RUN chown -R tangelo:tangelo progeny-demo

# Switch to tangelo user.
USER tangelo
ENV HOME /home/tangelo

WORKDIR progeny-demo

# Check out the correct commit.
RUN git checkout 66ca547405ce3b8c555e3dcbf3e4e42a4aca6f7f
RUN git reset --hard

# Build.
RUN npm install
RUN gulp

# Link the right config file.
RUN ln -s /progeny-demo/configs/public.yaml build/site/config.yaml

# Download and unpack the image data.
RUN wget https://data.kitware.com/api/v1/file/56463edc8d777f7522dbf6a5/download -O SUN2012.tar.gz
RUN tar xzvf SUN2012.tar.gz
RUN ln -s /progeny-demo/SUN2012/Images build/site/Images

# Set up some demodock vars.
ENV DEMODOCK_KEY clique

USER root

# Create a directory for Mongo to use.
RUN mkdir -p /data/db

# Download the database file.
RUN wget https://data.kitware.com/api/v1/file/568d58db8d777f429eac8ecb/download -O sun.archive.gz

# Start the clique application when this image is run.
COPY run.sh /progeny-demo/
ENV DEMODOCK_NAME "Image Similarity Graph (Clique)"
ENV DEMODOCK_DESCRIPTION "Visualizing image similarity using an interactive Clique graph. Right click on an image to expand its neighbors, and use the semantic zoom to explore clusters of tightly related images."
ENV DEMODOCK_IMG "/clique/assets/clique-poster.png"
ENV DEMODOCK_READY TRUE
CMD ["sh", "run.sh"]
