Merge pull request #279 from hcooper/dynamic-port

Support dynamic ports
This commit is contained in:
Donkie
2024-02-01 18:25:04 +01:00
committed by GitHub
27 changed files with 30 additions and 55 deletions

View File

@@ -66,4 +66,3 @@ RUN echo "GIT_COMMIT=${GIT_COMMIT}" > build.txt \
# Run command # Run command
EXPOSE 8000 EXPOSE 8000
ENTRYPOINT ["/home/app/spoolman/entrypoint.sh"] ENTRYPOINT ["/home/app/spoolman/entrypoint.sh"]
CMD ["--host", "0.0.0.0", "--port", "8000"]

View File

@@ -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. | | 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. | | 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. | | 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) ## Frequently Asked Questions (FAQs)
### QR Code Does not work on HTTP / The page is not served over HTTPS ### QR Code Does not work on HTTP / The page is not served over HTTPS

View File

@@ -2,6 +2,8 @@
PUID=${PUID:-1000} PUID=${PUID:-1000}
PGID=${PGID:-1000} PGID=${PGID:-1000}
SPOOLMAN_PORT=${SPOOLMAN_PORT:-8000}
SPOOLMAN_HOST=${SPOOLMAN_HOST:-0.0.0.0}
groupmod -o -g "$PGID" app groupmod -o -g "$PGID" app
usermod -o -u "$PUID" app usermod -o -u "$PUID" app
@@ -12,4 +14,4 @@ echo User GID: $(id -g app)
echo "Starting uvicorn..." echo "Starting uvicorn..."
# Execute the uvicorn command with any additional arguments # 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 "$@"

View File

@@ -13,7 +13,7 @@ import pytest
TIMEOUT = 10 TIMEOUT = 10
URL = "http://spoolman:8000" URL = "http://spoolman:" + os.environ.get("SPOOLMAN_PORT", "8000")
class DbType(StrEnum): class DbType(StrEnum):
@@ -43,7 +43,7 @@ def _wait_for_server(): # noqa: ANN202
start_time = time.time() start_time = time.time()
while True: while True:
try: try:
response = httpx.get("http://spoolman:8000", timeout=1) response = httpx.get(URL, timeout=1)
response.raise_for_status() response.raise_for_status()
except httpx.HTTPError: # noqa: PERF203 except httpx.HTTPError: # noqa: PERF203
if time.time() - start_time > TIMEOUT: if time.time() - start_time > TIMEOUT:

View File

@@ -6,9 +6,7 @@ from datetime import datetime, timezone
import httpx import httpx
import pytest import pytest
from ..conftest import assert_httpx_success, assert_lists_compatible from ..conftest import URL, assert_httpx_success, assert_lists_compatible
URL = "http://spoolman:8000"
def test_add_text_field(): def test_add_text_field():

View File

@@ -4,9 +4,7 @@ import json
import httpx import httpx
from ..conftest import assert_httpx_success from ..conftest import URL, assert_httpx_success
URL = "http://spoolman:8000"
def test_delete_field(): def test_delete_field():

View File

@@ -4,9 +4,7 @@ import json
import httpx import httpx
from ..conftest import assert_httpx_success, assert_lists_compatible from ..conftest import URL, assert_httpx_success, assert_lists_compatible
URL = "http://spoolman:8000"
def test_get_field(): def test_get_field():

View File

@@ -4,9 +4,7 @@ import json
import httpx import httpx
from ..conftest import assert_httpx_success from ..conftest import URL, assert_httpx_success
URL = "http://spoolman:8000"
def test_add_vendor_with_extra_field(): def test_add_vendor_with_extra_field():

View File

@@ -5,9 +5,7 @@ from typing import Any
import httpx import httpx
from ..conftest import assert_dicts_compatible from ..conftest import URL, assert_dicts_compatible
URL = "http://spoolman:8000"
def test_add_filament(random_vendor: dict[str, Any]): def test_add_filament(random_vendor: dict[str, Any]):

View File

@@ -4,7 +4,7 @@ from typing import Any
import httpx import httpx
URL = "http://spoolman:8000" from ..conftest import URL
def test_delete_filament(random_vendor: dict[str, Any]): def test_delete_filament(random_vendor: dict[str, Any]):

View File

@@ -7,9 +7,7 @@ from typing import Any
import httpx import httpx
import pytest import pytest
from ..conftest import assert_lists_compatible from ..conftest import URL, assert_lists_compatible
URL = "http://spoolman:8000"
@dataclass @dataclass

View File

@@ -4,9 +4,7 @@ from typing import Any
import httpx import httpx
from ..conftest import assert_dicts_compatible from ..conftest import URL, assert_dicts_compatible
URL = "http://spoolman:8000"
def test_get_filament(random_vendor: dict[str, Any]): def test_get_filament(random_vendor: dict[str, Any]):

View File

@@ -4,9 +4,7 @@ from typing import Any
import httpx import httpx
from ..conftest import assert_dicts_compatible from ..conftest import URL, assert_dicts_compatible
URL = "http://spoolman:8000"
def test_update_filament(random_vendor: dict[str, Any]): def test_update_filament(random_vendor: dict[str, Any]):

View File

@@ -2,7 +2,7 @@
import httpx import httpx
URL = "http://spoolman:8000" from ..conftest import URL
def test_get_currency(): def test_get_currency():

View File

@@ -4,7 +4,7 @@ import json
import httpx import httpx
URL = "http://spoolman:8000" from ..conftest import URL
def test_set_currency(): def test_set_currency():

View File

@@ -6,9 +6,7 @@ from typing import Any
import httpx import httpx
import pytest import pytest
from ..conftest import assert_dicts_compatible, length_from_weight from ..conftest import URL, assert_dicts_compatible, length_from_weight
URL = "http://spoolman:8000"
def test_add_spool_remaining_weight(random_filament: dict[str, Any]): def test_add_spool_remaining_weight(random_filament: dict[str, Any]):

View File

@@ -4,7 +4,7 @@ from typing import Any
import httpx import httpx
URL = "http://spoolman:8000" from ..conftest import URL
def test_delete_spool(random_filament: dict[str, Any]): def test_delete_spool(random_filament: dict[str, Any]):

View File

@@ -7,9 +7,7 @@ from typing import Any
import httpx import httpx
import pytest import pytest
from ..conftest import assert_lists_compatible from ..conftest import URL, assert_lists_compatible
URL = "http://spoolman:8000"
@dataclass @dataclass

View File

@@ -4,7 +4,7 @@ from typing import Any
import httpx import httpx
URL = "http://spoolman:8000" from ..conftest import URL
def test_get_spool(random_filament: dict[str, Any]): def test_get_spool(random_filament: dict[str, Any]):

View File

@@ -5,9 +5,7 @@ from typing import Any
import httpx import httpx
import pytest import pytest
from ..conftest import length_from_weight from ..conftest import URL, length_from_weight
URL = "http://spoolman:8000"
def test_update_spool(random_filament: dict[str, Any]): def test_update_spool(random_filament: dict[str, Any]):

View File

@@ -8,7 +8,7 @@ from typing import Any
import httpx import httpx
import pytest 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 @pytest.mark.parametrize("use_weight", [0, 0.05, -0.05, 1500]) # 1500 is big enough to use all filament

View File

@@ -2,9 +2,7 @@
import httpx import httpx
from .conftest import DbType, get_db_type from .conftest import URL, DbType, get_db_type
URL = "http://spoolman:8000"
def test_backup(): def test_backup():

View File

@@ -4,9 +4,7 @@ from datetime import datetime, timezone
import httpx import httpx
from ..conftest import assert_dicts_compatible from ..conftest import URL, assert_dicts_compatible
URL = "http://spoolman:8000"
def test_add_vendor(): def test_add_vendor():

View File

@@ -2,7 +2,7 @@
import httpx import httpx
URL = "http://spoolman:8000" from ..conftest import URL
def test_delete_vendor(): def test_delete_vendor():

View File

@@ -7,9 +7,7 @@ from typing import Any
import httpx import httpx
import pytest import pytest
from ..conftest import assert_lists_compatible from ..conftest import URL, assert_lists_compatible
URL = "http://spoolman:8000"
@dataclass @dataclass

View File

@@ -2,7 +2,7 @@
import httpx import httpx
URL = "http://spoolman:8000" from ..conftest import URL
def test_get_vendor(): def test_get_vendor():

View File

@@ -2,7 +2,7 @@
import httpx import httpx
URL = "http://spoolman:8000" from ..conftest import URL
def test_update_vendor(): def test_update_vendor():