From dff4916ed249ab2558c3daaa1b93b8d7f9e026bb Mon Sep 17 00:00:00 2001 From: Martin Blazik Date: Thu, 2 Jun 2022 08:11:12 +0200 Subject: [PATCH] Improve dcm script add "commands" command for listing all commands --- bin/dcm | 59 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/bin/dcm b/bin/dcm index d7352d7..baa6eee 100755 --- a/bin/dcm +++ b/bin/dcm @@ -57,7 +57,7 @@ def load_dc_file(dc_file): def dc_cmd(args): # split join - args = join_args(args) + args = join_args(args) return join_args([DOCKER_COMPOSE, DC_FILES_ARGS, args]) @@ -70,13 +70,18 @@ def dc_run(args): def dc_log(args): args = ["logs", "--no-color"] + args + [r"| sed -r 's/^[^|]+\| //g'"] dc_run(args) - + def dc_services(dc_file): dc = load_dc_file(dc_file) return [service for service in dc["services"].keys()] +def dc_commands(args): + for key in sorted(COMMANDS.keys()): + print(key) + + def dump_services(files): services = [(filename, service) for filename in files for service in dc_services(filename)] services = map(itemgetter(1), services) @@ -102,7 +107,7 @@ def deps_find(service, deps): if new: new_list = " ".join(new) print(f"{service} >> {new_list}") - all.update(services) + all.update(services) del deps[service] for one in new: all.update(deps_find(one, deps)) @@ -114,7 +119,7 @@ def dc_deps(dc_files, args): pp = PrettyPrinter(indent=2) for dc_file in dc_files: deps = deps_load(dc_file) - if service in deps: + if service in deps: all = sorted(deps_find(service, deps)) print("ALL >> " + " ".join(all)) return @@ -145,7 +150,7 @@ def wait_for(check, delay, duration): def service_wait(service, check, delay = 10, duration = 120): echo(f"WAIT FOR {service}") - started = wait_for(check, delay, duration) + started = wait_for(check, delay, duration) if started: echo(f"READY {service}") else: @@ -171,7 +176,7 @@ def dc_check(args): def dc_up(services): - dc_run(["up", "-d", join_args(services)]) + dc_run(["up", "-d"] + services) def dc_wait(args): @@ -190,9 +195,14 @@ def dc_on(args): service_wait(service, check) +def dc_build_parallel(args): + services = args + dc_run(["build", "--parallel"] + args) + + def tiger_on(): dc_on(["pulsar", "postgres"]) - dc_up(["redis", "jaeger", "router"]) + dc_up(["redis", "jaeger", "router"]) dc_on(["result-cache", "metadata-api", "aqe", "sql-executor", "scan-model", "afm-exec-api"]) @@ -210,11 +220,11 @@ DC_FILES = try_load_list("DCF", DEFAULT_DCF) DC_FILES_ARGS = dc_files(DC_FILES) SERVICES = { - "pulsar": - lambda: + "pulsar": + lambda: curl_check("http://localhost:8080/admin/v2/tenants/public"), - "postgres": - lambda: + "postgres": + lambda: system("/usr/bin/pg_isready") == 0, "redis": lambda: @@ -223,33 +233,36 @@ SERVICES = { "aqe": lambda: True, - "metadata-api": - lambda: + "metadata-api": + lambda: curl_check("http://localhost:9008/actuator/health/readiness"), - "afm-exec-api": - lambda: + "afm-exec-api": + lambda: curl_check("http://localhost:9001/actuator/health/readiness"), - "result-cache": - lambda: + "result-cache": + lambda: curl_check("http://localhost:9041/actuator/health/readiness"), - "scan-model": - lambda: + "scan-model": + lambda: curl_check("http://localhost:9061/actuator/health/readiness"), - "sql-executor": - lambda: + "sql-executor": + lambda: curl_check("http://localhost:9101/actuator/health/readiness"), - "data-loader": + "data-loader": None, # co chci testovat? ze ma Exit code 0 } COMMANDS = { "files": lambda args: dump_files(DC_FILES), + "commands": dc_commands, "services": lambda args: dump_services(DC_FILES), "log": dc_log, "deps": lambda args: dc_deps(DC_FILES, args), "check": dc_check, "wait": dc_wait, "on": dc_on, + "pb": dc_build_parallel, + "bp": dc_build_parallel, } @@ -262,7 +275,7 @@ def main(): exit(dc_run(args)) -if __name__ == '__main__': +if __name__ == '__main__': try: main() except KeyboardInterrupt: