Skip to content

Commit

Permalink
Dokku app names are cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
odscjames committed Mar 17, 2023
1 parent 03deada commit 848af62
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- nginx / client_max_body_size option - set by command line option or environmental variable.
- nginx / proxy-read-timeout option - set by command line option or environmental variable.
- Dokku app names are cleaned up. Invalid characters are changed to "-". Lower case is enforced.

## Changed

Expand Down
14 changes: 14 additions & 0 deletions docs/reference/dokku-app-names.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Dokku App Names
===============

Any app names that are not allowed in Dokku will be cleaned up automatically.

Names will be made lower case.

Characters that are not allowed will be changed to a dash (`-`). This includes:

* slashes
* underscores
* colons
* spaces

3 changes: 2 additions & 1 deletion docs/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Reference

deploy-command.rst
destroy-command.rst
app-resources.rst
app-resources.rst
dokku-app-names.rst
11 changes: 10 additions & 1 deletion dokkusd/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ def get_remote_names_configured(git_remote_verbose_output):
return out


def clean_dokku_app_name(app_name: str) -> str:
app_name = app_name.replace(" ", "-")
app_name = app_name.replace("_", "-")
app_name = app_name.replace(":", "-")
app_name = app_name.replace("/", "-")
app_name = app_name.replace("\\", "-")
return app_name.lower()


class Task:
def __init__(
self,
Expand All @@ -31,7 +40,7 @@ def __init__(
self.remote_user = remote_user
self.remote_host = remote_host
self.remote_port = remote_port
self.app_name = app_name
self.app_name = clean_dokku_app_name(app_name)

def _dokku_command(self, command):
full_command = [
Expand Down
29 changes: 29 additions & 0 deletions test/test_clean_dokku_app_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from dokkusd.util import clean_dokku_app_name


def test_fine_1():
assert "cat" == clean_dokku_app_name("cat")


def test_bad_1():
assert "cat-" == clean_dokku_app_name("cat_")


def test_bad_2():
assert "cat-" == clean_dokku_app_name("cat:")


def test_bad_3():
assert "cat-" == clean_dokku_app_name("cat/")


def test_bad_4():
assert "cat-" == clean_dokku_app_name("cat\\")


def test_bad_5():
assert "cat" == clean_dokku_app_name("CAT")


def test_bad_6():
assert "cat-" == clean_dokku_app_name("cat ")

0 comments on commit 848af62

Please sign in to comment.