From 1a227489e2c717b98397c2754d474d8098bbffec Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Tue, 21 Sep 2021 14:14:44 +0000 Subject: [PATCH] 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 --- playbooks/roles/lodgeit/files/opendev.svg | 1 + playbooks/roles/lodgeit/tasks/main.yaml | 16 ++++++++++++++++ .../lodgeit/templates/docker-compose.yaml.j2 | 2 +- playbooks/roles/lodgeit/templates/paste.vhost.j2 | 8 ++++++++ testinfra/test_paste.py | 6 ++++++ 5 files changed, 32 insertions(+), 1 deletion(-) create mode 120000 playbooks/roles/lodgeit/files/opendev.svg diff --git a/playbooks/roles/lodgeit/files/opendev.svg b/playbooks/roles/lodgeit/files/opendev.svg new file mode 120000 index 0000000000..618f33aadf --- /dev/null +++ b/playbooks/roles/lodgeit/files/opendev.svg @@ -0,0 +1 @@ +../../../../assets/opendev.svg \ No newline at end of file diff --git a/playbooks/roles/lodgeit/tasks/main.yaml b/playbooks/roles/lodgeit/tasks/main.yaml index 09339b84f3..27f3c0af6f 100644 --- a/playbooks/roles/lodgeit/tasks/main.yaml +++ b/playbooks/roles/lodgeit/tasks/main.yaml @@ -61,6 +61,22 @@ group: root 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 copy: src: robots.txt diff --git a/playbooks/roles/lodgeit/templates/docker-compose.yaml.j2 b/playbooks/roles/lodgeit/templates/docker-compose.yaml.j2 index 373f558f2f..f917ec255d 100644 --- a/playbooks/roles/lodgeit/templates/docker-compose.yaml.j2 +++ b/playbooks/roles/lodgeit/templates/docker-compose.yaml.j2 @@ -33,5 +33,5 @@ services: environment: 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_TITLE_OVERRIDE: 'Opendev Pastebin' + LODGEIT_TITLE_OVERRIDE: 'Opendev Pastebin' diff --git a/playbooks/roles/lodgeit/templates/paste.vhost.j2 b/playbooks/roles/lodgeit/templates/paste.vhost.j2 index c72a49fe38..f7b5fc82be 100644 --- a/playbooks/roles/lodgeit/templates/paste.vhost.j2 +++ b/playbooks/roles/lodgeit/templates/paste.vhost.j2 @@ -31,12 +31,16 @@ ProxyPass / http://localhost:9000/ retry=0 ProxyPassReverse / http://localhost:9000/ + + ProxyPass ! + ProxyPass ! Require all granted + Alias /assets /var/lib/lodgeit/www/assets Alias /robots.txt /var/lib/lodgeit/www/robots.txt @@ -74,12 +78,16 @@ RewriteCond %{QUERY_STRING} "method=pastes.getRecent" RewriteRule .* - [F,L] + + ProxyPass ! + ProxyPass ! Require all granted + Alias /assets /var/lib/lodgeit/www/assets Alias /robots.txt /var/lib/lodgeit/www/robots.txt diff --git a/testinfra/test_paste.py b/testinfra/test_paste.py index 014a0813df..5854a8f1be 100644 --- a/testinfra/test_paste.py +++ b/testinfra/test_paste.py @@ -45,6 +45,12 @@ def test_paste_redirects(host): r = requests.get('http://%s' % (host.backend.get_hostname())) 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): cmd = host.run('curl --insecure ' '--resolve paste.opendev.org:443:127.0.0.1 '