mirror of
https://git.nolog.cz/NoLog.cz/nginx-configurator.git
synced 2025-01-31 11:53:35 +01:00
add certs-only flag
This commit is contained in:
parent
c8a31d1d74
commit
e5e11af36d
2 changed files with 23 additions and 15 deletions
36
ncc/main.py
36
ncc/main.py
|
@ -91,13 +91,13 @@ def cli():
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@click.option(
|
@click.option(
|
||||||
"--dehydrated-only",
|
"--certs-only",
|
||||||
type=bool,
|
type=bool,
|
||||||
is_flag=True,
|
is_flag=True,
|
||||||
help="Only fetches and deploys new certificates",
|
help="Only fetches and deploys new certificates",
|
||||||
)
|
)
|
||||||
@click.option("--skip-master-check", type=bool, is_flag=True)
|
@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
|
"""Deploy the configuration to the cluster
|
||||||
|
|
||||||
Does the following:
|
Does the following:
|
||||||
|
@ -117,7 +117,7 @@ def up(dehydrated_only: bool, skip_master_check: bool):
|
||||||
|
|
||||||
with Step("Preparing configuration..."):
|
with Step("Preparing configuration..."):
|
||||||
dehydrated_dir = Path(CONFIG["dehydrated_dir"])
|
dehydrated_dir = Path(CONFIG["dehydrated_dir"])
|
||||||
if not dehydrated_only:
|
if not certs_only:
|
||||||
certs.generate_ssl(
|
certs.generate_ssl(
|
||||||
Path(CONFIG["main_config"]),
|
Path(CONFIG["main_config"]),
|
||||||
Path(CONFIG["dehydrated_dir"]) / "domains.txt",
|
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)})"
|
f"dehydrated returned {ec} (log: {click.format_filename(log)})"
|
||||||
)
|
)
|
||||||
|
|
||||||
ec, stdout = sysaction.run_shell(
|
if not certs_only:
|
||||||
("nginx", "-t", "-p", ".", "-c", CONFIG["main_config"]), window_height=5
|
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 ec != 0:
|
||||||
|
raise NccException("configuration did not pass nginx test", log=stdout)
|
||||||
|
|
||||||
with Step("Deploying to cluster...") as step:
|
with Step("Deploying to cluster...") as step:
|
||||||
for target in CONFIG["targets"]:
|
for target in CONFIG["targets"]:
|
||||||
step.echo('deploying to "' + target + '"', nl=False)
|
step.echo('deploying to "' + target + '"', nl=False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sysrsync.run(
|
if certs_only:
|
||||||
source=os.getcwd(),
|
sysrsync.run(
|
||||||
destination=target,
|
source=os.getcwd() + "/" + str(dehydrated_dir / "certs"),
|
||||||
exclusions=[str(dehydrated_dir / "archive/**")],
|
destination=target + "/" + str(dehydrated_dir / "certs"),
|
||||||
options=["-a", "--delete"],
|
options=["-a", "--delete"],
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
sysrsync.run(
|
||||||
|
source=os.getcwd(),
|
||||||
|
destination=target,
|
||||||
|
exclusions=[str(dehydrated_dir / "archive/**")],
|
||||||
|
options=["-a", "--delete"],
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
step.echo(click.style(" E", fg="red"))
|
step.echo(click.style(" E", fg="red"))
|
||||||
raise NccException("failed to rsync configuration") from e
|
raise NccException("failed to rsync configuration") from e
|
||||||
|
|
|
@ -21,7 +21,7 @@ def run_shell(cmd, window_height=0):
|
||||||
buf = deque()
|
buf = deque()
|
||||||
for line in out.stdout:
|
for line in out.stdout:
|
||||||
term_size = os.get_terminal_size()
|
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)
|
stdout.append(line)
|
||||||
buf.append(prefixed)
|
buf.append(prefixed)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue