From e86ea159ff602d1d90065617f069480009f72d15 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Sat, 9 Nov 2019 20:59:44 +0200
Subject: [PATCH] Apache improvements.

- Add status module.
- Set work dir to the user's home dir.
- Patch configuration instead of using sed.
- Test the Apache configuration during build.
---
 .dockerignore |  1 +
 Dockerfile    |  7 ++++++-
 patch.diff    | 30 ++++++++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 patch.diff

diff --git a/.dockerignore b/.dockerignore
index 616b3fa..a954727 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,2 +1,3 @@
 *
 !cgitrc
+!patch.diff
diff --git a/Dockerfile b/Dockerfile
index ca00f62..0d77049 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -5,13 +5,14 @@ RUN apt-get update && \
         apache2 \
         cgit \
         groff-base \
+        patch \
         python3-docutils \
         python3-markdown \
         python3-pygments \
     && \
     a2enmod cgid && \
     a2enconf cgit && \
-    sed -i 's/80/8080/g' /etc/apache2/ports.conf /etc/apache2/sites-enabled/000-default.conf && \
+    a2enmod status && \
     install -d -o www-data -g www-data -m 755 /var/cache/cgit && \
     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 && \
@@ -19,14 +20,18 @@ RUN apt-get update && \
     ln -sf /dev/stderr /var/log/apache2/error.log && \
     ln -sf /dev/stdout /var/log/apache2/other_vhosts_access.log && \
     rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/* /var/cache/apt/archives/*
+COPY --chown=root:root patch.diff /root/
 COPY --chown=root:root cgitrc /etc/
 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 patch --strip 0 --verbose --directory /etc/apache2 --input /root/patch.diff && \
+    apache2 -t
 EXPOSE 8080
 CMD [ "apache2", "-DFOREGROUND" ]
 VOLUME ["/srv/git"]
 USER "www-data"
+WORKDIR /var/www
 HEALTHCHECK CMD wget --spider --quiet http://localhost:8080/cgit/ --user-agent 'Healthcheck' || exit 1
diff --git a/patch.diff b/patch.diff
new file mode 100644
index 0000000..684b354
--- /dev/null
+++ b/patch.diff
@@ -0,0 +1,30 @@
+--- ports.conf	2019-11-09 19:58:29.052813201 +0200
++++ ports.conf	2019-11-02 14:40:08.000000000 +0200
+@@ -2,7 +2,7 @@
+ # have to change the VirtualHost statement in
+ # /etc/apache2/sites-enabled/000-default.conf
+ 
+-Listen 80
++Listen 8080
+ 
+ <IfModule ssl_module>
+ 	Listen 443
+--- sites-available/000-default.conf	2019-04-03 00:13:44.000000000 +0300
++++ sites-available/000-default.conf	2019-11-09 20:00:01.459226750 +0200
+@@ -1,4 +1,4 @@
+-<VirtualHost *:80>
++<VirtualHost *:8080>
+ 	# The ServerName directive sets the request scheme, hostname and port that
+ 	# the server uses to identify itself. This is used when creating
+ 	# redirection URLs. In the context of virtual hosts, the ServerName
+--- mods-available/status.conf	2019-04-03 00:13:44.000000000 +0300
++++ mods-available/status.conf	2019-11-09 19:59:09.642896703 +0200
+@@ -5,7 +5,7 @@
+ 
+ 	<Location /server-status>
+ 		SetHandler server-status
+-		Require local
++		#Require local
+ 		#Require ip 192.0.2.0/24
+ 	</Location>
+ 
-- 
GitLab