diff --git a/Dockerfile b/Dockerfile index f8044c3..7084173 100644 --- a/Dockerfile +++ b/Dockerfile @@ -62,4 +62,3 @@ ENV BUILD_DATE=${BUILD_DATE} # Run command EXPOSE 8000 ENTRYPOINT ["/home/app/spoolman/entrypoint.sh"] -CMD ["--host", "0.0.0.0", "--port", "8000"] diff --git a/README.md b/README.md index 0e76be1..22d9c52 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,8 @@ If you want to connect with an external database instead, specify the `SPOOLMAN_ | SPOOLMAN_AUTOMATIC_BACKUP | Automatic nightly DB backups for SQLite databases. Enabled by default, set to `FALSE` to disable. | | PUID | (*docker only*) Set the UID of the user in the docker container. Default is 1000. | | PGID | (*docker only*) Set the GID of the user in the docker container. Default is 1000. | +| SPOOLMAN_PORT | The port Spoolman should run on (default: 8000) | +| SPOOLMAN_HOST | The hostname/ip Spoolman should bind to (default: 0.0.0.0) | ## Frequently Asked Questions (FAQs) ### QR Code Does not work on HTTP / The page is not served over HTTPS diff --git a/entrypoint.sh b/entrypoint.sh index 237ef5b..e1f7ab9 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,6 +2,8 @@ PUID=${PUID:-1000} PGID=${PGID:-1000} +SPOOLMAN_PORT=${SPOOLMAN_PORT:-8000} +SPOOLMAN_HOST=${SPOOLMAN_HOST:-0.0.0.0} groupmod -o -g "$PGID" app usermod -o -u "$PUID" app @@ -12,4 +14,4 @@ echo User GID: $(id -g app) echo "Starting uvicorn..." # Execute the uvicorn command with any additional arguments -exec su-exec "app" uvicorn spoolman.main:app "$@" +exec su-exec "app" uvicorn spoolman.main:app --host $SPOOLMAN_HOST --port $SPOOLMAN_PORT "$@" diff --git a/tests_integration/tests/conftest.py b/tests_integration/tests/conftest.py index e8e100b..26cdbe0 100644 --- a/tests_integration/tests/conftest.py +++ b/tests_integration/tests/conftest.py @@ -13,7 +13,7 @@ import pytest TIMEOUT = 10 -URL = "http://spoolman:8000" +URL = "http://spoolman:" + os.environ.get("PORT", "8000") class DbType(StrEnum): @@ -43,7 +43,7 @@ def _wait_for_server(): # noqa: ANN202 start_time = time.time() while True: try: - response = httpx.get("http://spoolman:8000", timeout=1) + response = httpx.get(URL, timeout=1) response.raise_for_status() except httpx.HTTPError: # noqa: PERF203 if time.time() - start_time > TIMEOUT: diff --git a/tests_integration/tests/fields/test_create.py b/tests_integration/tests/fields/test_create.py index 23718be..0cd27a8 100644 --- a/tests_integration/tests/fields/test_create.py +++ b/tests_integration/tests/fields/test_create.py @@ -6,9 +6,7 @@ from datetime import datetime, timezone import httpx import pytest -from ..conftest import assert_httpx_success, assert_lists_compatible - -URL = "http://spoolman:8000" +from ..conftest import URL, assert_httpx_success, assert_lists_compatible def test_add_text_field(): diff --git a/tests_integration/tests/fields/test_delete.py b/tests_integration/tests/fields/test_delete.py index 3c540a5..d232cd7 100644 --- a/tests_integration/tests/fields/test_delete.py +++ b/tests_integration/tests/fields/test_delete.py @@ -4,9 +4,7 @@ import json import httpx -from ..conftest import assert_httpx_success - -URL = "http://spoolman:8000" +from ..conftest import URL, assert_httpx_success def test_delete_field(): diff --git a/tests_integration/tests/fields/test_get.py b/tests_integration/tests/fields/test_get.py index 26da655..7cf09a3 100644 --- a/tests_integration/tests/fields/test_get.py +++ b/tests_integration/tests/fields/test_get.py @@ -4,9 +4,7 @@ import json import httpx -from ..conftest import assert_httpx_success, assert_lists_compatible - -URL = "http://spoolman:8000" +from ..conftest import URL, assert_httpx_success, assert_lists_compatible def test_get_field(): diff --git a/tests_integration/tests/fields/test_utilize.py b/tests_integration/tests/fields/test_utilize.py index f7a370c..43124b4 100644 --- a/tests_integration/tests/fields/test_utilize.py +++ b/tests_integration/tests/fields/test_utilize.py @@ -4,9 +4,7 @@ import json import httpx -from ..conftest import assert_httpx_success - -URL = "http://spoolman:8000" +from ..conftest import URL, assert_httpx_success def test_add_vendor_with_extra_field(): diff --git a/tests_integration/tests/filament/test_add.py b/tests_integration/tests/filament/test_add.py index d5d1213..991f9a2 100644 --- a/tests_integration/tests/filament/test_add.py +++ b/tests_integration/tests/filament/test_add.py @@ -5,9 +5,7 @@ from typing import Any import httpx -from ..conftest import assert_dicts_compatible - -URL = "http://spoolman:8000" +from ..conftest import URL, assert_dicts_compatible def test_add_filament(random_vendor: dict[str, Any]): diff --git a/tests_integration/tests/filament/test_delete.py b/tests_integration/tests/filament/test_delete.py index ec9a275..ef77fd4 100644 --- a/tests_integration/tests/filament/test_delete.py +++ b/tests_integration/tests/filament/test_delete.py @@ -4,7 +4,7 @@ from typing import Any import httpx -URL = "http://spoolman:8000" +from ..conftest import URL def test_delete_filament(random_vendor: dict[str, Any]): diff --git a/tests_integration/tests/filament/test_find.py b/tests_integration/tests/filament/test_find.py index a1083ea..e864729 100644 --- a/tests_integration/tests/filament/test_find.py +++ b/tests_integration/tests/filament/test_find.py @@ -7,9 +7,7 @@ from typing import Any import httpx import pytest -from ..conftest import assert_lists_compatible - -URL = "http://spoolman:8000" +from ..conftest import URL, assert_lists_compatible @dataclass diff --git a/tests_integration/tests/filament/test_get.py b/tests_integration/tests/filament/test_get.py index c2c8261..63d5961 100644 --- a/tests_integration/tests/filament/test_get.py +++ b/tests_integration/tests/filament/test_get.py @@ -4,9 +4,7 @@ from typing import Any import httpx -from ..conftest import assert_dicts_compatible - -URL = "http://spoolman:8000" +from ..conftest import URL, assert_dicts_compatible def test_get_filament(random_vendor: dict[str, Any]): diff --git a/tests_integration/tests/filament/test_update.py b/tests_integration/tests/filament/test_update.py index af15bbb..90b2739 100644 --- a/tests_integration/tests/filament/test_update.py +++ b/tests_integration/tests/filament/test_update.py @@ -4,9 +4,7 @@ from typing import Any import httpx -from ..conftest import assert_dicts_compatible - -URL = "http://spoolman:8000" +from ..conftest import URL, assert_dicts_compatible def test_update_filament(random_vendor: dict[str, Any]): diff --git a/tests_integration/tests/setting/test_get.py b/tests_integration/tests/setting/test_get.py index 36c5b05..2e59f96 100644 --- a/tests_integration/tests/setting/test_get.py +++ b/tests_integration/tests/setting/test_get.py @@ -2,7 +2,7 @@ import httpx -URL = "http://spoolman:8000" +from ..conftest import URL def test_get_currency(): diff --git a/tests_integration/tests/setting/test_set.py b/tests_integration/tests/setting/test_set.py index 8cb1cd1..5d97acf 100644 --- a/tests_integration/tests/setting/test_set.py +++ b/tests_integration/tests/setting/test_set.py @@ -4,7 +4,7 @@ import json import httpx -URL = "http://spoolman:8000" +from ..conftest import URL def test_set_currency(): diff --git a/tests_integration/tests/spool/test_add.py b/tests_integration/tests/spool/test_add.py index edd81de..d87fe5d 100644 --- a/tests_integration/tests/spool/test_add.py +++ b/tests_integration/tests/spool/test_add.py @@ -6,9 +6,7 @@ from typing import Any import httpx import pytest -from ..conftest import assert_dicts_compatible, length_from_weight - -URL = "http://spoolman:8000" +from ..conftest import URL, assert_dicts_compatible, length_from_weight def test_add_spool_remaining_weight(random_filament: dict[str, Any]): diff --git a/tests_integration/tests/spool/test_delete.py b/tests_integration/tests/spool/test_delete.py index 56b7b04..d60e413 100644 --- a/tests_integration/tests/spool/test_delete.py +++ b/tests_integration/tests/spool/test_delete.py @@ -4,7 +4,7 @@ from typing import Any import httpx -URL = "http://spoolman:8000" +from ..conftest import URL def test_delete_spool(random_filament: dict[str, Any]): diff --git a/tests_integration/tests/spool/test_find.py b/tests_integration/tests/spool/test_find.py index 0ba8b50..22d0be7 100644 --- a/tests_integration/tests/spool/test_find.py +++ b/tests_integration/tests/spool/test_find.py @@ -7,9 +7,7 @@ from typing import Any import httpx import pytest -from ..conftest import assert_lists_compatible - -URL = "http://spoolman:8000" +from ..conftest import URL, assert_lists_compatible @dataclass diff --git a/tests_integration/tests/spool/test_get.py b/tests_integration/tests/spool/test_get.py index fa4e0f4..6a823be 100644 --- a/tests_integration/tests/spool/test_get.py +++ b/tests_integration/tests/spool/test_get.py @@ -4,7 +4,7 @@ from typing import Any import httpx -URL = "http://spoolman:8000" +from ..conftest import URL def test_get_spool(random_filament: dict[str, Any]): diff --git a/tests_integration/tests/spool/test_update.py b/tests_integration/tests/spool/test_update.py index ffcaac1..33577e9 100644 --- a/tests_integration/tests/spool/test_update.py +++ b/tests_integration/tests/spool/test_update.py @@ -5,9 +5,7 @@ from typing import Any import httpx import pytest -from ..conftest import length_from_weight - -URL = "http://spoolman:8000" +from ..conftest import URL, length_from_weight def test_update_spool(random_filament: dict[str, Any]): diff --git a/tests_integration/tests/spool/test_use.py b/tests_integration/tests/spool/test_use.py index 103d0e2..6c07116 100644 --- a/tests_integration/tests/spool/test_use.py +++ b/tests_integration/tests/spool/test_use.py @@ -8,7 +8,7 @@ from typing import Any import httpx import pytest -URL = "http://spoolman:8000" +from ..conftest import URL @pytest.mark.parametrize("use_weight", [0, 0.05, -0.05, 1500]) # 1500 is big enough to use all filament diff --git a/tests_integration/tests/test_backup.py b/tests_integration/tests/test_backup.py index 7714697..76624a3 100644 --- a/tests_integration/tests/test_backup.py +++ b/tests_integration/tests/test_backup.py @@ -2,9 +2,7 @@ import httpx -from .conftest import DbType, get_db_type - -URL = "http://spoolman:8000" +from .conftest import URL, DbType, get_db_type def test_backup(): diff --git a/tests_integration/tests/vendor/test_add.py b/tests_integration/tests/vendor/test_add.py index aceff76..22cbd8b 100644 --- a/tests_integration/tests/vendor/test_add.py +++ b/tests_integration/tests/vendor/test_add.py @@ -4,9 +4,7 @@ from datetime import datetime, timezone import httpx -from ..conftest import assert_dicts_compatible - -URL = "http://spoolman:8000" +from ..conftest import URL, assert_dicts_compatible def test_add_vendor(): diff --git a/tests_integration/tests/vendor/test_delete.py b/tests_integration/tests/vendor/test_delete.py index f9d932b..03c5a29 100644 --- a/tests_integration/tests/vendor/test_delete.py +++ b/tests_integration/tests/vendor/test_delete.py @@ -2,7 +2,7 @@ import httpx -URL = "http://spoolman:8000" +from ..conftest import URL def test_delete_vendor(): diff --git a/tests_integration/tests/vendor/test_find.py b/tests_integration/tests/vendor/test_find.py index f9e8cad..2584224 100644 --- a/tests_integration/tests/vendor/test_find.py +++ b/tests_integration/tests/vendor/test_find.py @@ -7,9 +7,7 @@ from typing import Any import httpx import pytest -from ..conftest import assert_lists_compatible - -URL = "http://spoolman:8000" +from ..conftest import URL, assert_lists_compatible @dataclass diff --git a/tests_integration/tests/vendor/test_get.py b/tests_integration/tests/vendor/test_get.py index eeab3f3..4983e9f 100644 --- a/tests_integration/tests/vendor/test_get.py +++ b/tests_integration/tests/vendor/test_get.py @@ -2,7 +2,7 @@ import httpx -URL = "http://spoolman:8000" +from ..conftest import URL def test_get_vendor(): diff --git a/tests_integration/tests/vendor/test_update.py b/tests_integration/tests/vendor/test_update.py index dce3e74..b65dca1 100644 --- a/tests_integration/tests/vendor/test_update.py +++ b/tests_integration/tests/vendor/test_update.py @@ -2,7 +2,7 @@ import httpx -URL = "http://spoolman:8000" +from ..conftest import URL def test_update_vendor():