[Bps-public-commit] docker-rt-debian-stretch branch, apache_integration, created. 448177cfbf17e05297d2648ea6e64feda7affe3b

Aaron Trevena ast at bestpractical.com
Thu Jun 11 08:24:31 EDT 2020


The branch, apache_integration has been created
        at  448177cfbf17e05297d2648ea6e64feda7affe3b (commit)

- Log -----------------------------------------------------------------
commit 448177cfbf17e05297d2648ea6e64feda7affe3b
Author: Aaron Trevena <aaron at aarontrevena.co.uk>
Date:   Thu Jun 11 13:15:08 2020 +0100

    RT running in docker with apache/fcgi and hostname configured
    
    Added scripts to patch simple RT config, and start apache in foreground
    Added documentation on building and running

diff --git a/Dockerfile b/Dockerfile
index 07076fe..01cff17 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -3,12 +3,15 @@ FROM bpssysadmin/rt-base-debian-stretch
 LABEL maintainer="Best Practical Solutions <contact at bestpractical.com>"
 
 # Valid values are RT branches like 5.0-trunk or version tags like rt-4.4.4
-ENV RT_VERSION 5.0-trunk
+
+ARG BUILD_RT_VERSION=5.0-trunk
+ENV RT_VERSION=$BUILD_RT_VERSION
 ENV RT_TEST_DEVEL 1
 ENV RT_DBA_USER root
 ENV RT_DBA_PASSWORD password
 ENV RT_TEST_DB_HOST=172.17.0.2
 ENV RT_TEST_RT_HOST=172.17.0.3
+ENV RTHOME=/opt/rt5
 
 RUN cd /usr/local/src \
   && git clone https://github.com/bestpractical/rt.git \
@@ -20,19 +23,20 @@ RUN cd /usr/local/src \
   && make initdb \
   && rm -rf /usr/local/src/*
 
-#COPY apache.rt.conf /etc/apache2/sites-available/rt.conf
-#RUN a2dissite 000-default.conf && a2ensite rt.conf
-
-#RUN chown -R www-data:www-data /opt/rt4/var/
-
-#COPY RT_SiteConfig.pm /opt/rt4/etc/RT_SiteConfig.pm
+COPY src/apache.rt.conf /etc/apache2/sites-available/rt.conf
+RUN a2dissite 000-default.conf && a2ensite rt.conf
 
-#VOLUME /opt/rt4
+RUN chown -R www-data:www-data /opt/rt5/var/
 
-#COPY docker-entrypoint.sh /usr/local/bin/
+COPY src/RT_SiteConfig.pm /opt/rt5/etc/RT_SiteConfig.pm
+COPY scripts/apache2-foreground /opt/rt5/bin/apache2-foreground
+COPY scripts/patch_siteconfig /opt/rt5/bin/patch_siteconfig
+COPY scripts/entrypoint.sh /opt/rt5/bin/entrypoint.sh
+RUN chmod +x /opt/rt5/bin/apache2-foreground
+RUN chmod +x /opt/rt5/bin/patch_siteconfig
+RUN chmod +x /opt/rt5/bin/entrypoint.sh
 
-#ENTRYPOINT ["docker-entrypoint.sh"]
+EXPOSE 80
 
-#CMD ["apache2-foreground"]
+ENTRYPOINT ["/opt/rt5/bin/entrypoint.sh"]
 
-CMD tail -f /dev/null
diff --git a/README b/README
index 734c4d4..e902f8b 100644
--- a/README
+++ b/README
@@ -6,3 +6,17 @@ other deployments of RT with docker. Since it is used for testing, it
 includes development dependencies that are not needed for production RT deployments.
 
 Thanks to Christian Loos (GitHub:@cloos) for publishing RT docker examples.
+
+To build the image:
+
+docker build -t rt5-stretch .
+
+To run the application in docker :
+
+docker run --name rt5 --link mariadb:db --hostname rt5docker.local -p 5800:80 rt5-stretch
+
+The dockerfile exposes port 80 by default, you can change the mapped port as required.
+The docker image uses the hostname provided to set the RT configuration, so that you can add
+ it to /etc/hosts on the host machine and proxy it, allowing you to access it as http://rt5docker.local/
+ or other specified hostname directly in the browser
+
diff --git a/scripts/apache2-foreground b/scripts/apache2-foreground
new file mode 100644
index 0000000..5fe22e2
--- /dev/null
+++ b/scripts/apache2-foreground
@@ -0,0 +1,40 @@
+#!/bin/bash
+set -e
+
+# Note: we don't just use "apache2ctl" here because it itself is just a shell-script wrapper around apache2 which provides extra functionality like "apache2ctl start" for launching apache2 in the background.
+# (also, when run as "apache2ctl <apache args>", it does not use "exec", which leaves an undesirable resident shell process)
+
+: "${APACHE_CONFDIR:=/etc/apache2}"
+: "${APACHE_ENVVARS:=$APACHE_CONFDIR/envvars}"
+if test -f "$APACHE_ENVVARS"; then
+	. "$APACHE_ENVVARS"
+fi
+
+# Apache gets grumpy about PID files pre-existing
+: "${APACHE_RUN_DIR:=/var/run/apache2}"
+: "${APACHE_PID_FILE:=$APACHE_RUN_DIR/apache2.pid}"
+rm -f "$APACHE_PID_FILE"
+
+# create missing directories
+# (especially APACHE_RUN_DIR, APACHE_LOCK_DIR, and APACHE_LOG_DIR)
+for e in "${!APACHE_@}"; do
+	if [[ "$e" == *_DIR ]] && [[ "${!e}" == /* ]]; then
+		# handle "/var/lock" being a symlink to "/run/lock", but "/run/lock" not existing beforehand, so "/var/lock/something" fails to mkdir
+		#   mkdir: cannot create directory '/var/lock': File exists
+		dir="${!e}"
+		while [ "$dir" != "$(dirname "$dir")" ]; do
+			dir="$(dirname "$dir")"
+			if [ -d "$dir" ]; then
+				break
+			fi
+			absDir="$(readlink -f "$dir" 2>/dev/null || :)"
+			if [ -n "$absDir" ]; then
+				mkdir -p "$absDir"
+			fi
+		done
+
+		mkdir -p "${!e}"
+	fi
+done
+
+exec apache2 -DFOREGROUND "$@"
diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh
new file mode 100644
index 0000000..fc8b4f6
--- /dev/null
+++ b/scripts/entrypoint.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+/opt/rt5/bin/patch_siteconfig
+
+/opt/rt5/bin/apache2-foreground
diff --git a/scripts/patch_siteconfig b/scripts/patch_siteconfig
new file mode 100644
index 0000000..81711f8
--- /dev/null
+++ b/scripts/patch_siteconfig
@@ -0,0 +1,23 @@
+#!/usr/bin/perl
+
+my $hostname = `hostname`;
+chomp($hostname);
+
+warn "hostname : $hostname";
+
+my $new_conf_file = @ARGV[0] || '/opt/rt5/etc/RT_SiteConfig.pm';
+
+my $config = join("\n",
+                  sprintf('Set( $rtname, "%s");', $hostname),
+                  sprintf('Set($Organization, "%s");', $hostname),
+                  sprintf('Set($WebDomain, "%s");', $hostname),
+                  "1;\n");
+
+open (my $OUTFH, '>>', $new_conf_file) or die "couldn't open $new_conf_file : $!";
+print $OUTFH $config;
+close $OUTFH;
+
+
+
+
+
diff --git a/src/RT_SiteConfig.pm b/src/RT_SiteConfig.pm
new file mode 100644
index 0000000..d5bcaa1
--- /dev/null
+++ b/src/RT_SiteConfig.pm
@@ -0,0 +1,36 @@
+use utf8;
+
+# Any configuration directives you include  here will override
+# RT's default configuration file, RT_Config.pm
+#
+# To include a directive here, just copy the equivalent statement
+# from RT_Config.pm and change the value. We've included a single
+# sample value below.
+#
+# If this file includes non-ASCII characters, it must be encoded in
+# UTF-8.
+#
+# This file is actually a perl module, so you can include valid
+# perl code, as well.
+#
+# The converse is also true, if this file isn't valid perl, you're
+# going to run into trouble. To check your SiteConfig file, use
+# this command:
+#
+#   perl -c /path/to/your/etc/RT_SiteConfig.pm
+#
+# You must restart your webserver after making changes to this file.
+#
+
+# You may also split settings into separate files under the etc/RT_SiteConfig.d/
+# directory.  All files ending in ".pm" will be parsed, in alphabetical order,
+# after this file is loaded.
+
+Set( $rtname, 'Test in Docker');
+
+# You must install Plugins on your own, this is only an example
+# of the correct syntax to use when activating them:
+#     Plugin( "RT::Authen::ExternalAuth" );
+
+1;
+
diff --git a/src/apache.rt.conf b/src/apache.rt.conf
new file mode 100644
index 0000000..1494806
--- /dev/null
+++ b/src/apache.rt.conf
@@ -0,0 +1,19 @@
+<VirtualHost *:80>
+    ### Optional apache logs for RT
+    # ErrorLog /opt/rt5/var/log/apache2.error
+    # TransferLog /opt/rt5/var/log/apache2.access
+    # LogLevel debug
+
+    SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
+    AddDefaultCharset UTF-8
+
+    ScriptAlias / /opt/rt5/sbin/rt-server.fcgi/
+
+    DocumentRoot "/opt/rt5/share/html"
+    <Location />
+        Require all granted
+        Options +ExecCGI
+        AddHandler fcgid-script fcgi
+    </Location>
+</VirtualHost>
+

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list