FROM registry.gitlab.com/arkindex/backend:base-0.10.1

ARG COMMON_BRANCH=master
ARG COMMON_ID=9855787
ARG PONOS_BRANCH=master
ARG PONOS_ID=10017043
ARG GITLAB_TOKEN="M98p3wihATgCx4Z5ChvK"

# Install arkindex-common from private repo
RUN \
  apk add tar && \
  mkdir /tmp/common && \
  wget --header "PRIVATE-TOKEN: $GITLAB_TOKEN" https://gitlab.com/api/v4/projects/$COMMON_ID/repository/archive.tar.gz?sha=$COMMON_BRANCH -O /tmp/common/archive.tar.gz && \
  tar --strip-components=1 -xvf /tmp/common/archive.tar.gz -C /tmp/common && \
  cd /tmp/common && python setup.py install && \
  rm -rf /tmp/common

# Install arkindex-ponos from private repo
RUN \
  mkdir /tmp/ponos && \
  wget --header "PRIVATE-TOKEN: $GITLAB_TOKEN" https://gitlab.com/api/v4/projects/$PONOS_ID/repository/archive.tar.gz?sha=$PONOS_BRANCH -O /tmp/ponos/archive.tar.gz && \
  tar --strip-components=1 -xvf /tmp/ponos/archive.tar.gz -C /tmp/ponos && \
  cd /tmp/ponos && python setup.py install && \
  rm -rf /tmp/ponos

# Install arkindex and its deps
# Uses a source archive instead of full local copy to speedup docker build
COPY dist/arkindex-*.tar.gz /tmp/arkindex.tar.gz
RUN pip install /tmp/arkindex.tar.gz gunicorn==19.9 && rm /tmp/arkindex.tar.gz

# Allow access to logs
RUN mkdir -p /logs
RUN chown -R ark:teklia /logs

# Run through supervisor
EXPOSE 80
CMD ["gunicorn", "--access-logfile=-", "--capture-output", "--bind=0.0.0.0:80", "arkindex.project.wsgi"]