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

RUN apk --no-cache add python2

RUN apk --no-cache add libxml2 libxslt

RUN apk --no-cache add libjpeg-turbo libmagic libpq py2-pip zlib \
 && apk --no-cache add --virtual .deps git build-base libjpeg-turbo-dev libxml2-dev libxslt-dev postgresql-dev python2-dev zlib-dev \
 && echo 'http://repository.fit.cvut.cz/mirrors/alpine/edge/testing' >>/etc/apk/repositories \
 && apk --no-cache add geos \
 && ln -s /lib/ld-musl-x86_64.so.1 /lib/libc.so.1 \
 && mkdir -p /srv/ckan \
 && cd /srv/ckan \
 && pip install -U setuptools \
 && pip install -e 'git+https://github.com/ckan/ckan.git#egg=ckan' \
 && sed -i 's/psycopg2==2.4.5/psycopg2==2.7.1/' /srv/ckan/src/ckan/requirements.txt \
 && pip install -r /srv/ckan/src/ckan/requirements.txt \
 && pip install -e 'git+https://github.com/ckan/ckanext-basiccharts#egg=ckanext_basiccharts' \
 && pip install -e 'git+https://github.com/ckan/ckanext-spatial#egg=ckanext_spatial' \
 && pip install -e 'git+https://github.com/ckan/ckanext-geoview#egg=ckanext_geoview' \
 && pip install -e 'git+https://github.com/ckan/ckanext-mapviews#egg=ckanext_mapviews' \
 && pip install -e 'git+https://github.com/ckan/ckanext-pages#egg=ckanext_pages' \
 && pip install -e 'git+https://github.com/XVTSolutions/ckanext-spatialUI#egg=ckanext_spatialui' \
 && pip install -e 'git+https://github.com/aptivate/ckanext-datasetthumbnail#egg=ckanext_datasetthumbnail' \
 && pip install -e 'git+https://github.com/datagvat/ckanext-dgvat_xls#egg=ckanext_dgvat_xls' \
 && pip install -r /srv/ckan/src/ckanext-spatial/pip-requirements.txt \
 && pip install -r /srv/ckan/src/ckanext-dgvat-xls/requirements.txt \
 && addgroup -S -g 8003 ckan \
 && adduser -S -u 8003 -h /srv/ckan -s /bin/false -g ckan -G ckan ckan \
 && chown -R ckan:ckan /srv/ckan \
 && apk del .deps \
 && find /srv/ckan/src -name '.git*' -exec rm -rf {} + \
 && rm -rf /root \
 && mkdir /root

VOLUME ["/etc/ckan", "/srv/ckan/storage"]
EXPOSE 8003

USER ckan
CMD ["paster", "serve", "/etc/ckan/ckan.ini"]
