How to package an OpenStack Horizon Dashboard plugin correctly?

686 views Asked by At

I am packaging a Horizon Plugin. I have a bunch of templates, a view, as well as css, js files, and images.

Everything should be contained so that the package is either a .deb or a tarball. So right now I keep all files in /opt/stack/horizon/openstack_dashboard/dashboards/<my-dashboard-name>.

My question is, how do I include js and css files properly? There is /opt/stack/horizon/openstack_dashboard/settings.py file that specifies HORIZON_CONFIG.js_files, however it is always empty! I put a list of files there, it still comes out as empty in the templates. So the question is, how do I include js and css files in a Horizon dashboard plugin, for the purpose of packaging it in either a single tarball or a .deb package?

1

There are 1 answers

0
Johan Viklund On

You should store static files below <my-dashboard-name>/static. It's best to namespace your static files, I use the following directory structure: <my-dashboard-name>/static/<my-dashboard-name>/js and so on for css and img then I reference the files in the HTML templates with /static/<my-dashboard-name>/js/jsfile.js, that way you won't get any name collisions.

When someone uses your plugin they extract your dashboard and register it in the right places and then additionally they have to run the collectstatic django management command from the base openstack_dashboard directory (in your case /opt/stack/horizon/), either:

$ ./run_tests.sh -m collectstatic

or

$ ./manage.py collectstatic

That should copy your static files to the right places according to how the site has been configured.