So there was this one question on Stackoverflow in which the OP was linking an .htaccess
tester for Mod-Rewrite-Rules. Despite this being all fine I was asking myself what about really(tm) testing this?
So I remembered the rewrite-log from the days ago and thought: Why not just fire up a docker container, do the setup for testing rewrites by turning the logs to screaming and give it a drive.
But all the setup.
So I had an idea: What about you put the whole example into the Dockerfile
? It has the RUN
directive, so the moment the image builds it is actually executing it.
Having it exit non-zero even prevents of storing the image locally.
Ah yeah, and why actually write a Dockerfile
even.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<<'EOD' docker build –rm –tag rewrite-tester –no-cache – | |
FROM httpd:alpine | |
RUN set -e \ | |
; sed -i -e 's/^#LoadModule rewrite_module/LoadModule rewrite_module/' \ | |
-e 's/^LogLevel .*$/LogLevel debug rewrite:trace8/' \ | |
-e '\|<Directory "/usr/local/apache2/htdocs">|,\ </Directory> s/^ AllowOverride .*$/ AllowOverride All/' \ | |
/usr/local/apache2/conf/httpd.conf \ | |
; echo -e ' \n\ | |
RewriteEngine On \n\ | |
RewriteBase / \n\ | |
RewriteCond %{REQUEST_URI} \.(gif|jpg|jpeg|png)$ \n\ | |
RewriteRule ^(.*)$ $1?i=jplx [DPI,QSA] \n\ | |
RewriteCond %{REQUEST_URI} !^/sites/default/files/js/ \n\ | |
RewriteCond %{REQUEST_URI} !^/sites/default/files/css/ \n\ | |
RewriteRule ^sites/default/files/(.*)$ index.php?q=system/files/$1 [END,QSA,R] \n\ | |
' | tee /usr/local/apache2/htdocs/.htaccess \ | |
; httpd-foreground & sleep 1 \ | |
; apk add curl \ | |
; curl -I 'http://127.0.0.1/sites/default/files/Slide074.png?abc' \ | |
; exit 123 | |
EOD | |
;: https://stackoverflow.com/a/58527089/367456 |
This also clearly highlights a missing feature in docker: no support for here-doc strings in the Dockerfile
since 2013, echo -e
to the rescue (but it’s cumbersome).