FROM openshifttools/oso-centos7-ops-base:latest

# Pause indefinitely if asked to do so.
ARG OO_PAUSE_ON_BUILD
RUN test "$OO_PAUSE_ON_BUILD" = "true" && while sleep 10; do true; done || :

EXPOSE 10050 10051

ADD zabbix.repo /etc/yum.repos.d/

# Install zabbix (and supporting tools) from zabbix repo

# By default docker recommends to install packages with tsflags=nodocs for space saving
# but in this case, we need it for this one package, because the DB schema is coming from the docs
RUN yum-install-check.sh -y --setopt=tsflags='' zabbix-server-mysql && \
    yum clean all
RUN yum-install-check.sh -y zabbix-agent zabbix-sender crontabs \
    mariadb openssh-clients openshift-tools-scripts-monitoring-zabbix-heal && \
    yum -y update && \
    yum clean all

# Lay down zabbix conf
ADD zabbix/conf/zabbix_server.conf /etc/zabbix/
ADD zabbix/conf/zabbix_agentd.conf /etc/zabbix/
ADD zabbix/conf/zabbix_agent.conf /etc/zabbix/

# DB creation
ADD zabbix/db_create/createdb.sh /root/zabbix/

# Add crontab for root
# Re-enable once we figure out how to run cron inside of openshift.
#ADD cronroot /var/spool/cron/root

# Add ansible stuff
ADD root /root

RUN mkdir -p /etc/openshift_tools

# Add zabbix alert script
ADD smtp_ses.py /usr/lib/zabbix/alertscripts/
ADD zbx2slack.py /usr/lib/zabbix/alertscripts/

# Start mysqld, zabbix, and apache
ADD start.sh /usr/local/bin/
CMD /usr/local/bin/start.sh

# Make the container work more consistently in and out of openshift
# BE CAREFUL!!! If you change these, you may bloat the image! Use 'docker history' to see the size!
RUN mkdir -p /run/zabbix
RUN chmod -R g+rwX /etc/passwd /etc/zabbix /etc/openshift_tools /var/log /run && \
    chgrp -R root /var/log /run
