FROM ruby
LABEL maintainer="Disassembler <disassembler@dasm.cz>"

RUN \
 # Install NodeJS runtime
 apk --no-cache add nodejs

RUN \
 # Install runtime dependencies
 apk --no-cache add libpq

RUN \
 # Install build dependencies for ODK Build
 apk --no-cache add --virtual .deps build-base git linux-headers openjdk8-jre-base postgresql-dev \
 # Clone ODK Build
 && git clone --depth 1 https://github.com/opendatakit/build /srv/opendatakit-build \
 # Install Ruby dependencies
 && cd /srv/opendatakit-build \
 && bundle install --without test \
 && rake deploy:build \
 # Create OS user
 && addgroup -S -g 8017 odkbuild \
 && adduser -S -u 8017 -h /srv/opendatakit-build -s /bin/false -g odkbuild -G odkbuild odkbuild \
 && chown -R odkbuild:odkbuild /srv/opendatakit-build \
 # Cleanup
 && apk --no-cache del .deps \
 && find /srv/opendatakit-build -name '.git*' -exec rm -rf {} + \
 && rm -rf /root/.bundle

RUN \
 # Install build dependencies for build2xlsform
 apk --no-cache add --virtual .deps git make npm \
 # Clone build2xlsform
 && git clone --depth 1 https://github.com/opendatakit/build2xlsform /srv/build2xlsform \
 && cd /srv/build2xlsform \
 && make \
 # Change ownership
 && chown -R odkbuild:odkbuild /srv/build2xlsform \
 # Cleanup
 && apk --no-cache del .deps \
 && find /srv/build2xlsform -name '.git*' -exec rm -rf {} + \
 && rm -rf /root/.config /root/.npm

COPY docker/ /

EXPOSE 8080

CMD ["s6-svscan", "/etc/services.d"]
