FROM alpine:3.7
MAINTAINER Disassembler <disassembler@dasm.cz>

RUN \
 # Install Python2 runtime
 apk --no-cache add python2

RUN \
 # Install runtime XML dependencies
 apk --no-cache add libxml2 libxslt

RUN \
 # Install runtime dependencies
 apk --no-cache add libffi libressl uwsgi-python

RUN \
 # Install build dependencies
 apk --no-cache add --virtual .deps build-base git libffi-dev libressl-dev libxml2-dev libxslt-dev py2-pip python2-dev \
 # Install CKAN DataPusher
 && mkdir -p /srv/ckandp \
 && cd /srv/ckandp \
 && pip install -U setuptools \
 && pip install -e 'git+https://github.com/ckan/datapusher.git#egg=datapusher' \
 # Hackfix the X509_STORE_CTX wrapper
 && sed -i 's/\[security\]//' /srv/ckandp/src/datapusher/requirements.txt \
 && pip install -r /srv/ckandp/src/datapusher/requirements.txt \
 # Create OS user
 && addgroup -S -g 8004 ckandp \
 && adduser -S -u 8004 -h /srv/ckandp -s /bin/false -g ckandp -G ckandp ckandp \
 && chown -R ckandp:ckandp /srv/ckandp \
 # Cleanup
 && apk --no-cache del .deps \
 && find /srv/ckandp/src -name '.git*' -exec rm -rf {} + \
 && rm -rf /root/.cache

VOLUME ["/etc/ckandp", "/srv/ckandp/data"]
EXPOSE 8080

USER ckandp
CMD ["uwsgi", "--plugin", "python", "--http-socket", "0.0.0.0:8080", "--wsgi-file", "/etc/ckandp/datapusher.wsgi", "--enable-threads"]
