From cfa266a3a2fd2f29ba48ecb93018197af5510649 Mon Sep 17 00:00:00 2001 From: Andriy Kurilin Date: Tue, 17 Sep 2024 13:49:32 +0200 Subject: Allow to use configure_user macro for external templates Commit 79a234239516b94b1b79c7ddafcc4fbe4e3ba155 introduced an ability to build 'in-house'/'not-built-in' projects with Kolla. This commits extends this feature with an ability to use configure_user macro for 'not-built-in' users. The implementation is done the same way as for 'sources', i.e. engine after registers new section structure as soon as it finds unknown '-user' section. In addition, the documentation and CI are extended to cover ``--docker-dir`` option. Change-Id: I690d9f3829083f2493bf286a1c45764b9699219b --- kolla/image/kolla_worker.py | 13 ++++++++++++- kolla/template/methods.py | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'kolla') diff --git a/kolla/image/kolla_worker.py b/kolla/image/kolla_worker.py index 798c8eaa7..3a78a7f35 100644 --- a/kolla/image/kolla_worker.py +++ b/kolla/image/kolla_worker.py @@ -271,6 +271,7 @@ class KollaWorker(object): return { 'debian_package_install': jinja_methods.debian_package_install, 'handle_repos': jinja_methods.handle_repos, + 'raise_error': jinja_methods.raise_error, } def get_users(self): @@ -280,7 +281,17 @@ class KollaWorker(object): for section in all_sections: match = re.search('^.*-user$', section) if match: - user = self.conf[match.group(0)] + cfg_group_name = match.group(0) + + if cfg_group_name not in self.conf._groups: + self.conf.register_opts( + common_config.get_user_opts( + None, None, + # cut `-user` suffix + group=cfg_group_name[:-5]), + group=cfg_group_name + ) + user = self.conf[cfg_group_name] ret[match.group(0)[:-5]] = { 'uid': user.uid, 'gid': user.gid, diff --git a/kolla/template/methods.py b/kolla/template/methods.py index 6747504fa..e9edbfeb0 100644 --- a/kolla/template/methods.py +++ b/kolla/template/methods.py @@ -11,6 +11,8 @@ # limitations under the License. import os +import typing as t + import yaml from jinja2 import pass_context @@ -150,3 +152,7 @@ def handle_repos(context, reponames, mode): commands = "RUN %s" % commands return commands + + +def raise_error(msg: str) -> t.NoReturn: + raise Exception(msg) -- cgit v1.2.3