FROM rhscl/ruby-25-rhel7:2.5-70.1596049320

LABEL summary="Zync - the sync tool" \
      description="Zync is going to take your 3scale data \
                   and push it somewhere else, reliably. \
                   Offers only one directional sync (from 3scale to other systems)." \
      io.k8s.display-name="Zync" \
      io.k8s.description="Zync is going to take your 3scale data \
                   and push it somewhere else, reliably. \
                   Offers only one directional sync (from 3scale to other systems)." \
      io.openshift.expose-services="8080:zync" \
      io.openshift.tags="sync, api management, 3scale, rhamp"

#Labels consumed by Red Hat build service
LABEL com.redhat.component="3scale-amp-zync-container" \
      maintainer="mcichra@redhat.com" \
      name="3scale-amp2/zync-rhel7" \
    version="1.12.0"

ENV BASH_ENV=/opt/app-root/etc/scl_enable \
   ENV=/opt/app-root/etc/scl_enable \
   PROMPT_COMMAND=". /opt/app-root/etc/scl_enable" \
   RAILS_ENV=production \
   RAILS_LOG_TO_STDOUT=1 \
   BUNDLE_WITHOUT=development:test \
   TZ=:/etc/localtime \
   BUNDLE_GEMFILE=Gemfile \
   DISABLE_SPRING=1 \
   GEMS_REPO=https://origin-repository.jboss.org/nexus/content/groups/rubygems_store/

EXPOSE 8080

USER root

RUN mkdir -p tmp log; chmod -vfR g+w tmp log

WORKDIR /opt/zync

ARG BUILD_TYPE=brew

COPY $BUILD_TYPE.repo /etc/yum.repos.d/brew.repo

ADD zync-*.tar.gz /tmp

RUN curl -o /etc/pki/ca-trust/source/anchors/newca.crt https://password.corp.redhat.com/RH-IT-Root-CA.crt \
  && update-ca-trust extract

RUN cd /tmp/zync-* && cd /opt/zync \
    && cp -pR /tmp/zync-*/* . \
    && source /opt/app-root/etc/scl_enable \
    && gem install --no-document bundler:2.0.1 --source $GEMS_REPO \
    && bundle config mirror.http://rubygems.org $GEMS_REPO \
    && bundle config mirror.https://rubygems.org $GEMS_REPO \
    && bundle install --deployment --jobs $(grep -c processor /proc/cpuinfo) --retry=5 --full-index \
    && chgrp root /opt/zync/ \
    && mkdir -p /root/licenses/3scale-amp-zync \
    && cp /opt/zync/doc/licenses/licenses.xml /root/licenses/3scale-amp-zync/licenses.xml

RUN rm /etc/pki/ca-trust/source/anchors/newca.crt \
  && update-ca-trust extract

RUN source /opt/app-root/etc/scl_enable \
   && cd /opt/zync \
   && rm -f log/*.log \
   && touch /opt/zync/entrypoint.sh \
   && chmod 755 /opt/zync/entrypoint.sh \
   && echo '#!/bin/sh' >> /opt/zync/entrypoint.sh \
   && echo 'source /opt/app-root/etc/scl_enable' >> /opt/zync/entrypoint.sh \
   && echo 'bundle exec bin/rails db:setup 2> /dev/null || bundle exec bin/rails db:migrate' >> /opt/zync/entrypoint.sh \
   && echo 'exec bundle exec "$@"' >> /opt/zync/entrypoint.sh

USER 1001

ENTRYPOINT ["/opt/zync/entrypoint.sh"]

CMD ["bin/rails", "server", "--binding", "0.0.0.0", "--port", "8080"]
