FROM rockylinux:8.8

MAINTAINER Thibaud Amielh <tamielh@kameleoon.com>

ARG NGINX_VERSION=1.21.4

# Install libraries and nginx
RUN yum update -y && \
    yum install -y epel-release yum-utils vim
COPY nginx-centos.repo /etc/yum.repos.d/nginx.repo
RUN yum update -y && \
    yum install -y gcc-c++ openssl gmp json-c python3 python3-pip cronie nginx-${NGINX_VERSION}

# Add configuration for module
RUN cd /opt && mkdir bin && cd /bin && mkdir kameleoon
COPY nginx_conf_generator.py /opt/bin/kameleoon/
RUN cd /etc/ && mkdir kameleoon && cd nginx && mkdir logs
COPY configuration.json /etc/kameleoon
COPY nginx-${NGINX_VERSION}/ngx_kameleoon_module.so /etc/nginx/modules
COPY kameleoon-server.conf /etc/nginx/conf.d
COPY nginx.conf /etc/nginx

# Install libraries for Python script
COPY requirements.txt /tmp
RUN pip3 install virtualenv && \
    pip3 install --upgrade pip && \
    pip3 install -r /tmp/requirements.txt

# Add cron job
COPY kameleoon-cron /etc/cron.d
RUN chmod 0644 /etc/cron.d/kameleoon-cron
RUN crontab /etc/cron.d/kameleoon-cron
RUN touch /var/log/cron.log

ENTRYPOINT python3 /opt/bin/kameleoon/nginx_conf_generator.py && crond && nginx -g 'daemon off;'
