Use Apache to serve a local OpenDev logo on paste

In order to avoid unnecessary browser requests to other sites,
install a copy of the OpenDev logo on the Lodgeit server and serve
it from there rather than pointing at one served from Gitea.

Change-Id: I4c3678a1de8ca4a41cd0c64aab71b2e0e25373af
This commit is contained in:
Jeremy Stanley 2021-09-21 14:14:44 +00:00
parent e8c456926c
commit 1a227489e2
5 changed files with 32 additions and 1 deletions

View File

@ -0,0 +1 @@
../../../../assets/opendev.svg

View File

@ -61,6 +61,22 @@
group: root group: root
mode: 0755 mode: 0755
- name: Create assets dir
file:
state: directory
path: /var/lib/lodgeit/www/assets
owner: root
group: root
mode: 0755
- name: Install OpenDev logo
copy:
src: opendev.svg
dest: /var/lib/lodgeit/www/assets/opendev.svg
owner: root
group: root
mode: 0644
- name: Install robots.txt - name: Install robots.txt
copy: copy:
src: robots.txt src: robots.txt

View File

@ -33,5 +33,5 @@ services:
environment: environment:
LODGEIT_DBURI: 'mysql+pymysql://{{ lodgeit_db_username }}:{{ lodgeit_db_password }}@127.0.0.1:3306/{{ lodgeit_db_dbname }}' LODGEIT_DBURI: 'mysql+pymysql://{{ lodgeit_db_username }}:{{ lodgeit_db_password }}@127.0.0.1:3306/{{ lodgeit_db_dbname }}'
LODGEIT_SECRET_KEY: '{{ lodgeit_secret_key }}' LODGEIT_SECRET_KEY: '{{ lodgeit_secret_key }}'
LODGEIT_TITLE_OVERRIDE: '<img src="https://opendev.org/opendev/system-config/raw/branch/master/assets/opendev.svg" style="width: 100px; padding-bottom:10px; margin-left:20px;" alt="Opendev Pastebin">' LODGEIT_TITLE_OVERRIDE: '<img src="/assets/opendev.svg" style="width: 100px; padding-bottom:10px; margin-left:20px;" alt="Opendev Pastebin">'

View File

@ -31,12 +31,16 @@
ProxyPass / http://localhost:9000/ retry=0 ProxyPass / http://localhost:9000/ retry=0
ProxyPassReverse / http://localhost:9000/ ProxyPassReverse / http://localhost:9000/
<Location "/assets/">
ProxyPass !
</Location>
<Location "/robots.txt"> <Location "/robots.txt">
ProxyPass ! ProxyPass !
</Location> </Location>
<Directory "/var/lib/lodgeit/www"> <Directory "/var/lib/lodgeit/www">
Require all granted Require all granted
</Directory> </Directory>
Alias /assets /var/lib/lodgeit/www/assets
Alias /robots.txt /var/lib/lodgeit/www/robots.txt Alias /robots.txt /var/lib/lodgeit/www/robots.txt
</VirtualHost> </VirtualHost>
@ -74,12 +78,16 @@
RewriteCond %{QUERY_STRING} "method=pastes.getRecent" RewriteCond %{QUERY_STRING} "method=pastes.getRecent"
RewriteRule .* - [F,L] RewriteRule .* - [F,L]
<Location "/assets/">
ProxyPass !
</Location>
<Location "/robots.txt"> <Location "/robots.txt">
ProxyPass ! ProxyPass !
</Location> </Location>
<Directory "/var/lib/lodgeit/www"> <Directory "/var/lib/lodgeit/www">
Require all granted Require all granted
</Directory> </Directory>
Alias /assets /var/lib/lodgeit/www/assets
Alias /robots.txt /var/lib/lodgeit/www/robots.txt Alias /robots.txt /var/lib/lodgeit/www/robots.txt
</VirtualHost> </VirtualHost>

View File

@ -45,6 +45,12 @@ def test_paste_redirects(host):
r = requests.get('http://%s' % (host.backend.get_hostname())) r = requests.get('http://%s' % (host.backend.get_hostname()))
assert r.status_code == 200 assert r.status_code == 200
def test_paste_logo(host):
cmd = host.run('curl --insecure '
'--resolve paste.opendev.org:443:127.0.0.1 '
'https://paste.opendev.org/assets/opendev.svg')
assert 'image/svg+xml' in cmd.stdout
def test_paste_robots(host): def test_paste_robots(host):
cmd = host.run('curl --insecure ' cmd = host.run('curl --insecure '
'--resolve paste.opendev.org:443:127.0.0.1 ' '--resolve paste.opendev.org:443:127.0.0.1 '