Skip to content

Commit 93daf54

Browse files
authored
Merge pull request #386 from stackhpc/upstream/master-2025-02-24
Synchronise master with upstream
2 parents fe548bb + 48423b9 commit 93daf54

File tree

26 files changed

+334
-245
lines changed

26 files changed

+334
-245
lines changed

.ansible-lint

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
exclude_paths:
3+
- .cache/ # implicit unless exclude_paths is defined in config
4+
- .zuul.d/
5+
offline: true
6+
parseable: true
7+
profile: basic
8+
skip_list:
9+
- package-latest
10+
- role-name
11+
strict: true
12+
use_default_rules: true

.yamllint

Lines changed: 0 additions & 10 deletions
This file was deleted.

.zuul.d/base.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@
126126
run: tests/playbooks/run.yml
127127
post-run: tests/playbooks/post.yml
128128
attempts: 5
129+
roles:
130+
- zuul: openstack/ansible-collection-kolla
129131
irrelevant-files:
130132
- ^.*\.rst$
131133
- ^doc/.*

doc/source/admin/image-building.rst

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,98 @@ The template becomes now:
525525
RUN cp /additions/jenkins/jenkins.json /jenkins.json
526526
{% endblock %}
527527
528+
Custom docker templates
529+
-----------------------
530+
531+
In order to unify the process of managing OpenStack-related projects, Kolla
532+
provides a way of building images for external 'non-built-in' projects.
533+
534+
If the template for a 'non-built-in' project meets Kolla template standards,
535+
an operator can provide a root directory with a template via the
536+
``--docker-dir`` CLI option (can be specified multiple times).
537+
538+
All Kolla's jinja2 macros should be available the same as for built-in
539+
projects with some notes:
540+
541+
- The ``configure_user`` macro. As the 'non-built-in' user is unknown to Kolla,
542+
there are no default values for user ID and group ID to use.
543+
To use this macro, an operator should specify "non-default" user details
544+
with ``<custom_user_name>-user`` configuration section and include info
545+
for ``uid`` and ``gid`` at least.
546+
547+
Let's look into how an operator can build an image for an in-house project
548+
with Kolla using `openstack/releases <https://opendev.org/openstack/releases>`_
549+
project.
550+
551+
First, create a ``Dockerfile.j2`` template for the project.
552+
553+
.. path /home/kolla/custom-kolla-docker-templates/releaser/Dockerfile.j2
554+
.. code-block:: jinja
555+
556+
FROM {{ namespace }}/{{ image_prefix }}openstack-base:{{ tag }}
557+
558+
{% block labels %}
559+
LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build_date }}"
560+
{% endblock %}
561+
562+
{% block releaser_header %}{% endblock %}
563+
564+
{% import "macros.j2" as macros with context %}
565+
566+
{{ macros.configure_user(name='releaser') }}
567+
568+
RUN ln -s releaser-source/* /releaser \
569+
&& {{ macros.install_pip(['/releaser-source'] | customizable("pip_packages")) }} \
570+
&& mkdir -p /etc/releaser \
571+
&& chown -R releaser: /etc/releaser \
572+
&& chmod 750 /etc/sudoers.d \
573+
&& touch /usr/local/bin/kolla_releaser_extend_start \
574+
&& chmod 644 /usr/local/bin/kolla_extend_start /usr/local/bin/kolla_releaser_extend_start
575+
576+
{% block footer %}{% endblock %}
577+
578+
Suggested directory structure:
579+
580+
.. code-block:: console
581+
582+
custom-kolla-docker-templates
583+
|__ releaser
584+
|__ Dockerfile.j2
585+
586+
Then, modify Kolla's configuration so the engine can download sources and
587+
configure users.
588+
589+
.. path /etc/kolla/kolla-build.conf
590+
.. code-block:: ini
591+
592+
[releaser]
593+
type = git
594+
location = https://opendev.org/openstack/releases
595+
reference = master
596+
597+
[releaser-user]
598+
uid = 53001
599+
gid = 53001
600+
601+
Last pre-check before building a new image - ensure that the new template
602+
is visible for Kolla:
603+
604+
.. code-block:: console
605+
606+
$ kolla-build --list-images --docker-dir custom-kolla-docker-templates "^releaser$"
607+
1 : base
608+
2 : releaser
609+
3 : openstack-base
610+
611+
And finally, build the ``releaser`` image, passing the ``--docker-dir``
612+
argument:
613+
614+
.. code-block:: console
615+
616+
kolla-build --docker-dir custom-kolla-docker-templates "^releaser$"
617+
618+
Can I use the ``--template-override`` option for custom templates? Yes!
619+
528620
Custom repos
529621
------------
530622

docker/macros.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
{% endmacro %}
4444

4545
{% macro configure_user(name, groups=None, shell=None, homedir=None) %}
46+
{%- if name not in users %}
47+
{{ raise_error("Failed to find configuration for '" + name + "' user. Try specifying '" + name + "-user' config section.") }}
48+
{%- endif %}
4649
{% set user=users[name] %}
4750
{%- if not homedir %}
4851
{% set homedir='/var/lib/' + name %}

kolla/image/kolla_worker.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ def _get_methods(self):
271271
return {
272272
'debian_package_install': jinja_methods.debian_package_install,
273273
'handle_repos': jinja_methods.handle_repos,
274+
'raise_error': jinja_methods.raise_error,
274275
}
275276

276277
def get_users(self):
@@ -280,7 +281,17 @@ def get_users(self):
280281
for section in all_sections:
281282
match = re.search('^.*-user$', section)
282283
if match:
283-
user = self.conf[match.group(0)]
284+
cfg_group_name = match.group(0)
285+
286+
if cfg_group_name not in self.conf._groups:
287+
self.conf.register_opts(
288+
common_config.get_user_opts(
289+
None, None,
290+
# cut `-user` suffix
291+
group=cfg_group_name[:-5]),
292+
group=cfg_group_name
293+
)
294+
user = self.conf[cfg_group_name]
284295
ret[match.group(0)[:-5]] = {
285296
'uid': user.uid,
286297
'gid': user.gid,

kolla/image/tasks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ def reset_userinfo(tarinfo):
232232
git.Git().clone(source['source'], clone_dir)
233233
git.Git(clone_dir).checkout(source['reference'])
234234
reference_sha = git.Git(clone_dir).rev_parse('HEAD')
235+
git.Git(clone_dir).remote("remove", "origin")
235236
self.logger.debug("Git checkout by reference %s (%s)",
236237
source['reference'], reference_sha)
237238
except Exception as e:

kolla/template/methods.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# limitations under the License.
1212

1313
import os
14+
import typing as t
15+
1416
import yaml
1517

1618
from jinja2 import pass_context
@@ -150,3 +152,7 @@ def handle_repos(context, reponames, mode):
150152
commands = "RUN %s" % commands
151153

152154
return commands
155+
156+
157+
def raise_error(msg: str) -> t.NoReturn:
158+
raise Exception(msg)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
features:
3+
- |
4+
Extends the support of externally-managed projects provided by the
5+
``--docker-dir`` option with an ability to use ``configure_user``
6+
jinja2 macros like Kolla built-in projects.
7+
The operator should specify "non-default" user details with
8+
``<custom_user_name>-user`` configuration section and include info for
9+
``uid`` and ``gid`` at least.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
Removes Git remote URLs after cloning to prevent credential exposure.
5+
`LP#2098904 <https://bugs.launchpad.net/kolla/+bug/2098904>`__

0 commit comments

Comments
 (0)