From cbe4a76ff79601e1cec2b36d3193a14431de147e Mon Sep 17 00:00:00 2001 From: Ray Fang Date: Fri, 27 Jul 2018 22:46:27 +0800 Subject: [PATCH] Fix #210 (#211) * Fix #210 * Add in_asterisk_list utility function --- iotedgedev/modules.py | 35 +++++++++++++++++------------------ iotedgedev/utility.py | 3 +++ tests/test_utility.py | 12 ++++++++++++ 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/iotedgedev/modules.py b/iotedgedev/modules.py index d36367e..8b058ba 100644 --- a/iotedgedev/modules.py +++ b/iotedgedev/modules.py @@ -84,31 +84,30 @@ class Modules: tags_to_build = set() for module in os.listdir(self.envvars.MODULES_PATH): - if module not in bypass_modules: - module_dir = os.path.join(self.envvars.MODULES_PATH, module) - module_json = Module(self.output, self.utility, os.path.join(module_dir, "module.json")) - for platform in module_json.platforms: - # get the Dockerfile from module.json - dockerfile = os.path.abspath(os.path.join(module_dir, module_json.get_dockerfile_by_platform(platform))) - container_tag = "" if self.envvars.CONTAINER_TAG == "" else "-" + self.envvars.CONTAINER_TAG - tag = "{0}:{1}{2}-{3}".format(module_json.repository, module_json.tag_version, container_tag, platform).lower() - image_tag_map[(module, platform)] = tag - tag_dockerfile_map[tag] = (module, dockerfile) - tag_build_options_map[tag] = module_json.build_options - if len(active_platform) > 0 and (active_platform[0] == "*" or platform in active_platform): - tags_to_build.add(tag) + module_dir = os.path.join(self.envvars.MODULES_PATH, module) + module_json = Module(self.output, self.utility, os.path.join(module_dir, "module.json")) + for platform in module_json.platforms: + # get the Dockerfile from module.json + dockerfile = os.path.abspath(os.path.join(module_dir, module_json.get_dockerfile_by_platform(platform))) + container_tag = "" if self.envvars.CONTAINER_TAG == "" else "-" + self.envvars.CONTAINER_TAG + tag = "{0}:{1}{2}-{3}".format(module_json.repository, module_json.tag_version, container_tag, platform).lower() + image_tag_map[(module, platform)] = tag + tag_dockerfile_map[tag] = (module, dockerfile) + tag_build_options_map[tag] = module_json.build_options + if not self.utility.in_asterisk_list(module, bypass_modules) and self.utility.in_asterisk_list(platform, active_platform): + tags_to_build.add(tag) deployment_manifest = DeploymentManifest(self.envvars, self.output, self.utility, self.envvars.DEPLOYMENT_CONFIG_TEMPLATE_FILE, True) modules_to_process = deployment_manifest.get_modules_to_process() replacements = {} for module, platform in modules_to_process: - if module not in bypass_modules: - key = (module, platform) - if key in image_tag_map: - tag = image_tag_map.get(key) + key = (module, platform) + if key in image_tag_map: + tag = image_tag_map.get(key) + replacements["${{MODULES.{0}.{1}}}".format(module, platform)] = tag + if not self.utility.in_asterisk_list(module, bypass_modules): tags_to_build.add(tag) - replacements["${{MODULES.{0}.{1}}}".format(module, platform)] = tag for tag in tags_to_build: if tag in tag_dockerfile_map: diff --git a/iotedgedev/utility.py b/iotedgedev/utility.py index 13fc09b..d55f55f 100644 --- a/iotedgedev/utility.py +++ b/iotedgedev/utility.py @@ -103,6 +103,9 @@ class Utility: def get_active_docker_platform(self): return [platform.strip() for platform in self.envvars.ACTIVE_DOCKER_PLATFORMS.split(",") if platform] + def in_asterisk_list(self, item, asterisk_list): + return len(asterisk_list) > 0 and (asterisk_list[0] == "*" or item in asterisk_list) + def get_modules_in_config(self, moduleType): modules_config = json.load(open(self.envvars.DEPLOYMENT_CONFIG_FILE_PATH)) diff --git a/tests/test_utility.py b/tests/test_utility.py index 6786256..8242b6d 100644 --- a/tests/test_utility.py +++ b/tests/test_utility.py @@ -42,3 +42,15 @@ def test_copy_template_expand_env(utility, tmpdir): dest = tmpdir.join("deployment_template_2.dest.json").strpath utility.copy_template(test_file_1, dest, replacements=replacements, expand_env=True) assert_json_file_equal(test_file_2, dest) + + +def test_in_asterisk_list(utility): + assert utility.in_asterisk_list("filtermodule", "pipemodule, filtermodule") + + +def test_in_asterisk_list_empty(utility): + assert not utility.in_asterisk_list("filtermodule", "") + + +def test_in_asterisk_list_asterisk(utility): + assert utility.in_asterisk_list("filtermodule", "*")