FROM ubuntu:16.04

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -y dist-upgrade && DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -y install unzip

RUN DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -y install software-properties-common

RUN add-apt-repository ppa:openjdk-r/ppa && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -y install openjdk-7-jdk

RUN mkdir -p /opt/torquebox /home/torquebox/oadr

ADD deps/torquebox-dist-3.0.2-bin.tar.gz /opt/torquebox

RUN useradd --no-create-home --shell /bin/bash --home-dir /home/torquebox torquebox

COPY app /home/torquebox/oadr/app/
COPY config /home/torquebox/oadr/config/
COPY db /home/torquebox/oadr/db/
COPY lib /home/torquebox/oadr/lib/
COPY public /home/torquebox/oadr/public/
COPY spec /home/torquebox/oadr/spec/
COPY test /home/torquebox/oadr/test/
COPY vendor /home/torquebox/oadr/vendor/
COPY config.ru Gemfile Gemfile.lock Rakefile /home/torquebox/oadr/

RUN sed -i "s|https://rubygems.org|http://rubygems.org|" /home/torquebox/oadr/Gemfile

RUN chown -R torquebox:torquebox /opt/torquebox /home/torquebox && ln -s /opt/torquebox/torquebox-3.0.2 /opt/torquebox/current

USER torquebox
WORKDIR /home/torquebox/oadr

ENV TORQUEBOX_HOME=/opt/torquebox/current
ENV JBOSS_HOME=${TORQUEBOX_HOME}/jboss JRUBY_HOME=${TORQUEBOX_HOME}/jruby 
ENV PATH=${JBOSS_HOME}/bin:${JRUBY_HOME}/bin:$PATH
ENV RAILS_ENV=production

RUN bundle install
RUN rake assets:precompile

COPY docker-entrypoint.sh docker-run.sh docker-initdb.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]

CMD ["run"]
