Add --nocache option to container image build

Change-Id: I11f0677681e51a59bcbb171d8da0e14c853d6c5c
This commit is contained in:
Michal Nasiadka 2021-03-26 10:15:38 +00:00
parent 0e2efc09ec
commit 0408e5388f
4 changed files with 52 additions and 2 deletions

View File

@ -4,6 +4,8 @@
vars:
# Set this to True to push images to the registry when built.
push_images: False
# Set this to True to skip using cache.
nocache: False
# Set this variable to a space-separated list of regexes to override the
# default set of images.
container_image_regexes: ""
@ -52,6 +54,7 @@
{% if item.type is defined %}--type {{ item.type }}{% endif %}
{% if kolla_docker_registry is not none %}--registry {{ kolla_docker_registry }}{% endif %}
{% if push_images | bool %}--push{% endif %}
{% if nocache | bool %}--nocache{% endif %}
{{ item.regexes }} 2>&1 | tee --append {{ kolla_build_log_path }}
executable: /bin/bash
with_items: "{{ container_image_sets }}"

View File

@ -760,6 +760,8 @@ class SeedContainerImageBuild(KayobeAnsibleMixin, VaultMixin, Command):
parser = super(SeedContainerImageBuild, self).get_parser(
prog_name)
group = parser.add_argument_group("Container Image Build")
group.add_argument("--nocache", action="store_true",
help="whether to not use cache")
group.add_argument("--push", action="store_true",
help="whether to push images to a registry after "
"building")
@ -773,7 +775,10 @@ class SeedContainerImageBuild(KayobeAnsibleMixin, VaultMixin, Command):
playbooks = _build_playbook_list(
"container-image-builders-check", "kolla-build",
"container-image-build")
extra_vars = {"push_images": parsed_args.push}
extra_vars = {
"nocache": parsed_args.nocache,
"push_images": parsed_args.push
}
if parsed_args.regex:
regexes = " ".join(parsed_args.regex)
extra_vars["container_image_regexes"] = regexes
@ -1483,6 +1488,8 @@ class OvercloudContainerImageBuild(KayobeAnsibleMixin, VaultMixin, Command):
parser = super(OvercloudContainerImageBuild, self).get_parser(
prog_name)
group = parser.add_argument_group("Container Image Build")
group.add_argument("--nocache", action="store_true",
help="whether to not use cache")
group.add_argument("--push", action="store_true",
help="whether to push images to a registry after "
"building")
@ -1496,7 +1503,10 @@ class OvercloudContainerImageBuild(KayobeAnsibleMixin, VaultMixin, Command):
playbooks = _build_playbook_list(
"container-image-builders-check", "kolla-build",
"container-image-build")
extra_vars = {"push_images": parsed_args.push}
extra_vars = {
"nocache": parsed_args.nocache,
"push_images": parsed_args.push
}
if parsed_args.regex:
regexes = " ".join(parsed_args.regex)
extra_vars["container_image_regexes"] = regexes

View File

@ -694,6 +694,7 @@ class TestCase(unittest.TestCase):
"container_image_sets": (
"{{ seed_container_image_sets }}"),
"push_images": False,
"nocache": False
}
),
]
@ -720,6 +721,35 @@ class TestCase(unittest.TestCase):
extra_vars={
"container_image_regexes": "^regex1$ ^regex2$",
"push_images": True,
"nocache": False
}
),
]
self.assertEqual(expected_calls, mock_run.call_args_list)
@mock.patch.object(commands.KayobeAnsibleMixin,
"run_kayobe_playbooks")
def test_seed_container_image_build_with_nocache(self, mock_run):
command = commands.SeedContainerImageBuild(TestApp(), [])
parser = command.get_parser("test")
parsed_args = parser.parse_args(["--nocache"])
result = command.run(parsed_args)
self.assertEqual(0, result)
expected_calls = [
mock.call(
mock.ANY,
[
utils.get_data_files_path(
"ansible", "container-image-builders-check.yml"),
utils.get_data_files_path("ansible", "kolla-build.yml"),
utils.get_data_files_path(
"ansible", "container-image-build.yml")
],
extra_vars={
"container_image_sets": (
"{{ seed_container_image_sets }}"),
"push_images": False,
"nocache": True
}
),
]
@ -1635,6 +1665,7 @@ class TestCase(unittest.TestCase):
"container_image_sets": (
"{{ overcloud_container_image_sets }}"),
"push_images": False,
"nocache": False
}
),
]
@ -1661,6 +1692,7 @@ class TestCase(unittest.TestCase):
extra_vars={
"container_image_regexes": "^regex1$ ^regex2$",
"push_images": True,
"nocache": False
}
),
]

View File

@ -0,0 +1,5 @@
---
features:
- |
Added new option (``--nocache``) to ``kayobe seed container image build``
and ``kayobe overcloud container image build`` to skip using build cache.