From e2402ac1904c2c0fdf85811c91371f29de168ea0 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Mon, 27 May 2024 15:56:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A5=20=E2=80=94=20Change=20default=20c?= =?UTF-8?q?onfig=20file=20path=20to=20argos-config.yaml=20(fix=20#36)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Argos will first try the given config file (given either with `--config` or with `ARGOS_YAML_FILE` env var), then `argos-config.yaml`, then `/etc/argos/config.yaml`. --- .gitignore | 1 + CHANGELOG.md | 1 + argos/commands.py | 40 ++++++++++++++++++---------- argos/server/settings.py | 3 +-- docs/checks.md | 6 ++--- docs/cli.md | 13 ++++++--- docs/configuration.md | 12 +++++---- docs/installation/getting-started.md | 2 +- 8 files changed, 49 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 18d87f6..309295c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,6 @@ venv .env public *.swp +argos-config.yaml config.yaml dist diff --git a/CHANGELOG.md b/CHANGELOG.md index 3430cb0..d421232 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - ✨ β€” Add command to generate example configuration (fix #38) - πŸ“ β€” Improve documentation - ✨ β€” Add command to warn if it’s been long since last viewing an agent (fix #49) +- πŸ’₯ β€” Change default config file path to argos-config.yaml (fix #36) ## 0.1.1 diff --git a/argos/commands.py b/argos/commands.py index 8a76256..746885b 100644 --- a/argos/commands.py +++ b/argos/commands.py @@ -34,14 +34,22 @@ def coroutine(f): def validate_config_access(ctx, param, value): - path = Path(value) - if path.is_file() and os.access(path, os.R_OK): - return value + for file in set(value, "argos-config.yaml", "/etc/argos/config.yaml"): + path = Path(file) - if path.is_file(): - raise click.BadParameter(f"the file {value} is not readabale.") + if path.is_file() and os.access(path, os.R_OK): + return file - raise click.BadParameter(f"the file {value} does not exists or is not reachable.") + if value == "argos-config.yaml": + raise click.BadParameter( + f"the file {value} does not exists or is not reachable, " + "nor does /etc/argos/config.yaml." + ) + + raise click.BadParameter( + f"the file {value} does not exists or is not reachable, " + "nor does argos-config.yaml or /etc/argos/config.yaml." + ) @click.group() @@ -102,9 +110,10 @@ def agent(server_url, auth, max_tasks, wait_time, log_level): @click.option("--port", default=8000, type=int, help="Port to bind") @click.option( "--config", - default="config.yaml", + default="argos-config.yaml", help="Path of the configuration file. " - "If ARGOS_YAML_FILE environment variable is set, its value will be used instead.", + "If ARGOS_YAML_FILE environment variable is set, its value will be used instead. " + "Default value: argos-config.yaml and /etc/argos/config.yaml as fallback.", envvar="ARGOS_YAML_FILE", callback=validate_config_access, ) @@ -150,9 +159,10 @@ def validate_max_results(ctx, param, value): ) @click.option( "--config", - default="config.yaml", + default="argos-config.yaml", help="Path of the configuration file. " - "If ARGOS_YAML_FILE environment variable is set, its value will be used instead.", + "If ARGOS_YAML_FILE environment variable is set, its value will be used instead. " + "Default value: argos-config.yaml and /etc/argos/config.yaml as fallback.", envvar="ARGOS_YAML_FILE", callback=validate_config_access, ) @@ -216,9 +226,10 @@ async def watch_agents(time_without_agent, config): @server.command(short_help="Load or reload tasks’ configuration") @click.option( "--config", - default="config.yaml", + default="argos-config.yaml", help="Path of the configuration file. " - "If ARGOS_YAML_FILE environment variable is set, its value will be used instead.", + "If ARGOS_YAML_FILE environment variable is set, its value will be used instead. " + "Default value: argos-config.yaml and /etc/argos/config.yaml as fallback.", envvar="ARGOS_YAML_FILE", callback=validate_config_access, ) @@ -247,9 +258,10 @@ async def reload_config(config): @server.command() @click.option( "--config", - default="config.yaml", + default="argos-config.yaml", help="Path of the configuration file. " - "If ARGOS_YAML_FILE environment variable is set, its value will be used instead.", + "If ARGOS_YAML_FILE environment variable is set, its value will be used instead. " + "Default value: argos-config.yaml and /etc/argos/config.yaml as fallback.", envvar="ARGOS_YAML_FILE", callback=validate_config_access, ) diff --git a/argos/server/settings.py b/argos/server/settings.py index 12a7286..01861cb 100644 --- a/argos/server/settings.py +++ b/argos/server/settings.py @@ -23,11 +23,10 @@ class Settings(BaseSettings): class DevSettings(Settings): """Settings for dev environment. - Uses config.yaml as config file. + Uses argos-config.yaml as config file. Uses a SQLite database.""" app_env: str = "dev" - yaml_file: str = "config.yaml" db_pool_size: Optional[int] = None db_max_overflow: Optional[int] = None database_url: str = "sqlite:////tmp/argos.db" diff --git a/docs/checks.md b/docs/checks.md index 0f96724..fcc4d2c 100644 --- a/docs/checks.md +++ b/docs/checks.md @@ -13,7 +13,7 @@ These checks are the most basic ones. They simply check that the response from t ```{code-block} yaml --- -caption: config.yaml +caption: argos-config.yaml --- - domain: "https://example.org" paths: @@ -30,7 +30,7 @@ caption: config.yaml ```{code-block} yaml --- -caption: config.yaml +caption: argos-config.yaml --- ssl: thresholds: @@ -42,4 +42,4 @@ ssl: - path: "/" checks: - ssl-certificate-expiration: "on-check" -``` \ No newline at end of file +``` diff --git a/docs/cli.md b/docs/cli.md index 81a18a0..8eff139 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -107,7 +107,9 @@ Options: --host TEXT Host to bind --port INTEGER Port to bind --config TEXT Path of the configuration file. If ARGOS_YAML_FILE environment - variable is set, its value will be used instead. + variable is set, its value will be used instead. Default + value: argos-config.yaml and /etc/argos/config.yaml as + fallback. --reload Enable hot reloading --help Show this message and exit. ``` @@ -129,7 +131,8 @@ Usage: argos server migrate [OPTIONS] Options: --config TEXT Path of the configuration file. If ARGOS_YAML_FILE environment - variable is set, its value will be used instead. + variable is set, its value will be used instead. Default value: + argos-config.yaml and /etc/argos/config.yaml as fallback. --help Show this message and exit. ``` @@ -158,7 +161,8 @@ Options: checks have a timeout value of 60 seconds) --config TEXT Path of the configuration file. If ARGOS_YAML_FILE environment variable is set, its value will be - used instead. + used instead. Default value: argos-config.yaml and + /etc/argos/config.yaml as fallback. --help Show this message and exit. ``` @@ -208,7 +212,8 @@ Usage: argos server reload-config [OPTIONS] Options: --config TEXT Path of the configuration file. If ARGOS_YAML_FILE environment - variable is set, its value will be used instead. + variable is set, its value will be used instead. Default value: + argos-config.yaml and /etc/argos/config.yaml as fallback. --help Show this message and exit. ``` diff --git a/docs/configuration.md b/docs/configuration.md index 38aeef4..8d93f1a 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -21,6 +21,8 @@ Here are the environment variables you can define to configure how the service w The path to the yaml configuration file, defining the checks. +If you do not provide the environment variable, Argos will try to read `argos-config.yaml` in the current directory, then `/etc/config/argos.yaml`. + #### ARGOS_DATABASE_URL The database url, as defined [in SQLAlchemy docs](https://docs.sqlalchemy.org/en/20/core/engines.html#database-urls). @@ -28,7 +30,7 @@ The database url, as defined [in SQLAlchemy docs](https://docs.sqlalchemy.org/en For instance, to connect to a postgres database on localhost with user, pass and dbname "argos": ``` -ARGOS_DATABASE_URL = "postgresql://argos:argos@localhost/argos" +ARGOS_DATABASE_URL="postgresql://argos:argos@localhost/argos" ``` #### DB_POOL_SIZE @@ -37,8 +39,8 @@ ARGOS_DATABASE_URL = "postgresql://argos:argos@localhost/argos" You configure the size of the database pool of connection, and the max overflow (until when new connections are accepted ?) These are documented [in the SQLAlchemy docs in greater details](https://docs.sqlalchemy.org/en/20/core/pooling.html#sqlalchemy.pool.QueuePool.params.pool_size) ```bash -DB_POOL_SIZE = 10 -DB_MAX_OVERFLOW = 20 +DB_POOL_SIZE=10 +DB_MAX_OVERFLOW=20 ``` ## Argos "checks" configuration @@ -50,7 +52,7 @@ Here is a simple configuration file: ```{literalinclude} ../conf/config-example.yaml --- -caption: config.yaml +caption: argos-config.yaml --- -``` \ No newline at end of file +``` diff --git a/docs/installation/getting-started.md b/docs/installation/getting-started.md index 17e4e3d..6e498e6 100644 --- a/docs/installation/getting-started.md +++ b/docs/installation/getting-started.md @@ -42,7 +42,7 @@ pip install -e . The quickest way to get started is to generate the configuration file from argos and edit it: ```bash -argos server generate-config > config.yaml +argos server generate-config > argos-config.yaml ``` You can read more about the configuration in the [configuration section](../configuration.md).