From c501007196931444efaaa6a492d0c8ea8977b684 Mon Sep 17 00:00:00 2001 From: James B Date: Fri, 17 Mar 2023 12:17:41 +0000 Subject: [PATCH] nginx / client_max_body_size option - command line option or env var, not app.json https://github.com/OpenDataServices/dokkusd-client/issues/9 https://github.com/OpenDataServices/dokkusd-client/issues/8 --- CHANGELOG.md | 9 +++++++ docs/reference/app-resources.rst | 25 ------------------ docs/reference/deploy-command.rst | 9 +++++++ dokkusd/cli.py | 6 +++++ dokkusd/deploy.py | 43 ++++++++++++++++++++----------- 5 files changed, 52 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9f337a..fa57aab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## Added + +- nginx / client_max_body_size option - set by command line option or environmental variable. + +## Changed + +- nginx / client_max_body_size option - setting this by app.json is deprecated and will be removed in a later version. + + ## Fixed - When creating new git remote name, check it does not already exist. If it does, add random numbers to name. diff --git a/docs/reference/app-resources.rst b/docs/reference/app-resources.rst index 0e2ab96..806d6d5 100644 --- a/docs/reference/app-resources.rst +++ b/docs/reference/app-resources.rst @@ -95,28 +95,3 @@ HTTP Auth with user and password -------------------------------- Currently this can only be set on the command line - see the deploy call. - -Nginx ------ - -https://dokku.com/docs/networking/proxies/nginx/#specifying-a-custom-client_max_body_size - -You can set a value with: - -.. code-block:: json - - "dokkusd": { - "nginx": { - "client_max_body_size": "50m" - } - } - -You can clear a value and use the default with: - -.. code-block:: json - - "dokkusd": { - "nginx": { - "client_max_body_size": "50m" - } - } diff --git a/docs/reference/deploy-command.rst b/docs/reference/deploy-command.rst index 75f2b11..505b917 100644 --- a/docs/reference/deploy-command.rst +++ b/docs/reference/deploy-command.rst @@ -79,3 +79,12 @@ Be careful to escape any fields: .. code-block:: bash DOKKUSD_ENVIRONMENT_VARIABLES_JSON={\"ENV\":\"dev\",\"DATABASE\":\"dev\"} python -m dokkusd.cli deploy + +Nginx Client Max body size +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Sets the Nginx Client Max body size. + +Pass a string to `--dokkunginxclientmaxbodysize` or set the `DOKKUSD_NGINX_CLIENT_MAX_BODY_SIZE` environmental variable. + +Should include units. eg `50m` not `50`. diff --git a/dokkusd/cli.py b/dokkusd/cli.py index 7c9b5d2..5e6f508 100644 --- a/dokkusd/cli.py +++ b/dokkusd/cli.py @@ -52,6 +52,11 @@ def main() -> None: "--environmentvariablesprefixedby", help="Any Environmental variables prefixed with this will be given to the Dokku app.", ) + deploy_parser.add_argument( + "--dokkunginxclientmaxbodysize", + help="Sets a value for Nginx Client Max Body Size. Include units eg 50m", + default=os.getenv("DOKKUSD_NGINX_CLIENT_MAX_BODY_SIZE"), + ) ### Destroy destroy_parser = subparsers.add_parser("destroy") @@ -104,6 +109,7 @@ def main() -> None: http_auth_password=args.httpauthpassword, environment_variables_json_string=args.environmentvariablesjson, environment_variables=env_vars, + dokku_nginx_client_max_body_size=args.dokkunginxclientmaxbodysize, ) deploy.go() diff --git a/dokkusd/deploy.py b/dokkusd/deploy.py index c947a5e..4661d53 100644 --- a/dokkusd/deploy.py +++ b/dokkusd/deploy.py @@ -22,6 +22,7 @@ def __init__( http_auth_password: str = None, environment_variables_json_string: str = None, environment_variables: dict = {}, + dokku_nginx_client_max_body_size=None, ): super().__init__( directory=directory, @@ -34,6 +35,7 @@ def __init__( self.http_auth_password = http_auth_password self._environment_variables: dict = environment_variables self.environment_variables_json_string = environment_variables_json_string + self._dokku_nginx_client_max_body_size = dokku_nginx_client_max_body_size def go(self) -> None: @@ -124,21 +126,32 @@ def go(self) -> None: print(stderr) # --------------------- Nginx - if "nginx" in app_json.get("dokkusd", {}): - nginx = app_json.get("dokkusd", {}).get("nginx") - if isinstance(nginx, dict): - if "client_max_body_size" in nginx: - print("Nginx: client-max-body-size ...") - stdout, stderr = self._dokku_command( - [ - "nginx:set", - self.app_name, - "client-max-body-size", - str(nginx.get("client_max_body_size")), - ] - ) - print(stdout) - print(stderr) + # If not already passed, look for it in app.json + # This way things passed to us take priority over things set in app.json + # This way of passing the value is deprecated and undocumented. + # This code block will be removed in a later version. + if not self._dokku_nginx_client_max_body_size: + if "nginx" in app_json.get("dokkusd", {}): + nginx = app_json.get("dokkusd", {}).get("nginx") + if isinstance(nginx, dict): + if "client_max_body_size" in nginx: + self._dokku_nginx_client_max_body_size = str( + nginx.get("client_max_body_size") + ) + + # If set, process + if self._dokku_nginx_client_max_body_size: + print("Nginx: client-max-body-size ...") + stdout, stderr = self._dokku_command( + [ + "nginx:set", + self.app_name, + "client-max-body-size", + str(self._dokku_nginx_client_max_body_size), + ] + ) + print(stdout) + print(stderr) # --------------------- Deploy print("Deploy ...")