IMAGE openmapkit_0.12.0-201021
FROM alpine3.10-nodejs10_10.19.0-201021
# libxmljs installation fails on nodejs>10

RUN EOF
    # Install runtime dependencies
    apk --no-cache add python2 openjdk8-jre-base

    # Install build dependencies
    apk --no-cache add --virtual .deps build-base git npm py2-pip yarn

    # Clone OpenMapKit
    git clone --recursive --depth 1 https://github.com/posm/OpenMapKitServer /srv/openmapkit

    # Install OpenMapKit dependencies
    cd /srv/openmapkit
    pip install -r requirements.txt
    npm install
    cd frontend
    yarn
    yarn build

    # Create OS user
    addgroup -S -g 8080 omk
    adduser -S -u 8080 -h /srv/openmapkit -s /bin/false -g omk -G omk omk
    chown -R omk:omk /srv/openmapkit

    # Cleanup
    apk --no-cache del .deps
    find /srv/openmapkit -name '.git*' -exec rm -rf {} +
    rm -rf /usr/local/share/.cache
    rm -rf /root/.cache /root/.config /root/.node-gyp /root/.npm
EOF

# s6 required for single service due to inability of nodejs to process signals when running as PID 1
COPY image.d

CMD /bin/s6-svscan /etc/services.d
