Skip to content

Commit

Permalink
feat: handle run directory for the whole cli
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulFarault committed Jul 15, 2024
1 parent 44be9b1 commit 0084e7b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
10 changes: 10 additions & 0 deletions tdp/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

import logging
from os import chdir
from pathlib import Path
from typing import Optional

Expand Down Expand Up @@ -50,6 +51,15 @@ def load_env(ctx: click.Context, param: click.Parameter, value: Path) -> Optiona
type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]),
help="Set the level of log output.",
)
@click.option(
"--run-directory",
envvar="TDP_RUN_DIRECTORY",
type=click.Path(resolve_path=True, exists=True),
help="Working directory where the executor is launched (`ansible-playbook` for Ansible).",
required=True,
callback=lambda ctx, param, value: chdir(value),
expose_value=False,
)
def cli(log_level: str):
setup_logging(log_level)
logging.info("Logging is configured.")
Expand Down
9 changes: 0 additions & 9 deletions tdp/cli/commands/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@
is_flag=True,
help="Mock the deploy, do not actually run the ansible playbook.",
)
@click.option(
"--run-directory",
envvar="TDP_RUN_DIRECTORY",
type=click.Path(resolve_path=True, path_type=Path, exists=True),
help="Working directory where the executor is launched (`ansible-playbook` for Ansible).",
required=True,
)
@validate_option
@vars_option
def deploy(
Expand All @@ -57,7 +50,6 @@ def deploy(
db_engine: Engine,
force_stale_update: bool,
mock_deploy: bool,
run_directory: Path,
validate: bool,
vars: Path,
):
Expand All @@ -77,7 +69,6 @@ def deploy(
deployment_iterator = DeploymentRunner(
collections=collections,
executor=Executor(
run_directory=run_directory.absolute() if run_directory else None,
dry=dry or mock_deploy,
),
cluster_variables=cluster_variables,
Expand Down
2 changes: 0 additions & 2 deletions tdp/core/deployment/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def __init__(self, run_directory=None, dry: bool = False):
ExecutableNotFoundError: If the ansible-playbook command is not found in PATH.
"""
# TODO configurable via config file
self._rundir = run_directory
self._dry = dry

# Resolve ansible-playbook command
Expand Down Expand Up @@ -57,7 +56,6 @@ def _execute_ansible_command(
command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
cwd=self._rundir,
universal_newlines=True,
)
if res.stdout is None:
Expand Down

0 comments on commit 0084e7b

Please sign in to comment.