Skip to content

Commit

Permalink
environment_variables: Can set via command line
Browse files Browse the repository at this point in the history
  • Loading branch information
odscjames committed Oct 5, 2022
1 parent c9cc612 commit 13dc343
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/reference/app-resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Currently each type can only be attached once.
Environment Variables
---------------------

You can set these via `app.json`:

.. code-block:: json
{
Expand All @@ -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
--------------------------------
Expand Down
13 changes: 13 additions & 0 deletions docs/reference/deploy-command.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions dokkusd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()

Expand Down
8 changes: 8 additions & 0 deletions dokkusd/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 13dc343

Please sign in to comment.