From 5ed05a59466f87c94afdd1c5746e549b2bc4a82a Mon Sep 17 00:00:00 2001 From: Wilton Rodrigues Date: Sat, 30 Oct 2021 11:16:18 -0300 Subject: [PATCH 1/5] Changing how container starts - Using best practices from https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#entrypoint - This way, the apache proccess will be PID 1 - It can simply start Apache2 - Or run Apache2 and pass parameters to the Server --- 2.9/Dockerfile | 4 +++- 2.9/scripts/docker-entrypoint.sh | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/2.9/Dockerfile b/2.9/Dockerfile index 728a001..f0585c7 100644 --- a/2.9/Dockerfile +++ b/2.9/Dockerfile @@ -71,7 +71,7 @@ RUN wget https://github.com/OCSInventory-NG/OCSInventory-ocsreports/releases/dow WORKDIR /tmp/OCSNG_UNIX_SERVER-${OCS_VERSION} RUN cd Apache/ && \ - perl Makefile.PL && \ + perl Makefile.PL && \ make && \ make install ; @@ -82,4 +82,6 @@ COPY ./scripts/docker-entrypoint.sh /usr/bin/docker-entrypoint.sh EXPOSE 80 443 +# https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#entrypoint ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"] +CMD ["/usr/sbin/httpd", "-DFOREGROUND"] diff --git a/2.9/scripts/docker-entrypoint.sh b/2.9/scripts/docker-entrypoint.sh index 5b69441..2b3f977 100755 --- a/2.9/scripts/docker-entrypoint.sh +++ b/2.9/scripts/docker-entrypoint.sh @@ -22,7 +22,7 @@ if [ ! -f $OCS_WEBCONSOLE_DIR/ocsreports/var.php ]; then cp -r /tmp/OCSNG_UNIX_SERVER-2.9/ocsreports/ ${OCS_WEBCONSOLE_DIR} rm -rf ${OCS_WEBCONSOLE_DIR}/ocsreports/dbconfig.inc.php fi; - + if [ ! -z ${OCS_DISABLE_COM_MODE+x} ]; then echo echo "+---------------------------------------------------------------------------+" @@ -43,7 +43,7 @@ if [ ! -z ${OCS_DISABLE_WEB_MODE+x} ]; then echo fi -# Configure z-ocsinventory-server file +# Configure z-ocsinventory-server file if [ ! -f /etc/httpd/conf.d/z-ocsinventory-server.conf ] && [ -z ${OCS_DISABLE_COM_MODE+x} ]; then cp /tmp/conf/ocsinventory-server.conf /etc/httpd/conf.d/z-ocsinventory-server.conf sed -i 's/VERSION_MP/2/g' /etc/httpd/conf.d/z-ocsinventory-server.conf @@ -74,7 +74,7 @@ if [ -f ${SRV_CONF_FILE} ] && [ -z ${OCS_DISABLE_COM_MODE+x} ]; then done fi -# Configure ocsinventory-reports file +# Configure ocsinventory-reports file if [ ! -f /etc/httpd/conf.d/ocsinventory-reports.conf ] && [ -z ${OCS_DISABLE_WEB_MODE+x} ]; then cp /tmp/conf/ocsinventory-reports.conf /etc/httpd/conf.d/ocsinventory-reports.conf sed -i 's/OCSREPORTS_ALIAS/\/ocsreports/g' /etc/httpd/conf.d/ocsinventory-reports.conf @@ -137,4 +137,4 @@ echo "| Starting OCS Inventory NG Management Docker... |" echo "+----------------------------------------------------------+" echo -/usr/sbin/httpd -DFOREGROUND +exec "$@" \ No newline at end of file From a1c948f57f6101dc7ae72d6264babbad288976a5 Mon Sep 17 00:00:00 2001 From: Wilton Rodrigues Date: Sat, 30 Oct 2021 11:23:24 -0300 Subject: [PATCH 2/5] Improving the Dockerfile - Configure Apache2 to output Logs to stdout and stderr - Based on https://github.com/docker-library/httpd/blob/5f92ab18146f41d1d324e99c5e197bdeda65d063/2.4/Dockerfile#L202 - Remove unecessary layers to WORKDIR and using directory params --- 2.9/Dockerfile | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/2.9/Dockerfile b/2.9/Dockerfile index f0585c7..d8f4ca4 100644 --- a/2.9/Dockerfile +++ b/2.9/Dockerfile @@ -18,8 +18,6 @@ ENV APACHE_RUN_USER=apache APACHE_RUN_GROUP=apache \ VOLUME /var/lib/ocsinventory-reports /etc/ocsinventory-server /usr/share/ocsinventory-reports/ocsreports/extensions -WORKDIR /tmp - RUN yum ${YUM_FLAGS} install wget \ curl \ yum-utils \ @@ -65,17 +63,23 @@ RUN yum ${YUM_FLAGS} install wget \ php73-php-zip \ php73-php-opcache ; -RUN wget https://github.com/OCSInventory-NG/OCSInventory-ocsreports/releases/download/${OCS_VERSION}/OCSNG_UNIX_SERVER-${OCS_VERSION}.tar.gz && \ - tar xzf OCSNG_UNIX_SERVER-${OCS_VERSION}.tar.gz ; +RUN wget https://github.com/OCSInventory-NG/OCSInventory-ocsreports/releases/download/${OCS_VERSION}/OCSNG_UNIX_SERVER-${OCS_VERSION}.tar.gz -P /tmp && \ + tar xzf /tmp/OCSNG_UNIX_SERVER-${OCS_VERSION}.tar.gz -C /tmp; -WORKDIR /tmp/OCSNG_UNIX_SERVER-${OCS_VERSION} - -RUN cd Apache/ && \ +RUN cd /tmp/OCSNG_UNIX_SERVER-${OCS_VERSION}/Apache/ && \ perl Makefile.PL && \ make && \ make install ; -WORKDIR /tmp +WORKDIR /etc/httpd/conf.d + +# Redirect Apache2 Logs to stdout e stderr +# https://github.com/docker-library/httpd/blob/5f92ab18146f41d1d324e99c5e197bdeda65d063/2.4/Dockerfile#L202 +RUN sed -ri \ + -e 's!^(\s*CustomLog)\s+\S+!\1 /proc/self/fd/1!g' \ + -e 's!^(\s*ErrorLog)\s+\S+!\1 /proc/self/fd/2!g' \ + -e 's!^(\s*TransferLog)\s+\S+!\1 /proc/self/fd/1!g' \ + "/etc/httpd/conf/httpd.conf" COPY conf/ /tmp/conf COPY ./scripts/docker-entrypoint.sh /usr/bin/docker-entrypoint.sh From 769e4cc2fb8059e52a21236c6925db5c28004ed4 Mon Sep 17 00:00:00 2001 From: Wilton Rodrigues Date: Sat, 30 Oct 2021 11:48:09 -0300 Subject: [PATCH 3/5] Changing perl SOAP module - This prevents the error 'Can't load SOAP::Transport::HTTP* - Web service will be unavailable' --- 2.9/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.9/Dockerfile b/2.9/Dockerfile index d8f4ca4..621725f 100644 --- a/2.9/Dockerfile +++ b/2.9/Dockerfile @@ -34,7 +34,7 @@ RUN yum ${YUM_FLAGS} install wget \ perl-Compress-Zlib \ perl-DBI perl-DBD-MySQL \ perl-Net-IP \ - perl-SOAP-Lite \ + perl-Apache2-SOAP \ perl-Archive-Zip \ perl-Mojolicious \ perl-Plack \ From d6a2d58b3c69c7c95607e007592a4fcabd717a13 Mon Sep 17 00:00:00 2001 From: Wilton Rodrigues Date: Sat, 30 Oct 2021 11:58:02 -0300 Subject: [PATCH 4/5] Adding IPDISCOVER_LINK_TAG_NETWORK missing config - This prevents the warning 'Bad setting. `IPDISCOVER_LINK_TAG_NETWORK` is not set.' on logs --- 2.9/conf/ocsinventory-server.conf | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/2.9/conf/ocsinventory-server.conf b/2.9/conf/ocsinventory-server.conf index d4e461f..42aae79 100644 --- a/2.9/conf/ocsinventory-server.conf +++ b/2.9/conf/ocsinventory-server.conf @@ -186,6 +186,8 @@ PerlSetEnv OCS_OPT_IPDISCOVER_NO_POSTPONE 0 # Enable groups for ipdiscover (for example, you might want to prevent some groups to be ipdiscover agents) PerlSetEnv OCS_OPT_IPDISCOVER_USE_GROUPS 1 + # Link ipdiscover network to computer TAG + PerlSetEnv OCS_OPT_IPDISCOVER_LINK_TAG_NETWORK 0 # ===== INVENTORY FILES MAPPING SETTINGS ===== @@ -378,4 +380,4 @@ require "SOAP_USER" - \ No newline at end of file + From a2140c7ab4916f27edb01553c62f128aeabda483 Mon Sep 17 00:00:00 2001 From: Wilton Rodrigues Date: Sat, 30 Oct 2021 12:28:53 -0300 Subject: [PATCH 5/5] Setting Apache Server Name - This prevents the warning 'Could not reliably determine the server's fully qualified domain name' - Config Apache Server Name with APACHE_SERVER_NAME env var or 'localhost' --- 2.9/scripts/docker-entrypoint.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/2.9/scripts/docker-entrypoint.sh b/2.9/scripts/docker-entrypoint.sh index 2b3f977..61aa52b 100755 --- a/2.9/scripts/docker-entrypoint.sh +++ b/2.9/scripts/docker-entrypoint.sh @@ -43,6 +43,13 @@ if [ ! -z ${OCS_DISABLE_WEB_MODE+x} ]; then echo fi +echo "+----------------------------------------------------------+" +echo "| Setting Apache Server Name to '${APACHE_SERVER_NAME:-localhost}'" +echo "+----------------------------------------------------------+" +echo +sed -ri -e "s!^#(ServerName)\s+\S+!\1 ${APACHE_SERVER_NAME:-localhost}:80!g" \ + "/etc/httpd/conf/httpd.conf" + # Configure z-ocsinventory-server file if [ ! -f /etc/httpd/conf.d/z-ocsinventory-server.conf ] && [ -z ${OCS_DISABLE_COM_MODE+x} ]; then cp /tmp/conf/ocsinventory-server.conf /etc/httpd/conf.d/z-ocsinventory-server.conf