Skip to content

Remove calculate_images_to_build function #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 11 additions & 33 deletions pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1518,40 +1518,13 @@ def build_all_images(
build_image(image, build_configuration)


def calculate_images_to_build(
images: List[str], include: Optional[List[str]], exclude: Optional[List[str]]
) -> Set[str]:
"""
Calculates which images to build based on the `images`, `include` and `exclude` sets.

>>> calculate_images_to_build(["a", "b"], ["a"], ["b"])
... ["a"]
"""

if not include and not exclude:
return set(images)
include = set(include or [])
exclude = set(exclude or [])
images = set(images or [])

for image in include.union(exclude):
if image not in images:
raise ValueError("Image definition {} not found".format(image))

images_to_build = include.intersection(images)
if exclude:
images_to_build = images.difference(exclude)
return images_to_build


def main():
_setup_tracing()
_setup_tracing()

parser = argparse.ArgumentParser()
parser.add_argument("--include", action="append", help="list of images to include")
parser.add_argument("--exclude", action="append", help="list of images to exclude")
parser.add_argument("--builder", default="docker", type=str, help="docker or podman")
parser.add_argument("--include", help="list of images to include")
parser.add_argument("--builder", default="docker", type=str)
parser.add_argument("--list-images", action="store_true")
parser.add_argument("--parallel", action="store_true", default=False)
parser.add_argument("--debug", action="store_true", default=False)
Expand Down Expand Up @@ -1588,12 +1561,17 @@ def main():
if not args.sign:
logger.warning("--sign flag not provided, images won't be signed")

images_to_build = calculate_images_to_build(
list(get_builder_function_for_image_name().keys()), args.include, args.exclude
)
if args.include is None:
print("No images to build, --include is required.")
sys.exit(1)

image_to_build = args.include
if args.include not in get_builder_function_for_image_name():
print("Image {} not found".format(args.include))
sys.exit(1)

build_all_images(
images_to_build,
image_to_build,
args.builder,
debug=args.debug,
parallel=args.parallel,
Expand Down
54 changes: 1 addition & 53 deletions pipeline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest

from pipeline import (
calculate_images_to_build,
get_included_images,
gather_all_supported_agent_versions,
gather_latest_agent_versions,
get_versions_to_rebuild,
Expand Down Expand Up @@ -64,58 +64,6 @@ def test_operator_build_configuration_defaults():
assert config.namespace == "default"


@pytest.mark.parametrize(
"test_case",
[
(["a", "b", "c"], ["a"], ["b"], {"a", "c"}),
(["a", "b", "c"], ["a", "b"], None, {"a", "b"}),
(["a", "b", "c"], None, ["a"], {"b", "c"}),
(["a", "b", "c"], [], [], {"a", "b", "c"}),
(["a", "b", "c"], ["d"], None, ValueError),
(["a", "b", "c"], None, ["d"], ValueError),
([], ["a"], ["b"], ValueError),
(["a", "b", "c"], None, None, {"a", "b", "c"}),
# Given an include, it should only return include images
(["cli", "ops-manager", "appdb-daily", "init-appdb"], ["cli"], [], {"cli"}),
# Given no include nor excludes it should return all images
(
["cli", "ops-manager", "appdb-daily", "init-appdb"],
[],
[],
{"init-appdb", "appdb-daily", "ops-manager", "cli"},
),
# Given an exclude, it should return all images except the excluded ones
(
["cli", "ops-manager", "appdb-daily", "init-appdb"],
[],
["init-appdb", "appdb-daily"],
{"ops-manager", "cli"},
),
# Given an include and a different exclude, it should return all images except the exclusions
(
["cli", "ops-manager", "appdb-daily", "init-appdb"],
["appdb-daily"],
["init-appdb"],
{"appdb-daily", "cli", "ops-manager"},
),
# Given multiple includes and a different exclude, it should return all images except the exclusions
(
["cli", "ops-manager", "appdb-daily", "init-appdb"],
["cli", "appdb-daily"],
["init-appdb"],
{"appdb-daily", "cli", "ops-manager"},
),
],
)
def test_calculate_images_to_build(test_case):
images, include, exclude, expected = test_case
if expected is ValueError:
with pytest.raises(ValueError):
calculate_images_to_build(images, include, exclude)
else:
assert calculate_images_to_build(images, include, exclude) == expected


@pytest.mark.parametrize(
"version,min_version,max_version,expected",
[
Expand Down