Skip to content

Commit

Permalink
nginx / client_max_body_size option - command line option or env var,…
Browse files Browse the repository at this point in the history
… not app.json

#9
#8
  • Loading branch information
odscjames committed Mar 17, 2023
1 parent eefb424 commit c501007
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 40 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 0 additions & 25 deletions docs/reference/app-resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
9 changes: 9 additions & 0 deletions docs/reference/deploy-command.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
6 changes: 6 additions & 0 deletions dokkusd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()

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

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

0 comments on commit c501007

Please sign in to comment.