From 20584f79534b1d6efa45d5714b0b79cc7538d4b2 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Sat, 6 Nov 2021 13:35:12 +0200 Subject: [PATCH] Refactor the httpd images a bit. - Use the environment variables (like APACHE_RUN_USER or APACHE_LOG_DIR) during the build, so now they're set earlier. - Add the APACHE_LOCK_DIR. --- httpd/bullseye/Dockerfile | 22 ++++++++++++---------- httpd/buster/Dockerfile | 22 ++++++++++++---------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/httpd/bullseye/Dockerfile b/httpd/bullseye/Dockerfile index 7fc3077..cf65f77 100644 --- a/httpd/bullseye/Dockerfile +++ b/httpd/bullseye/Dockerfile @@ -1,4 +1,10 @@ FROM registry.hub.docker.com/library/debian:bullseye-slim +ENV APACHE_RUN_DIR=/run/apache2 \ + APACHE_LOCK_DIR=/var/lock/apache2 \ + APACHE_LOG_DIR=/var/log/apache2 \ + APACHE_RUN_USER=www-data \ + APACHE_RUN_GROUP=www-data \ + APACHE_PID_FILE=/run/apache2/apache2.pid # hadolint ignore=DL3008,DL3015 RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y \ @@ -9,17 +15,13 @@ RUN apt-get update && \ setcap CAP_NET_BIND_SERVICE=+ep /usr/sbin/apache2 && \ DEBIAN_FRONTEND=noninteractive apt-get purge --auto-remove -y libcap2-bin && \ a2enmod status && \ - install -d -o www-data -g www-data -m 755 /run/apache2 && \ - install -d -o www-data -g www-data -m 755 /var/log/apache2 && \ - ln -sf /dev/stdout /var/log/apache2/access.log && \ - ln -sf /dev/stderr /var/log/apache2/error.log && \ - ln -sf /dev/stdout /var/log/apache2/other_vhosts_access.log && \ + install -d -o "$APACHE_RUN_USER" -g "$APACHE_RUN_GROUP" -m 755 "$APACHE_RUN_DIR" && \ + install -d -o "$APACHE_RUN_USER" -g "$APACHE_RUN_GROUP" -m 755 "$APACHE_LOCK_DIR" && \ + install -d -o "$APACHE_RUN_USER" -g "$APACHE_RUN_GROUP" -m 755 "$APACHE_LOG_DIR" && \ + ln -sf /dev/stdout "$APACHE_LOG_DIR/access.log" && \ + ln -sf /dev/stderr "$APACHE_LOG_DIR/error.log" && \ + ln -sf /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log" && \ rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/* /var/cache/apt/archives/* -ENV APACHE_RUN_DIR=/run/apache2 \ - APACHE_LOG_DIR=/var/log/apache2 \ - APACHE_RUN_USER=www-data \ - APACHE_RUN_GROUP=www-data \ - APACHE_PID_FILE=/run/apache2/apache2.pid RUN apache2 -t EXPOSE 80 CMD [ "apache2", "-DFOREGROUND" ] diff --git a/httpd/buster/Dockerfile b/httpd/buster/Dockerfile index 88d945c..d9db471 100644 --- a/httpd/buster/Dockerfile +++ b/httpd/buster/Dockerfile @@ -1,4 +1,10 @@ FROM registry.hub.docker.com/library/debian:buster-slim +ENV APACHE_RUN_DIR=/run/apache2 \ + APACHE_LOCK_DIR=/var/lock/apache2 \ + APACHE_LOG_DIR=/var/log/apache2 \ + APACHE_RUN_USER=www-data \ + APACHE_RUN_GROUP=www-data \ + APACHE_PID_FILE=/run/apache2/apache2.pid # hadolint ignore=DL3008,DL3015 RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y \ @@ -9,17 +15,13 @@ RUN apt-get update && \ setcap CAP_NET_BIND_SERVICE=+ep /usr/sbin/apache2 && \ DEBIAN_FRONTEND=noninteractive apt-get purge --auto-remove -y libcap2-bin && \ a2enmod status && \ - install -d -o www-data -g www-data -m 755 /run/apache2 && \ - install -d -o www-data -g www-data -m 755 /var/log/apache2 && \ - ln -sf /dev/stdout /var/log/apache2/access.log && \ - ln -sf /dev/stderr /var/log/apache2/error.log && \ - ln -sf /dev/stdout /var/log/apache2/other_vhosts_access.log && \ + install -d -o "$APACHE_RUN_USER" -g "$APACHE_RUN_GROUP" -m 755 "$APACHE_RUN_DIR" && \ + install -d -o "$APACHE_RUN_USER" -g "$APACHE_RUN_GROUP" -m 755 "$APACHE_LOCK_DIR" && \ + install -d -o "$APACHE_RUN_USER" -g "$APACHE_RUN_GROUP" -m 755 "$APACHE_LOG_DIR" && \ + ln -sf /dev/stdout "$APACHE_LOG_DIR/access.log" && \ + ln -sf /dev/stderr "$APACHE_LOG_DIR/error.log" && \ + ln -sf /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log" && \ rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/* /var/cache/apt/archives/* -ENV APACHE_RUN_DIR=/run/apache2 \ - APACHE_LOG_DIR=/var/log/apache2 \ - APACHE_RUN_USER=www-data \ - APACHE_RUN_GROUP=www-data \ - APACHE_PID_FILE=/run/apache2/apache2.pid RUN apache2 -t EXPOSE 80 CMD [ "apache2", "-DFOREGROUND" ] -- GitLab