From 0df2367e7a424d5a7cec66bb2475e9013c4b6aef Mon Sep 17 00:00:00 2001 From: Miguelangel Freitas Date: Fri, 20 Apr 2018 17:54:45 -0500 Subject: [PATCH] Refactoring wazuh/wazuh-nginx container --- nginx/Dockerfile | 12 +++++++-- nginx/config/entrypoint.sh | 53 ++++++++++++++++++++++++++++++++++++++ nginx/config/run.sh | 43 ------------------------------- 3 files changed, 63 insertions(+), 45 deletions(-) create mode 100644 nginx/config/entrypoint.sh delete mode 100644 nginx/config/run.sh diff --git a/nginx/Dockerfile b/nginx/Dockerfile index 71caddd4..96decefd 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -1,7 +1,15 @@ FROM nginx:latest +ENV DEBIAN_FRONTEND noninteractive + RUN apt-get update && apt-get install -y openssl apache2-utils -COPY config/run.sh /run.sh +COPY config/entrypoint.sh /entrypoint.sh -RUN chmod 755 /run.sh +RUN chmod 755 /entrypoint.sh + +RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +VOLUME ["/etc/nginx/conf.d"] + +ENTRYPOINT /entrypoint.sh diff --git a/nginx/config/entrypoint.sh b/nginx/config/entrypoint.sh new file mode 100644 index 00000000..fb1409d6 --- /dev/null +++ b/nginx/config/entrypoint.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +set -e + +# Generating certificates. +if [ ! -d /etc/nginx/conf.d/ssl ]; then + echo "Generating SSL certificates" + mkdir -p /etc/nginx/conf.d/ssl/certs /etc/nginx/conf.d/ssl/private + openssl req -x509 -batch -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/conf.d/ssl/private/kibana-access.key -out /etc/nginx/conf.d/ssl/certs/kibana-access.pem >/dev/null +else + echo "SSL certificates already present" +fi + +# Configuring default credentiales. +if [ ! -f /etc/nginx/conf.d/kibana.htpasswd ]; then + echo "Setting Nginx credentials" + echo bar|htpasswd -i -c /etc/nginx/conf.d/kibana.htpasswd foo >/dev/null +else + echo "Kibana credentials already configured" +fi + + +if [ "x${NGINX_PORT}" = "x" ]; then + NGINX_PORT=443 +fi + +if [ "x${KIBANA_HOST}" = "x" ]; then + KIBANA_HOST="kibana:5601" +fi + +echo "Configuring NGINX" +cat > /etc/nginx/conf.d/default.conf </dev/null -else - echo "SSL certificates already present" -fi - -if [ ! -f /etc/nginx/conf.d/kibana.htpasswd ]; then - echo "Setting Nginx credentials" - echo bar|htpasswd -i -c /etc/nginx/conf.d/kibana.htpasswd foo >/dev/null -else - echo "Kibana credentials already configured" -fi - -echo "Configuring NGINX" -cat > /etc/nginx/conf.d/default.conf <