This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/attic-docker.git
The following commit(s) were added to refs/heads/main by this push:
new cd7f59b Docker test harness - initial
cd7f59b is described below
commit cd7f59b38f6ccfb3cfcb13b1b93a18d08659e59f
Author: Sebb <[email protected]>
AuthorDate: Sun Jan 12 14:59:25 2025 +0000
Docker test harness - initial
---
.dockerignore | 5 +++
Dockerfile | 29 +++++++++++++++++
README.md | 23 ++++++++++++-
compose.yaml | 9 ++++++
config/000-default.conf | 29 +++++++++++++++++
config/attic_filter.lua | 85 +++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 179 insertions(+), 1 deletion(-)
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..78af629
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,5 @@
+# Ignore everything initially
+**
+
+# Allow what we want
+!config/**
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..0bdff57
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,29 @@
+FROM ubuntu:20.04
+
+ENV GEM_HOME="/srv/gems" \
+ LANG=C.UTF-8 \
+ LC_ALL=C.UTF-8
+
+RUN apt-get update && \
+ DEBIAN_FRONTEND='noninteractive' apt-get install -y \
+ apache2
+RUN echo "ServerName apache-lua.local" >
/etc/apache2/conf-enabled/servername.conf
+
+RUN DEBIAN_FRONTEND='noninteractive' apt-get install -y \
+ lua5.2 \
+ lua5.2-sec \
+ lua-socket \
+ lua-posix
+
+RUN a2enmod cgi && \
+ a2enmod lua && \
+ a2enmod headers
+
+COPY config/000-default.conf /etc/apache2/sites-enabled/000-default.conf
+COPY config/attic_filter.lua /etc/apache2/conf-enabled/attic_filter.lua
+
+EXPOSE 80
+
+WORKDIR /var/www
+
+CMD ["apache2ctl", "-DFOREGROUND"]
\ No newline at end of file
diff --git a/README.md b/README.md
index ec00e18..f3c9101 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,22 @@
-Docker build for testing Attic banner etc.
\ No newline at end of file
+Docker build for testing Attic banner etc.
+
+Build:
+docker compose build
+
+Checkout the Attic site, e.g.
+git clone ... /path/to/website
+
+To enable/disable the Attic banner, create/delete the directory:
+/path/to/website/_ATTIC
+
+To enable/disable Content-Security-Policy, create/delete the directory:
+/path/to/website/_CSP
+
+Start:
+VAR_HTML=/path/to/website docker compose up
+
+browse to localhost:8000
+
+To ena
+Start shell (container must be running)
+docker compose exec attic_lua_csp /bin/bash
diff --git a/compose.yaml b/compose.yaml
new file mode 100644
index 0000000..71f4078
--- /dev/null
+++ b/compose.yaml
@@ -0,0 +1,9 @@
+services:
+ attic_lua_csp:
+ image: attic_lua_csp
+ build: .
+ ports:
+ - "8000:80"
+ volumes:
+ - ${VAR_HTML:-./www}:/var/www
+ - ${VAR_LOG:-./log}:/var/log/apache2
diff --git a/config/000-default.conf b/config/000-default.conf
new file mode 100644
index 0000000..b613a18
--- /dev/null
+++ b/config/000-default.conf
@@ -0,0 +1,29 @@
+<VirtualHost *:80>
+
+ ServerAdmin webmaster@localhost
+ ServerName attic_lua
+ DocumentRoot /var/www
+
+ LuaScope thread
+ LuaCodeCache stat
+
+ <If "-d '/var/www/_CSP'">
+ Header set Content-Security-Policy "default-src 'self' data:
'unsafe-inline' https://www.apachecon.com/ https://www.communityovercode.org/
https://analytics.apache.org/; script-src 'self' 'unsafe-inline' 'unsafe-eval'
https://analytics.apache.org/; style-src 'self' 'unsafe-inline';
frame-ancestors 'none'; img-src 'self' https://www.apache.org/;"
+ </If>
+
+ # Filter website to add Attic header if marker directory is present
+ LuaOutputFilter attic "/etc/apache2/conf-enabled/attic_filter.lua"
output_filter
+ <If "-d '/var/www/_ATTIC'">
+ AddOutputFilter attic html
+ </If>
+
+ # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
+ # error, crit, alert, emerg.
+ # It is also possible to configure the loglevel for particular
+ # modules, e.g.
+ #LogLevel info ssl:warn
+
+ ErrorLog /var/log/apache2/error.log
+ CustomLog /var/log/apache2/access.log combined
+
+</VirtualHost>
diff --git a/config/attic_filter.lua b/config/attic_filter.lua
new file mode 100644
index 0000000..70f2a8f
--- /dev/null
+++ b/config/attic_filter.lua
@@ -0,0 +1,85 @@
+--[[
+ This is an output filter for HTML files
+ It adds a banner for projects that are flagged as in the attic.
+
+ It is invoked by the tlp vhosts if the following directory exists:
+ /var/www/attic.apache.org/flagged/%{HTTP_HOST}
+
+ See the tlp vhost definitions in
https://github.com/apache/infrastructure-p6/blob/production/data/roles/tlpserver.yaml
+
+ The mod_lua API is described here:
+ https://httpd.apache.org/docs/current/mod/mod_lua.html#modifying_buckets
+
+ How it works:
+ For simplicity, we add the banner to the start of the page.
+
+ This is not really valid HTML, but seems to work in most cases, and avoids
having to find a better
+ place to insert it. It does not work for some hosts, especially those that
have a static menu bar
+ with scrolling content. In such cases, the code looks for a specific tag
(which should only occur once
+ in any of the site pages, otherwise two banners may be added) and adds the
banner either before or after it.
+
+ The best location for this is found by trial and error:
+ - download a copy of a page
+ - move the banner from the start of the page (where it is added by
default) and try it in various
+ other parts of the page.
+ - try the same in some other pages that have a different layout.
+ - repeat until a suitable location is found and find a tag or other string
that uniquely identifies it
+ - add the host-specific processing to the filter along the lines of the
existing host exceptions
+
+ Note: This filter was introduced in April 2018, so not all projects in the
Attic use this filter.
+ Previously the project websites themselves were changed.
+]]--
+
+function output_filter(r)
+ -- We only filter text/html types
+ if not r.content_type:match("text/html") then return end
+
+ -- get TLP part of hostname
+ local host = r.hostname:match("^([^.]+)")
+
+ -- create the customised banner
+ local divstyle =
'font-size:x-large;padding:15px;color:white;background:red;z-index:99;' ;
+ local astyle = 'color:white;text-decoration:underline' ;
+ local div = ([[
+ <div style='%s'>
+ This project has retired. For details please refer to its
+ <a style='%s' href="https://attic.apache.org/projects/%s.html">
+ Attic page</a>.
+ </div>]]):format(divstyle, astyle, host)
+
+ -- add header:
+ -- special processing needed for some hosts
+ if host == 'predictionio' or host == 'eagle' or host == 'metamodel' or
host == 'mxnet'
+ then
+ coroutine.yield('')
+ else
+ coroutine.yield(div)
+ end
+
+ -- spit out the actual page
+ while bucket ~= nil do
+ -- special processing needed for hosts as above
+ if host == 'predictionio'
+ then
+ local output = bucket:gsub('<header>', '<header>'..div, 1)
+ coroutine.yield(output)
+ elseif host == 'mxnet'
+ then
+ local output = bucket:gsub('</header>', div..'</header>', 1)
+ coroutine.yield(output)
+ elseif host == 'eagle'
+ then
+ local output = bucket:gsub('</nav>', '</nav>'..div, 1)
+ coroutine.yield(output)
+ elseif host == 'metamodel'
+ then
+ local output = bucket:gsub('</nav>', div..'</nav>', 1)
+ coroutine.yield(output)
+ else
+ coroutine.yield(bucket)
+ end
+ end
+
+ -- no need to add anything at the end of the content
+
+end