FROM docker.internal.justin.tv/devtools/runtime/xenial/base

RUN mkdir /root/.postgresql && wget -O /root/.postgresql/root.crt https://s3.amazonaws.com/redshift-downloads/redshift-ca-bundle.crt

COPY Gemfile Gemfile.lock /opt/twitch/viewcounts-ace-alerts/
WORKDIR /opt/twitch/viewcounts-ace-alerts

RUN apt-get update && apt-get install -y --no-install-recommends \
		ruby2.3=2.3.1-2~16.04.2 \
		ruby2.3-dev=2.3.1-2~16.04.2 \
		ruby-pg=0.18.4-1 \
		libpq-dev \
		build-essential \
	&& gem install bundle && bundle install \
	&& apt-get remove -y libpq-dev build-essential ruby2.3-dev \
	&& apt-get autoremove -y \
	&& rm -rf /var/lib/apt/lists/*

COPY *.rb /opt/twitch/viewcounts-ace-alerts/
COPY queries/*.sql /opt/twitch/viewcounts-ace-alerts/queries/

CMD [ "ruby", "main.rb" ]
