FROM python:2.7-slim

RUN groupadd --gid 1001 app && \
    useradd --uid 1001 --gid 1001 --shell /usr/sbin/nologin app

ENV LANG C.UTF-8

WORKDIR /app

# install syncserver dependencies
COPY ./requirements.txt /app/requirements.txt
COPY ./dev-requirements.txt /app/dev-requirements.txt
COPY ./syncserver /app/syncserver
COPY ./setup.py /app

RUN apt-get -qq update && \
    apt-get -qq --yes install g++ curl && \
    pip install --upgrade --no-cache-dir -r requirements.txt && \
    pip install --upgrade --no-cache-dir -r dev-requirements.txt && \
    apt-get -qq --yes remove --purge g++ && \
    apt-get -qq --yes autoremove --purge && \
    apt-get -qq --yes clean all && \
    rm -rf "/usr/share/doc/"* \
           "/var/cache/"* \
           "/var/lib/apt/lists/"* \
           "/usr/src/"* \
           "/var/cache/"* \
           "/var/log/"{apt/*,dpkg.log} \
           "/var/www/html" \
           "/tmp/"* && \
    python ./setup.py develop

# Add Tini
ENV "TINI_VERSION" "v0.16.1"
ADD "https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini" "/tini"
RUN chmod +x "/tini"
ENTRYPOINT ["/tini", "--"]

# run as non priviledged user
USER app

CMD [ "/usr/local/bin/gunicorn", "--paste", "/app/config/syncserver.ini" ]
