forked from cerc-io/stack-orchestrator
More logging for webapp deployments (#755)
Reviewed-on: cerc-io/stack-orchestrator#755 Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com> Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
This commit is contained in:
parent
9f1dd284a5
commit
08438b1cd5
@ -283,6 +283,7 @@ def command(ctx, kube_config, laconic_config, image_registry, deployment_parent_
|
|||||||
dump_known_requests(state_file, [r], "DEPLOYING")
|
dump_known_requests(state_file, [r], "DEPLOYING")
|
||||||
status = "ERROR"
|
status = "ERROR"
|
||||||
run_log_file = None
|
run_log_file = None
|
||||||
|
run_reg_client = laconic
|
||||||
try:
|
try:
|
||||||
run_id = f"{r.id}-{str(time.time()).split('.')[0]}-{str(uuid.uuid4()).split('-')[0]}"
|
run_id = f"{r.id}-{str(time.time()).split('.')[0]}-{str(uuid.uuid4()).split('-')[0]}"
|
||||||
if log_dir:
|
if log_dir:
|
||||||
@ -292,10 +293,12 @@ def command(ctx, kube_config, laconic_config, image_registry, deployment_parent_
|
|||||||
run_log_file_path = os.path.join(run_log_dir, f"{run_id}.log")
|
run_log_file_path = os.path.join(run_log_dir, f"{run_id}.log")
|
||||||
print(f"Directing deployment logs to: {run_log_file_path}")
|
print(f"Directing deployment logs to: {run_log_file_path}")
|
||||||
run_log_file = open(run_log_file_path, "wt")
|
run_log_file = open(run_log_file_path, "wt")
|
||||||
|
run_reg_client = LaconicRegistryClient(laconic_config, log_file=run_log_file)
|
||||||
|
|
||||||
process_app_deployment_request(
|
process_app_deployment_request(
|
||||||
run_id,
|
run_id,
|
||||||
ctx,
|
ctx,
|
||||||
laconic,
|
run_reg_client,
|
||||||
r,
|
r,
|
||||||
record_namespace_deployments,
|
record_namespace_deployments,
|
||||||
record_namespace_dns,
|
record_namespace_dns,
|
||||||
|
@ -39,13 +39,14 @@ class AttrDict(dict):
|
|||||||
return v
|
return v
|
||||||
|
|
||||||
|
|
||||||
def cmd(*vargs):
|
def logged_cmd(log_file, *vargs):
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(vargs, capture_output=True)
|
print(" ".join(vargs), file=log_file)
|
||||||
|
result = subprocess.run(vargs, capture_output=True, stdout=log_file, stderr=log_file)
|
||||||
result.check_returncode()
|
result.check_returncode()
|
||||||
return result.stdout.decode()
|
return result.stdout.decode()
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(result.stderr.decode())
|
print(result.stderr.decode(), log_file)
|
||||||
raise err
|
raise err
|
||||||
|
|
||||||
|
|
||||||
@ -58,8 +59,9 @@ def match_owner(recordA, *records):
|
|||||||
|
|
||||||
|
|
||||||
class LaconicRegistryClient:
|
class LaconicRegistryClient:
|
||||||
def __init__(self, config_file):
|
def __init__(self, config_file, log_file=None):
|
||||||
self.config_file = config_file
|
self.config_file = config_file
|
||||||
|
self.log_file = log_file
|
||||||
self.cache = AttrDict(
|
self.cache = AttrDict(
|
||||||
{
|
{
|
||||||
"name_or_id": {},
|
"name_or_id": {},
|
||||||
@ -77,7 +79,7 @@ class LaconicRegistryClient:
|
|||||||
args.append("--%s" % k)
|
args.append("--%s" % k)
|
||||||
args.append(str(v))
|
args.append(str(v))
|
||||||
|
|
||||||
results = [AttrDict(r) for r in json.loads(cmd(*args))]
|
results = [AttrDict(r) for r in json.loads(logged_cmd(self.log_file, *args))]
|
||||||
|
|
||||||
# Most recent records first
|
# Most recent records first
|
||||||
results.sort(key=lambda r: r.createTime)
|
results.sort(key=lambda r: r.createTime)
|
||||||
@ -115,7 +117,7 @@ class LaconicRegistryClient:
|
|||||||
|
|
||||||
args = ["laconic", "-c", self.config_file, "cns", "name", "resolve", name]
|
args = ["laconic", "-c", self.config_file, "cns", "name", "resolve", name]
|
||||||
|
|
||||||
parsed = [AttrDict(r) for r in json.loads(cmd(*args))]
|
parsed = [AttrDict(r) for r in json.loads(logged_cmd(self.log_file, *args))]
|
||||||
if parsed:
|
if parsed:
|
||||||
self._add_to_cache(parsed)
|
self._add_to_cache(parsed)
|
||||||
return parsed[0]
|
return parsed[0]
|
||||||
@ -145,7 +147,7 @@ class LaconicRegistryClient:
|
|||||||
name_or_id,
|
name_or_id,
|
||||||
]
|
]
|
||||||
|
|
||||||
parsed = [AttrDict(r) for r in json.loads(cmd(*args))]
|
parsed = [AttrDict(r) for r in json.loads(logged_cmd(self.log_file, *args))]
|
||||||
if len(parsed):
|
if len(parsed):
|
||||||
self._add_to_cache(parsed)
|
self._add_to_cache(parsed)
|
||||||
return parsed[0]
|
return parsed[0]
|
||||||
@ -173,22 +175,22 @@ class LaconicRegistryClient:
|
|||||||
record_file = open(record_fname, 'w')
|
record_file = open(record_fname, 'w')
|
||||||
yaml.dump(record, record_file)
|
yaml.dump(record, record_file)
|
||||||
record_file.close()
|
record_file.close()
|
||||||
print(open(record_fname, 'r').read())
|
print(open(record_fname, 'r').read(), file=self.log_file)
|
||||||
|
|
||||||
new_record_id = json.loads(
|
new_record_id = json.loads(
|
||||||
cmd("laconic", "-c", self.config_file, "cns", "record", "publish", "--filename", record_fname)
|
logged_cmd(self.log_file, "laconic", "-c", self.config_file, "cns", "record", "publish", "--filename", record_fname)
|
||||||
)["id"]
|
)["id"]
|
||||||
for name in names:
|
for name in names:
|
||||||
self.set_name(name, new_record_id)
|
self.set_name(name, new_record_id)
|
||||||
return new_record_id
|
return new_record_id
|
||||||
finally:
|
finally:
|
||||||
cmd("rm", "-rf", tmpdir)
|
logged_cmd("rm", "-rf", tmpdir)
|
||||||
|
|
||||||
def set_name(self, name, record_id):
|
def set_name(self, name, record_id):
|
||||||
cmd("laconic", "-c", self.config_file, "cns", "name", "set", name, record_id)
|
logged_cmd(self.log_file, "laconic", "-c", self.config_file, "cns", "name", "set", name, record_id)
|
||||||
|
|
||||||
def delete_name(self, name):
|
def delete_name(self, name):
|
||||||
cmd("laconic", "-c", self.config_file, "cns", "name", "delete", name)
|
logged_cmd(self.log_file, "laconic", "-c", self.config_file, "cns", "name", "delete", name)
|
||||||
|
|
||||||
|
|
||||||
def file_hash(filename):
|
def file_hash(filename):
|
||||||
@ -257,7 +259,7 @@ def build_container_image(app_record, tag, extra_build_args=[], log_file=None):
|
|||||||
result = subprocess.run(build_command, stdout=log_file, stderr=log_file)
|
result = subprocess.run(build_command, stdout=log_file, stderr=log_file)
|
||||||
result.check_returncode()
|
result.check_returncode()
|
||||||
finally:
|
finally:
|
||||||
cmd("rm", "-rf", tmpdir)
|
logged_cmd(log_file, "rm", "-rf", tmpdir)
|
||||||
|
|
||||||
|
|
||||||
def push_container_image(deployment_dir, log_file=None):
|
def push_container_image(deployment_dir, log_file=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user