From 0d735766dd79d341b0166590f0fbb7c1b6039cb6 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 17 Jan 2025 11:24:27 +0100 Subject: [PATCH 01/17] pass argument to sript VCS_REF_CLIENT --- services/static-webserver/client/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/static-webserver/client/Makefile b/services/static-webserver/client/Makefile index 9e01133e058..95d803ba5c9 100644 --- a/services/static-webserver/client/Makefile +++ b/services/static-webserver/client/Makefile @@ -52,7 +52,7 @@ compile: ## qx compiles host' 'source' -> image's 'build-output' --build-arg VCS_STATUS_CLIENT=${VCS_STATUS_CLIENT} \ --build-arg VCS_URL=${VCS_URL} \ --target=build-client . - python ./scripts/post-compile.py + python ./scripts/post-compile.py ${VCS_REF_CLIENT} touch: ## minimal image build with /project/output-build inside # touch /project/output-build such that multi-stage 'services/web/Dockerfile' can build development target (fixes #1097) From 581c3778f43a1c3e352e219c2e9ce24bfc642156 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 17 Jan 2025 11:25:01 +0100 Subject: [PATCH 02/17] add_no_cache_param --- .../client/scripts/post-compile.py | 61 +++++++++++++++---- .../client/source/boot/index.html | 2 +- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/services/static-webserver/client/scripts/post-compile.py b/services/static-webserver/client/scripts/post-compile.py index afc1cd5033a..f1ceb99e6fd 100644 --- a/services/static-webserver/client/scripts/post-compile.py +++ b/services/static-webserver/client/scripts/post-compile.py @@ -1,41 +1,78 @@ -import os import json - +import os +import random +import sys output_folders = [ - "source-output", # dev output + "source-output", # dev output "build-output", # default production output - "build-client" # I believe we create the production outputs here + "build-client", # I believe we create the production outputs here ] -def read_json_file(filename): +def _read_json_file(filename): dirname = os.path.dirname(__file__) meta_filename = os.path.join(dirname, filename) - with open(meta_filename, "r") as file: + with open(meta_filename) as file: metadata = json.load(file) return metadata["applications"] def update_apps_metadata(): dirname = os.path.dirname(__file__) - applications = read_json_file("apps_metadata.json") + applications = _read_json_file("apps_metadata.json") for i in applications: application = i.get("application") + replacements = i.get("replacements") for output_folder in output_folders: - filename = os.path.join(dirname, '..', output_folder, application, "index.html") + filename = os.path.join( + dirname, "..", output_folder, application, "index.html" + ) if not os.path.isfile(filename): continue - with open(filename, "r") as file: + with open(filename) as file: data = file.read() - replacements = i.get("replacements") for key in replacements: replace_text = replacements[key] - data = data.replace("${"+key+"}", replace_text) - with open(filename, "w") as file: + data = data.replace("${" + key + "}", replace_text) + with open(filename, "w") as file: print(f"Updating app metadata: {filename}") file.write(data) +def _get_index_file_paths(): + index_file_paths = [] + dirname = os.path.dirname(__file__) + applications = _read_json_file("apps_metadata.json") + for i in applications: + application = i.get("application") + for output_folder in output_folders: + index_file_paths.append( + os.path.join(dirname, "..", output_folder, application, "index.html") + ) + return index_file_paths + + +def add_no_cache_param(vcs_ref_client): + index_file_paths = _get_index_file_paths() + for index_file_path in index_file_paths: + if not os.path.isfile(index_file_path): + continue + with open(index_file_path) as index_file: + data = index_file.read() + if vcs_ref_client: + data = data.replace("vcs_ref_client", vcs_ref_client) + else: + random.seed(5) + data = data.replace("vcs_ref_client", str(random.random())) + with open(index_file_path, "w") as file: + print(f"Updating vcs_ref_client: {index_file_path}") + file.write(data) + + if __name__ == "__main__": update_apps_metadata() + vcs_ref_client = None + if len(sys.argv) > 1: + vcs_ref_client = sys.argv[1] + add_no_cache_param(vcs_ref_client) diff --git a/services/static-webserver/client/source/boot/index.html b/services/static-webserver/client/source/boot/index.html index c12e128897c..4be66095443 100644 --- a/services/static-webserver/client/source/boot/index.html +++ b/services/static-webserver/client/source/boot/index.html @@ -67,7 +67,7 @@ ${preBootJs} - + + +