Add --dry-run option

This commit is contained in:
Thomas E Lackey 2023-12-14 04:55:27 +00:00
parent 88f66a3626
commit 2e27a4661b
2 changed files with 325 additions and 320 deletions

View File

@ -164,10 +164,11 @@ def dump_known_requests(filename, requests):
@click.option("--dns-suffix", help="DNS domain to use eg, laconic.servesthe.world") @click.option("--dns-suffix", help="DNS domain to use eg, laconic.servesthe.world")
@click.option("--record-namespace-dns", help="eg, crn://laconic/dns") @click.option("--record-namespace-dns", help="eg, crn://laconic/dns")
@click.option("--record-namespace-deployments", help="eg, crn://laconic/deployments") @click.option("--record-namespace-deployments", help="eg, crn://laconic/deployments")
@click.option("--dry-run", help="Don't do anything, just report what would be done.", is_flag=True)
@click.pass_context @click.pass_context
def command(ctx, kube_config, laconic_config, image_registry, deployment_parent_dir, def command(ctx, kube_config, laconic_config, image_registry, deployment_parent_dir,
request_id, discover, state_file, only_update_state, request_id, discover, state_file, only_update_state,
dns_suffix, record_namespace_dns, record_namespace_deployments): dns_suffix, record_namespace_dns, record_namespace_deployments, dry_run):
if request_id and discover: if request_id and discover:
print("Cannot specify both --request-id and --discover", file=sys.stderr) print("Cannot specify both --request-id and --discover", file=sys.stderr)
sys.exit(2) sys.exit(2)
@ -196,6 +197,7 @@ def command(ctx, kube_config, laconic_config, image_registry, deployment_parent_
requests = laconic.app_deployment_requests() requests = laconic.app_deployment_requests()
if only_update_state: if only_update_state:
if not dry_run:
dump_known_requests(state_file, requests) dump_known_requests(state_file, requests)
return return
@ -250,6 +252,7 @@ def command(ctx, kube_config, laconic_config, image_registry, deployment_parent_
print("Found %d unsatisfied request(s) to process." % len(requests_to_execute)) print("Found %d unsatisfied request(s) to process." % len(requests_to_execute))
if not dry_run:
for r in requests_to_execute: for r in requests_to_execute:
try: try:
process_app_deployment_request( process_app_deployment_request(

View File

@ -186,8 +186,10 @@ def build_container_image(app_record, tag, extra_build_args=[]):
print(f"Cloning repository {repo} to {clone_dir} ...") print(f"Cloning repository {repo} to {clone_dir} ...")
if ref: if ref:
result = subprocess.run(["git", "clone", "--depth", "1", "--branch", ref, repo, clone_dir]) # TODO: Determing branch or hash, and use depth 1 if we can.
result = subprocess.run(["git", "clone", repo, clone_dir])
result.check_returncode() result.check_returncode()
subprocess.check_call(["git", "checkout", ref], cwd=clone_dir)
else: else:
result = subprocess.run(["git", "clone", "--depth", "1", repo, clone_dir]) result = subprocess.run(["git", "clone", "--depth", "1", repo, clone_dir])
result.check_returncode() result.check_returncode()