Skip to content

Commit e0216a6

Browse files
committed
Add horizon customisation doc
1 parent 5ddc51a commit e0216a6

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
.. include:: vars.rst
2+
3+
====================================
4+
Customising Horizon
5+
====================================
6+
7+
Horizon is the most frequent site-specific container customisation required:
8+
other customisations tend to be common across deployments, but personalisation
9+
of Horizon is unique to each institution.
10+
11+
This describes a simple process for customising the Horizon theme.
12+
13+
Creating a custom Horizon theme
14+
-------------------------------
15+
16+
A simple custom theme for Horizon can be implemented as small modifications of
17+
an existing theme, such as the `Default
18+
<https://opendev.org/openstack/horizon/src/branch/master/openstack_dashboard/themes/default>`__
19+
one.
20+
21+
A theme contains at least two files: ``static/_styles.scss``, which can be empty, and
22+
``static/_variables.scss``, which can reference another theme like this:
23+
24+
.. code-block:: scss
25+
26+
@import "/themes/default/variables";
27+
@import "/themes/default/styles";
28+
29+
Some resources such as logos can be overridden by dropping SVG image files into
30+
``static/img`` (since the Ocata release, files must be SVG instead of PNG). See
31+
`the Horizon documentation
32+
<https://docs.openstack.org/horizon/latest/configuration/themes.html#customizing-the-logo>`__
33+
for more details.
34+
35+
Content on some pages such as the splash (login) screen can be updated using
36+
templates.
37+
38+
See `our example horizon-theme <https://github.com/stackhpc/horizon-theme>`__
39+
which inherits from the default theme and includes:
40+
41+
* a custom splash screen logo
42+
* a custom top-left logo
43+
* a custom message on the splash screen
44+
45+
Further reading:
46+
47+
* https://docs.openstack.org/horizon/latest/configuration/customizing.html
48+
* https://docs.openstack.org/horizon/latest/configuration/themes.html
49+
* https://docs.openstack.org/horizon/latest/configuration/branding.html
50+
51+
Building a Horizon container image with custom theme
52+
----------------------------------------------------
53+
54+
Building a custom container image for Horizon can be done by modifying
55+
``kolla.yml`` to fetch the custom theme and include it in the image:
56+
57+
.. code-block:: yaml
58+
:substitutions:
59+
60+
kolla_sources:
61+
horizon-additions-theme-<custom theme name>:
62+
type: "git"
63+
location: <custom theme repository url>
64+
reference: master
65+
66+
kolla_build_blocks:
67+
horizon_footer: |
68+
# Binary images cannot use the additions mechanism.
69+
{% raw %}
70+
{% if install_type == 'source' %}
71+
ADD additions-archive /
72+
RUN mkdir -p /etc/openstack-dashboard/themes/<custom theme name> \
73+
&& cp -R /additions/horizon-additions-theme-<custom theme name>-archive-master/* /etc/openstack-dashboard/themes/<custom theme name>/ \
74+
&& chown -R horizon: /etc/openstack-dashboard/themes
75+
{% endif %}
76+
{% endraw %}
77+
78+
If using a specific container image tag, don't forget to set:
79+
80+
.. code-block:: yaml
81+
82+
kolla_tag: mytag
83+
84+
Build the image with:
85+
86+
.. code-block:: console
87+
88+
kayobe overcloud container image build horizon -e kolla_install_type=source --push
89+
90+
Pull the new Horizon container to the controller:
91+
92+
.. code-block:: console
93+
94+
kayobe overcloud container image pull --kolla-tags horizon
95+
96+
Deploy and use the custom theme
97+
-------------------------------
98+
99+
Switch to source image type in ``${KAYOBE_CONFIG_PATH}/kolla/globals.yml``:
100+
101+
.. code-block:: yaml
102+
103+
horizon_install_type: source
104+
105+
You may also need to update the container image tag:
106+
107+
.. code-block:: yaml
108+
109+
horizon_tag: mytag
110+
111+
Configure Horizon to include the custom theme and use it by default:
112+
113+
.. code-block:: console
114+
115+
mkdir -p ${KAYOBE_CONFIG_PATH}/kolla/config/horizon/
116+
117+
Add to ``${KAYOBE_CONFIG_PATH}/kolla/config/horizon/custom_local_settings``:
118+
119+
.. code-block:: console
120+
121+
AVAILABLE_THEMES = [
122+
('default', 'Default', 'themes/default'),
123+
('material', 'Material', 'themes/material'),
124+
('<custom theme name>', '<custom theme visible name>', '/etc/openstack-dashboard/themes/<custom theme name>'),
125+
]
126+
DEFAULT_THEME = '<custom theme name>'
127+
128+
You can also set other customisations in this file, such as the HTML title of the page:
129+
130+
.. code-block:: console
131+
132+
SITE_BRANDING = "<Your Branding>"
133+
134+
Deploy with:
135+
136+
.. code-block:: console
137+
138+
kayobe overcloud service reconfigure --kolla-tags horizon
139+
140+
Troubleshooting
141+
---------------
142+
143+
Make sure you build source images, as binary images cannot use the addition
144+
mechanism used here.
145+
146+
If the theme is selected but the logo doesn’t load, try running these commands
147+
inside the ``horizon`` container:
148+
149+
.. code-block:: console
150+
151+
/var/lib/kolla/venv/bin/python /var/lib/kolla/venv/bin/manage.py collectstatic --noinput --clear
152+
/var/lib/kolla/venv/bin/python /var/lib/kolla/venv/bin/manage.py compress --force
153+
settings_bundle | md5sum > /var/lib/kolla/.settings.md5sum.txt
154+
155+
Alternatively, try changing anything in ``custom_local_settings`` and restarting
156+
the ``horizon`` container.
157+
158+
If the ``horizon`` container is restarting with the following error:
159+
160+
.. code-block:: console
161+
162+
/var/lib/kolla/venv/bin/python /var/lib/kolla/venv/bin/manage.py compress --force
163+
CommandError: An error occurred during rendering /var/lib/kolla/venv/lib/python3.6/site-packages/openstack_dashboard/templates/horizon/_scripts.html: Couldn't find any precompiler in COMPRESS_PRECOMPILERS setting for mimetype '\'text/javascript\''.
164+
165+
It can be resolved by dropping cached content with ``docker restart
166+
memcached``. Note this will log out users from Horizon, as Django sessions are
167+
stored in Memcached.

0 commit comments

Comments
 (0)