FROM ubuntu:16.04

ENV appDir /opt/twitch/jax/current
RUN mkdir -p $appDir
COPY ./.manta/ $appDir
RUN groupadd -r web && useradd --no-log-init -r -g web web
RUN chown -R web:web $appDir

RUN apt-get update

RUN echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections
RUN echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections

RUN apt-get install -y software-properties-common python-software-properties wget apt-transport-https curl supervisor vim

RUN add-apt-repository ppa:webupd8team/java

RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
RUN echo 'deb https://artifacts.elastic.co/packages/5.x/apt stable main' | tee -a /etc/apt/sources.list.d/elastic-5.x.list
RUN apt-get update && apt-get install -y elasticsearch=5.5.1  oracle-java8-installer

COPY api/logging.yml /usr/share/elasticsearch/config/
COPY api/elasticsearch.yml /usr/share/elasticsearch/config/
COPY api/log4j2.properties /usr/share/elasticsearch/config/
RUN chown -R web:elasticsearch /usr/share/elasticsearch/

COPY api/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN mkdir -p /var/log/supervisor
RUN chown -R web:elasticsearch /var/log/supervisor/
RUN chown -R web:elasticsearch /etc/supervisor/conf.d/

RUN usermod -a -G elasticsearch web

USER root
ENV PATH=$PATH:/usr/share/elasticsearch/bin
EXPOSE 9200 9300 6062
ENTRYPOINT ["/usr/bin/supervisord"]
