From d3258a7e634bca7a1820d375c282255ee07f4b87 Mon Sep 17 00:00:00 2001 From: krateng Date: Sun, 20 Feb 2022 05:06:38 +0100 Subject: [PATCH] Bugfixes and Docker dev test script --- .gitignore | 1 + Dockerfile | 1 + Dockerfile-dev | 33 +++++++++++++++++++++++++++++++++ dockertest.sh | 2 ++ maloja/database/__init__.py | 8 ++++++-- maloja/proccontrol/setup.py | 3 ++- maloja/server.py | 1 + 7 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 Dockerfile-dev create mode 100644 dockertest.sh diff --git a/.gitignore b/.gitignore index a74e6d1..79b7162 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ /*.yml /pylintrc .venv/* +/testdata # build /dist diff --git a/Dockerfile b/Dockerfile index 2c8a278..727f07a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,7 @@ RUN \ # expected behavior for a default setup is for maloja to "just work" ENV MALOJA_SKIP_SETUP=yes +ENV MALOJA_HOST=0.0.0.0 EXPOSE 42010 # use exec form for better signal handling https://docs.docker.com/engine/reference/builder/#entrypoint diff --git a/Dockerfile-dev b/Dockerfile-dev new file mode 100644 index 0000000..9d1b202 --- /dev/null +++ b/Dockerfile-dev @@ -0,0 +1,33 @@ +FROM python:3-alpine + +# Based on the work of Jonathan Boeckel +# https://gitlab.com/Joniator/docker-maloja +# https://github.com/Joniator + +WORKDIR /usr/src/app + + +# Copy project into dir +COPY ./install ./install +COPY ./requirements.txt ./requirements.txt + + + # Build dependencies (This will pipe all packages from the file) +RUN sed 's/#.*//' ./install/dependencies_build.txt | xargs apk add --no-cache --virtual .build-deps + # Runtime dependencies (Same) +RUN sed 's/#.*//' ./install/dependencies_run.txt | xargs apk add --no-cache + # Python dependencies +RUN pip3 install --no-cache-dir -r requirements.txt + # Local project install +COPY . . +RUN pip3 install /usr/src/app + # Remove build dependencies +RUN apk del .build-deps + +# expected behavior for a default setup is for maloja to "just work" +ENV MALOJA_SKIP_SETUP=yes +ENV MALOJA_HOST=0.0.0.0 + +EXPOSE 42010 +# use exec form for better signal handling https://docs.docker.com/engine/reference/builder/#entrypoint +ENTRYPOINT ["maloja", "run"] diff --git a/dockertest.sh b/dockertest.sh new file mode 100644 index 0000000..1232d79 --- /dev/null +++ b/dockertest.sh @@ -0,0 +1,2 @@ +docker build -t maloja-dev . -f Dockerfile-dev +docker run -p 42010:42010 -v $PWD/testdata:/mlj -e MALOJA_DATA_DIRECTORY=/mlj maloja-dev diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index 372f47b..753b232 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -462,8 +462,12 @@ def start_db(): dbstatus['healthy'] = True # inform time module about begin of scrobbling - firstscrobble = sqldb.get_scrobbles()[0] - register_scrobbletime(firstscrobble['time']) + try: + firstscrobble = sqldb.get_scrobbles()[0] + register_scrobbletime(firstscrobble['time']) + except IndexError: + register_scrobbletime(int(datetime.datetime.now().timestamp())) + # create cached information cached.update_medals() diff --git a/maloja/proccontrol/setup.py b/maloja/proccontrol/setup.py index 9e212e1..37bdc1d 100644 --- a/maloja/proccontrol/setup.py +++ b/maloja/proccontrol/setup.py @@ -68,11 +68,12 @@ def setup(): newpw = prompt("Please set a password for web backend access. Leave this empty to generate a random password.",skip=SKIP,secret=True) if newpw is None: newpw = randomstring(32) + newpw_repeat = newpw print("Generated password:",col["yellow"](newpw)) else: newpw_repeat = prompt("Please type again to confirm.",skip=SKIP,secret=True) if newpw != newpw_repeat: print("Passwords do not match!") - else: auth.defaultuser.setpw(newpw) + auth.defaultuser.setpw(newpw) if malojaconfig["SEND_STATS"] is None: answer = ask("I would like to know how many people use Maloja. Would it be okay to send a daily ping to my server (this contains no data that isn't accessible via your web interface already)?",default=True,skip=SKIP) diff --git a/maloja/server.py b/maloja/server.py index 86cf068..6fa4040 100644 --- a/maloja/server.py +++ b/maloja/server.py @@ -284,6 +284,7 @@ def run_server(): try: #run(webserver, host=HOST, port=MAIN_PORT, server='waitress') + log(f"Listening on {HOST}:{PORT}") waitress.serve(webserver, host=HOST, port=PORT, threads=THREADS) except OSError: log("Error. Is another Maloja process already running?")