Convert dcm alias to script
Enhance possibilities of dcm command for handy using * define new commnads * dump services * services order startup
This commit is contained in:
116
bin/dcm
Executable file
116
bin/dcm
Executable file
@@ -0,0 +1,116 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
pulsar
|
||||||
|
# wait-for-pulsar <check-delay> <max-duration>
|
||||||
|
pulsar-create-namespace
|
||||||
|
# wait-for-pulsar-create-namespace - wanted return code 0
|
||||||
|
postgres redis jaeger router
|
||||||
|
# wait-for-postgres
|
||||||
|
|
||||||
|
# jeste poresit fazovani
|
||||||
|
metadata-api-new aqe afm-exec-api result-cache scan-model sql-executor swagger-ui
|
||||||
|
"""
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import yaml
|
||||||
|
import pprint
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
from sys import argv
|
||||||
|
from time import time, sleep
|
||||||
|
|
||||||
|
|
||||||
|
def split(text):
|
||||||
|
return re.split(r'\s+', text)
|
||||||
|
|
||||||
|
|
||||||
|
def prefix_join(prefix, array):
|
||||||
|
return " ".join([prefix + " " + item for item in array])
|
||||||
|
|
||||||
|
|
||||||
|
def dc_files(files):
|
||||||
|
return prefix_join("-f", files)
|
||||||
|
|
||||||
|
|
||||||
|
def load_dc_file(dc_file):
|
||||||
|
with open(dc_file) as yamlFile:
|
||||||
|
dc = yaml.load(yamlFile, Loader=yaml.FullLoader)
|
||||||
|
return dc
|
||||||
|
|
||||||
|
|
||||||
|
def dc_services(dc_file):
|
||||||
|
dc = load_dc_file(dc_file)
|
||||||
|
return [service for service in dc["services"].keys()]
|
||||||
|
|
||||||
|
|
||||||
|
def dump_services(files):
|
||||||
|
for filename in files:
|
||||||
|
for service in dc_services(filename):
|
||||||
|
print(service)
|
||||||
|
|
||||||
|
|
||||||
|
def dump_files(files):
|
||||||
|
for file in files:
|
||||||
|
print(file)
|
||||||
|
|
||||||
|
|
||||||
|
def check_pulsar():
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def check_postgres():
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for(check, delay, duration):
|
||||||
|
start = time()
|
||||||
|
while time() - start < duration:
|
||||||
|
if check():
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
sleep(delay)
|
||||||
|
|
||||||
|
|
||||||
|
def try_load_list(name, default):
|
||||||
|
if name in os.environ:
|
||||||
|
return split(os.environ[name])
|
||||||
|
else:
|
||||||
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
DCF = ["docker-compose.yaml", "docker-compose-monitoring.yaml"]
|
||||||
|
DCF = try_load_list("DCF", DCF)
|
||||||
|
|
||||||
|
TIGER_SERVICES = [
|
||||||
|
"afm-exec-api",
|
||||||
|
"metadata-api-new",
|
||||||
|
"aqe",
|
||||||
|
"result-cache",
|
||||||
|
"scan-model",
|
||||||
|
"sql-executor"
|
||||||
|
]
|
||||||
|
TIGER_SERVICES = try_load_list("SERVICES", TIGER_SERVICES)
|
||||||
|
|
||||||
|
COMMANDS = {
|
||||||
|
"files": lambda: dump_files(DCF),
|
||||||
|
"services": lambda: dump_services(DCF)
|
||||||
|
# deps - vypis zavyslosti
|
||||||
|
# logs - aby se nemuselo zadavat tolik argumentu
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
args = " ".join(argv[1:])
|
||||||
|
cmd = " ".join(["docker-compose", dc_files(DCF), args])
|
||||||
|
print(cmd)
|
||||||
|
returned_value = subprocess.call(cmd, shell=True)
|
||||||
|
exit(returned_value)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
action = argv[1] if len(argv) > 1 else None
|
||||||
|
if action in COMMANDS:
|
||||||
|
COMMANDS[action]()
|
||||||
|
else:
|
||||||
|
main()
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
export DCF="-f docker-compose.yaml -f docker-compose-monitoring.yaml"
|
export DCF="docker-compose.yaml docker-compose-monitoring.yaml"
|
||||||
export MIN_SERVICES="pulsar-create-namespace postgres redis jaeger router"
|
export MIN_SERVICES="pulsar-create-namespace postgres redis jaeger router"
|
||||||
#export SERVICES="afm-exec-api sql-executor scan-model router data-loader"
|
#export SERVICES="afm-exec-api sql-executor scan-model router data-loader"
|
||||||
export SERVICES="afm-exec-api aqe config-manager metadata-api result-cache scan-model sql-executor swagger-ui"
|
export SERVICES="afm-exec-api aqe config-manager metadata-api metadata-api-new result-cache scan-model sql-executor swagger-ui"
|
||||||
export SPRING_ZIPKIN_ENABLED=true
|
export SPRING_ZIPKIN_ENABLED=true
|
||||||
|
|
||||||
alias cbx='gw clean build -x test'
|
|
||||||
alias cbt='gw clean build compileTestKotlin'
|
|
||||||
|
|||||||
Reference in New Issue
Block a user