diff --git a/application-templates/webapp/frontend/package.json b/application-templates/webapp/frontend/package.json new file mode 100644 index 00000000..b8d45278 --- /dev/null +++ b/application-templates/webapp/frontend/package.json @@ -0,0 +1,11 @@ +{ + "name": "__APP_NAME__", + "scripts": { + "dev": "vite", + "start": "DOMAIN=http://localhost:5000 vite", + "start:dev": "DOMAIN=https://test.ch.metacell.us vite", + "start:local": "DOMAIN=http://samples.ch vite", + "prebuild": "eslint .", + "build": "vite build" + } +} diff --git a/tools/deployment-cli-tools/ch_cli_tools/helm.py b/tools/deployment-cli-tools/ch_cli_tools/helm.py index dc4a6cba..2552dcbe 100644 --- a/tools/deployment-cli-tools/ch_cli_tools/helm.py +++ b/tools/deployment-cli-tools/ch_cli_tools/helm.py @@ -410,7 +410,7 @@ def image_tag(self, image_name, build_context_path=None, dependencies=()): ignore = set(DEFAULT_IGNORE) if os.path.exists(ignore_path): with open(ignore_path) as f: - ignore = ignore.union({line.strip() for line in f}) + ignore = ignore.union({line.strip() for line in f if line.strip() and not line.startswith('#')}) logging.info(f"Ignoring {ignore}") tag = generate_tag_from_content(build_context_path, ignore) logging.info(f"Content hash: {tag}") diff --git a/tools/deployment-cli-tools/ch_cli_tools/utils.py b/tools/deployment-cli-tools/ch_cli_tools/utils.py index 9e2cbf9e..3ec8e6f3 100644 --- a/tools/deployment-cli-tools/ch_cli_tools/utils.py +++ b/tools/deployment-cli-tools/ch_cli_tools/utils.py @@ -145,6 +145,8 @@ def get_template(yaml_path, base_default=False): def file_is_yaml(fname): return fname[-4:] == 'yaml' or fname[-3:] == 'yml' +def file_is_json(fname): + return fname[-4:] == 'json' def replaceindir(root_src_dir, source, replace): """ @@ -270,6 +272,14 @@ def merge_configuration_directories(source, dest): except Exception as e: logging.warning(f"Overwriting file {fdest} with {fpath}") shutil.copy2(fpath, fdest) + elif file_is_json(fpath): + try: + merge_json_files(fpath, fdest) + logging.info( + f"Merged/overridden file content of {fdest} with {fpath}") + except Exception as e: + logging.warning(f"Overwriting file {fdest} with {fpath}") + shutil.copy2(fpath, fdest) else: logging.warning(f"Overwriting file {fdest} with {fpath}") shutil.copy2(fpath, fdest) @@ -280,6 +290,28 @@ def merge_yaml_files(fname, fdest): content_src = yaml.load(f) merge_to_yaml_file(content_src, fdest) +def merge_json_files(fname, fdest): + with open(fname) as f: + content_src = json.load(f) + merge_to_json_file(content_src, fdest) + +def merge_to_json_file(content_src, fdest): + if not content_src: + return + if not exists(fdest): + merged = content_src + else: + with open(fdest) as f: + content_dest = json.load(f) + + merged = dict_merge( + content_dest, content_src) if content_dest else content_src + + if not exists(dirname(fdest)): + os.makedirs(dirname(fdest)) + with open(fdest, "w") as f: + json.dump(merged, f, indent=2) + return merged def merge_to_yaml_file(content_src, fdest): if not content_src: diff --git a/tools/deployment-cli-tools/harness-application b/tools/deployment-cli-tools/harness-application index cc626eea..37bec808 100644 --- a/tools/deployment-cli-tools/harness-application +++ b/tools/deployment-cli-tools/harness-application @@ -71,6 +71,7 @@ if __name__ == "__main__": shutil.move(os.path.join(app_path, args.name), os.path.join(app_path, 'frontend')) generate_ts_client(openapi_file=os.path.join(app_path, 'api/openapi.yaml')) + if 'server' in templates: with tempfile.TemporaryDirectory() as tmp_dirname: copymergedir(os.path.join(CH_ROOT, APPLICATION_TEMPLATE_PATH, template_name), tmp_dirname) diff --git a/tools/deployment-cli-tools/tests/resources/conf-source1/a.json b/tools/deployment-cli-tools/tests/resources/conf-source1/a.json new file mode 100644 index 00000000..acc95bb9 --- /dev/null +++ b/tools/deployment-cli-tools/tests/resources/conf-source1/a.json @@ -0,0 +1,7 @@ +{ + "a": "a", + "b": { + "ba": "ba", + "bc": "bc" + } +} \ No newline at end of file diff --git a/tools/deployment-cli-tools/tests/resources/conf-source1/b.json b/tools/deployment-cli-tools/tests/resources/conf-source1/b.json new file mode 100644 index 00000000..424af7c0 --- /dev/null +++ b/tools/deployment-cli-tools/tests/resources/conf-source1/b.json @@ -0,0 +1,7 @@ +{ + "a": "a", + "b": { + "ba": "ba", + "bb": "bb" + } +} \ No newline at end of file diff --git a/tools/deployment-cli-tools/tests/resources/conf-source2/a.json b/tools/deployment-cli-tools/tests/resources/conf-source2/a.json new file mode 100644 index 00000000..c7f21ebc --- /dev/null +++ b/tools/deployment-cli-tools/tests/resources/conf-source2/a.json @@ -0,0 +1,7 @@ +{ + "a": "a1", + "b": { + "ba": "ba1", + "bb": "bb" + } +} \ No newline at end of file diff --git a/tools/deployment-cli-tools/tests/resources/conf-source2/c.json b/tools/deployment-cli-tools/tests/resources/conf-source2/c.json new file mode 100644 index 00000000..424af7c0 --- /dev/null +++ b/tools/deployment-cli-tools/tests/resources/conf-source2/c.json @@ -0,0 +1,7 @@ +{ + "a": "a", + "b": { + "ba": "ba", + "bb": "bb" + } +} \ No newline at end of file diff --git a/tools/deployment-cli-tools/tests/test_utils.py b/tools/deployment-cli-tools/tests/test_utils.py index cbd813c1..cade7770 100644 --- a/tools/deployment-cli-tools/tests/test_utils.py +++ b/tools/deployment-cli-tools/tests/test_utils.py @@ -47,6 +47,17 @@ def test_merge_configuration_directories(): assert a['b']['ba'] == 'ba1' assert a['b']['bb'] == 'bb' assert a['b']['bc'] == 'bc' + + assert os.path.exists(os.path.join(res_path, "a.json")) + assert os.path.exists(os.path.join(res_path, "b.json")) + assert os.path.exists(os.path.join(res_path, "c.json")) + + with open(os.path.join(res_path, "a.json")) as f: + a = json.load(f) + assert a['a'] == 'a1' + assert a['b']['ba'] == 'ba1' + assert a['b']['bb'] == 'bb' + assert a['b']['bc'] == 'bc' finally: if os.path.exists(res_path): shutil.rmtree(res_path)