IMAGE opendatakit-build_0.3.5-210106
FROM alpine3.12-ruby2.4_2.4.10-210106

RUN EOF
    # Install runtime dependencies
    apk --no-cache add libpq nodejs openssl

    # Install build dependencies
    apk --no-cache add --virtual .deps build-base git linux-headers make npm openjdk8-jre-base postgresql-dev

    # Clone ODK Build
    git clone --depth 1 https://github.com/getodk/build /srv/opendatakit-build

    # Install Ruby dependencies
    cd /srv/opendatakit-build
    gem install bundler:1.13.6
    bundle install --without test
    rake deploy:build

    # Clone build2xlsform
    git clone --depth 1 https://github.com/getodk/build2xlsform /srv/build2xlsform
    cd /srv/build2xlsform
    make

    # Create OS user
    addgroup -S -g 8080 odkbuild
    adduser -S -u 8080 -h /srv/opendatakit-build -s /bin/false -g odkbuild -G odkbuild odkbuild
    chown -R odkbuild:odkbuild /srv/opendatakit-build
    chown -R odkbuild:odkbuild /srv/build2xlsform

    # Cleanup
    apk --no-cache del .deps
    find /srv -name '.git*' -exec rm -rf {} +
    rm -rf /.bundle /root/.config /root/.npm
EOF

COPY opendatakit-build.image.d

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