From 13dc34391f6129f2d54fac9b77639d951e59b340 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 5 Oct 2022 16:30:50 +0100 Subject: [PATCH] environment_variables: Can set via command line --- docs/reference/app-resources.rst | 4 ++++ docs/reference/deploy-command.rst | 13 +++++++++++++ dokkusd/cli.py | 6 ++++++ dokkusd/deploy.py | 8 ++++++++ 4 files changed, 31 insertions(+) diff --git a/docs/reference/app-resources.rst b/docs/reference/app-resources.rst index 01181ae..ddca9a7 100644 --- a/docs/reference/app-resources.rst +++ b/docs/reference/app-resources.rst @@ -59,6 +59,8 @@ Currently each type can only be attached once. Environment Variables --------------------- +You can set these via `app.json`: + .. code-block:: json { @@ -70,6 +72,8 @@ Environment Variables } } +You can also set these on the command line - see the deploy call. + HTTP Auth with user and password -------------------------------- diff --git a/docs/reference/deploy-command.rst b/docs/reference/deploy-command.rst index 5063730..7da2f99 100644 --- a/docs/reference/deploy-command.rst +++ b/docs/reference/deploy-command.rst @@ -55,3 +55,16 @@ Optional, but both user and password are required if used. Pass the user by `--httpauthuser` or set the `DOKKUSD_HTTP_AUTH_USER` environmental variable. Pass the password by `--httpauthpassword` or set the `DOKKUSD_HTTP_AUTH_PASSWORD` environmental variable. + +Environment Variables +~~~~~~~~~~~~~~~~~~~~~ + +Optional. + +Pass a JSON block by `--environmentvariablesjson` or set the `DOKKUSD_ENVIRONMENT_VARIABLES_JSON` environmental variable. + +Be careful to escape any fields: + +.. code-block:: bash + + DOKKUSD_ENVIRONMENT_VARIABLES_JSON={\"ENV\":\"dev\",\"DATABASE\":\"dev\"} python -m dokkusd.cli deploy diff --git a/dokkusd/cli.py b/dokkusd/cli.py index f48551b..24e1ba2 100644 --- a/dokkusd/cli.py +++ b/dokkusd/cli.py @@ -43,6 +43,11 @@ def main() -> None: help="HTTP Auth Password", default=os.getenv("DOKKUSD_HTTP_AUTH_PASSWORD"), ) + deploy_parser.add_argument( + "--environmentvariablesjson", + help="Environment Variables in JSON dictionary", + default=os.getenv("DOKKUSD_ENVIRONMENT_VARIABLES_JSON"), + ) ### Destroy destroy_parser = subparsers.add_parser("destroy") @@ -87,6 +92,7 @@ def main() -> None: app_name=args.appname, http_auth_user=args.httpauthuser, http_auth_password=args.httpauthpassword, + environment_variables_json_string=args.environmentvariablesjson, ) deploy.go() diff --git a/dokkusd/deploy.py b/dokkusd/deploy.py index 7138a8e..dcce3f5 100644 --- a/dokkusd/deploy.py +++ b/dokkusd/deploy.py @@ -20,6 +20,7 @@ def __init__( app_name: str, http_auth_user: str = None, http_auth_password: str = None, + environment_variables_json_string: str = None, ): super().__init__( directory=directory, @@ -30,6 +31,7 @@ def __init__( ) self.http_auth_user = http_auth_user self.http_auth_password = http_auth_password + self.environment_variables_json_string = environment_variables_json_string def go(self) -> None: @@ -77,6 +79,12 @@ def go(self) -> None: # --------------------- Env Vars print("Configure Environment Variables ...") envvars = app_json.get("dokkusd", {}).get("environment_variables", {}) + if self.environment_variables_json_string: + print(self.environment_variables_json_string) + environment_variables_dict = json.loads( + self.environment_variables_json_string + ) + envvars.update(environment_variables_dict) for key, value in envvars.items(): environment_variable = EnvironmentVariableConfigModel( key, value, self.app_name