FROM centos:7.6.1810

LABEL maintainer="tomishinets.v@sdsys.ru"

COPY nginx.repo /etc/yum.repos.d/nginx.repo
COPY err_trap \
     generate.sh \
     renewal.sh \
     healthcheck.sh \
     /tmp/

RUN yum install -y epel-release \
    && yum install -y yum-utils python2-certbot-nginx openssl ca-certificates mailx nginx \
    && yum install -y https://centos7.iuscommunity.org/ius-release.rpm \
    && yum install -y git2u \
    && yum clean all \
    && rm -rf /var/cache/yum \
    && mkdir -p /var/www/html/.well-known \
    && mkdir -p /var/log/letsencrypt \
    && touch /var/log/letsencrypt/letsencrypt.log \
    && chmod +x /tmp/err_trap \
    && chmod +x /tmp/generate.sh \
    && chmod +x /tmp/renewal.sh \
    && chmod +x /tmp/healthcheck.sh \
    && touch /tmp/renewal \
#    && ln -sf /dev/stdout /var/log/letsencrypt/letsencrypt.log \
    && ln -sf /dev/stdout /var/log/nginx/access.log \
    && ln -sf /dev/stderr /var/log/nginx/error.log

COPY default.conf /etc/nginx/conf.d/

HEALTHCHECK --start-period=20s --interval=10s --timeout=5s --retries=2 CMD /tmp/healthcheck.sh
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]