# This Dockerfile builds ikoba from local sources.
# Create a source package first:
#   $ python setup.py sdist
# which should create a .tar.gz package in dist/.
# The version of this package must be set below.
#
# Please note, that we do not set valid configuration values in etc/paypal.conf
# but simply use the sample configuration. 
#

FROM ubuntu:20.04
ARG IKOBA_VERSION=0.2.dev0

MAINTAINER Uli Fouquet <uli@waeup.org>

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y tzdata
RUN apt-get install -y apt-utils build-essential
RUN apt-get install -y python2.7-dev libxml2-dev libxslt1-dev \
                       zlib1g-dev python3-virtualenv
# see https://urllib3.readthedocs.org/en/latest/security.html#openssl-pyopenssl
RUN apt-get install -y libssl-dev libffi-dev
# libs needed/useful for Pillow image manipulations
RUN apt-get install -y libjpeg-dev libfreetype6-dev libtiff-dev libopenjp2-7-dev
RUN apt-get install -y sudo git wget

# fix link needed by Pillow
RUN ln -s /usr/include/freetype2 /usr/include/freetype2/freetype

# add user `ikoba`
RUN useradd -ms /bin/bash ikoba
# set password of user `ikoba` and add to group 'sudo'
RUN echo ikoba:ikoba | chpasswd && adduser ikoba sudo

# get sources
WORKDIR /home/ikoba
ADD dist/waeup.ikoba-${IKOBA_VERSION}.tar.gz /home/ikoba/
RUN mv waeup.ikoba-${IKOBA_VERSION} waeup.ikoba

# make sure, all added files belong to `ikoba`
RUN chown -R ikoba:ikoba /home/ikoba/

USER ikoba
ENV HOME /home/ikoba

# create a virtual env
RUN virtualenv -p /usr/bin/python2.7 py27

# install ikoba -- this is the heavy part...
WORKDIR /home/ikoba/waeup.ikoba
RUN /home/ikoba/py27/bin/pip install --upgrade pip==20.3.4
RUN /home/ikoba/py27/bin/pip install --upgrade --force-reinstall setuptools==44.1.1
RUN /home/ikoba/py27/bin/pip install "zc.buildout<3"
RUN /home/ikoba/py27/bin/buildout

# install a paypal.conf with fake data
RUN cp etc/paypal-testing.conf-sample etc/paypal.conf

# this dir will contain data you might want to be persistent
VOLUME ["/home/ikoba/waeup.ikoba/var/"]

CMD /home/ikoba/waeup.ikoba/bin/ikobactl fg
