add certs-only flag

This commit is contained in:
bain 2024-11-04 22:12:42 +01:00
parent 28db18d384
commit b496ada16c
Signed by: bain
GPG key ID: 31F0F25E3BED0B9B
2 changed files with 23 additions and 15 deletions

View file

@ -91,13 +91,13 @@ def cli():
@cli.command()
@click.option(
"--dehydrated-only",
"--certs-only",
type=bool,
is_flag=True,
help="Only fetches and deploys new certificates",
)
@click.option("--skip-master-check", type=bool, is_flag=True)
def up(dehydrated_only: bool, skip_master_check: bool):
def up(certs_only: bool, skip_master_check: bool):
"""Deploy the configuration to the cluster
Does the following:
@ -117,7 +117,7 @@ def up(dehydrated_only: bool, skip_master_check: bool):
with Step("Preparing configuration..."):
dehydrated_dir = Path(CONFIG["dehydrated_dir"])
if not dehydrated_only:
if not certs_only:
certs.generate_ssl(
Path(CONFIG["main_config"]),
Path(CONFIG["dehydrated_dir"]) / "domains.txt",
@ -133,23 +133,31 @@ def up(dehydrated_only: bool, skip_master_check: bool):
f"dehydrated returned {ec} (log: {click.format_filename(log)})"
)
ec, stdout = sysaction.run_shell(
("nginx", "-t", "-p", ".", "-c", CONFIG["main_config"]), window_height=5
)
if ec != 0:
raise NccException("configuration did not pass nginx test", log=stdout)
if not certs_only:
ec, stdout = sysaction.run_shell(
("nginx", "-t", "-p", ".", "-c", CONFIG["main_config"]), window_height=5
)
if ec != 0:
raise NccException("configuration did not pass nginx test", log=stdout)
with Step("Deploying to cluster...") as step:
for target in CONFIG["targets"]:
step.echo('deploying to "' + target + '"', nl=False)
try:
sysrsync.run(
source=os.getcwd(),
destination=target,
exclusions=[str(dehydrated_dir / "archive/**")],
options=["-a", "--delete"],
)
if certs_only:
sysrsync.run(
source=os.getcwd() + "/" + str(dehydrated_dir / "certs"),
destination=target + "/" + str(dehydrated_dir / "certs"),
options=["-a", "--delete"],
)
else:
sysrsync.run(
source=os.getcwd(),
destination=target,
exclusions=[str(dehydrated_dir / "archive/**")],
options=["-a", "--delete"],
)
except Exception as e:
step.echo(click.style(" E", fg="red"))
raise NccException("failed to rsync configuration") from e

View file

@ -21,7 +21,7 @@ def run_shell(cmd, window_height=0):
buf = deque()
for line in out.stdout:
term_size = os.get_terminal_size()
prefixed = (" => " + line).rstrip()[: term_size[0] - 1] + "\n"
prefixed = (" => " + line).replace("\t", " ").rstrip()[: term_size[0] - 1] + "\n"
stdout.append(line)
buf.append(prefixed)