Commit 3b758442 authored by Jérome Perrin's avatar Jérome Perrin

software/theia: generate a pseudo-random favicon

After trying to generate a random image ourselve with image magic with:

    ${imagemagick:location}/bin/convert -size 6x6 xc: +noise Random \( -clone 0 -flip \) -append \( -clone 0 -flop \) +append -scale 128x128 $${:location}

I gave up and just download an image from gravatar, but ignoring errors
if any to comply with the "instanciation should work offline" rule.
parent 48d0b1d2
......@@ -15,7 +15,7 @@
[instance]
filename = instance.cfg.in
md5sum = 202f809fd759e9a507db7c7d33caae48
md5sum = 1d495ab97a865b31ac7f2287cb76aed0
[yarn.lock]
filename = yarn.lock
......
......@@ -53,7 +53,7 @@ template = inline:
root $${directory:frontend-static}
browse
proxy / $${theia-instance:base-url} {
except public
except public $${favicon.ico:filename}
}
proxy /services $${theia-instance:base-url} {
websocket
......@@ -91,6 +91,29 @@ hash-files =
$${frontend-instance:wrapper-path}
wait-for-files = $${frontend-instance:pidfile}
[favicon.ico]
# generate a pseudo random favicon, different for each instance name.
recipe = slapos.recipe.build
install =
import hashlib, shutil
buildout_offline = self.buildout['buildout']['offline']
self.buildout['buildout']['offline'] = 'false'
try:
gravatar_url = "https://www.gravatar.com/avatar/" + hashlib.md5(
'''$${slap-configuration:root-instance-title}'''
).hexdigest() + "?s=256&d=retro"
shutil.copy(self.download(gravatar_url), '''$${:location}''')
except Exception:
# Because installation should work offline, if we can't download a favicon,
# just ignore this step.
self.logger.exception("Error while downloading favicon, using empty one")
open('''$${:location}''', 'w').close()
finally:
self.buildout['buildout']['offline'] = buildout_offline
location = $${directory:frontend-static}/$${:filename}
filename = $${:_buildout_section_name_}
[user]
recipe = slapos.cookbook:userinfo
......
......@@ -74,6 +74,11 @@ class TestTheia(SlapOSInstanceTestCase):
urljoin(authenticated_url, '/public/test_file'), verify=False)
self.assertEqual('hello', resp.text)
# there's a (not empty) favicon
resp = requests.get(
urljoin(authenticated_url, '/favicon.ico'), verify=False)
self.assertEqual(requests.codes.ok, resp.status_code)
self.assertTrue(resp.raw)
def test_theia_slapos(self):
# Make sure we can use the shell and the integrated slapos command
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment