diff --git a/Dockerfile b/Dockerfile index adbbb03..49efe66 100644 --- a/Dockerfile +++ b/Dockerfile @@ -66,6 +66,5 @@ ENV BUILD_DATE=${BUILD_DATE} # Run command EXPOSE 8000 -VOLUME ["/home/app/.local/share/spoolman"] ENTRYPOINT ["uvicorn", "spoolman.main:app"] CMD ["--host", "0.0.0.0", "--port", "8000"] diff --git a/spoolman/env.py b/spoolman/env.py index 60042f0..4cfc35f 100644 --- a/spoolman/env.py +++ b/spoolman/env.py @@ -326,3 +326,16 @@ def check_write_permissions() -> None: gid, ) sys.exit(1) + + +def is_docker() -> bool: + """Check if we are running in a docker container.""" + return Path("/.dockerenv").exists() + + +def is_data_dir_mounted() -> bool: + """Check if the data directory is mounted as a shfs.""" + # "mount" will give us a list of all mounted filesystems + mounts = subprocess.run("mount", check=True, stdout=subprocess.PIPE, text=True) # noqa: S603, S607 + data_dir = str(get_data_dir().resolve()) + return any(data_dir in line for line in mounts.stdout.splitlines()) diff --git a/spoolman/main.py b/spoolman/main.py index dc7fe12..0b4401e 100644 --- a/spoolman/main.py +++ b/spoolman/main.py @@ -95,6 +95,22 @@ async def startup() -> None: logger.info("Startup complete.") + if env.is_docker() and not env.is_data_dir_mounted(): + logger.warning("!!!! WARNING !!!!") + logger.warning("!!!! WARNING !!!!") + logger.warning("The data directory is not mounted.") + logger.warning( + 'Spoolman stores its database in the container directory "%s". ' + "If this directory isn't mounted to the host OS, the database will be lost when the container is stopped.", + env.get_data_dir(), + ) + logger.warning( + "Please carefully read the docker part of the README.md file, " + "and ensure your docker-compose file matches the example.", + ) + logger.warning("!!!! WARNING !!!!") + logger.warning("!!!! WARNING !!!!") + if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=8000)