From 07a5b7d436d9be68a3c04e3584777e8ab6eac016 Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 29 Jul 2021 23:09:30 +0200 Subject: flake: add app server package output --- .gitignore | 1 + flake.nix | 10 ++++++++++ readme.md | 14 ++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/.gitignore b/.gitignore index aa78700..304a908 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ __pycache__ development_database +result *~ *.swp *.swo diff --git a/flake.nix b/flake.nix index 4e10a12..b8616f8 100644 --- a/flake.nix +++ b/flake.nix @@ -92,6 +92,16 @@ in { + packages = { + # Minimal production server. + # This includes only application files tracked by git. + # Using `gunicorn` on top of `uvicorn` is recommended for bigger loads. + server = writeShellScript "server" '' + cd ${./.} + ${pythonWithDependencies}/bin/uvicorn --app-dir app app:main "$@" + ''; + }; + devShell = mkShell rec { buildInputs = [ pythonWithDependencies ] ++ develPackagesAndScripts; diff --git a/readme.md b/readme.md index 8e18082..569b173 100644 --- a/readme.md +++ b/readme.md @@ -342,6 +342,20 @@ This server will listen to incoming requests to a locally bound port. It will automatically reload itself when its files are edited, and display logs about type checking and runtime errors. +### Production deployment + +While the deployment phase is way out of the scope of a database introductory +course, asking students to deploy their application on the Internet could be a +motivational factor. It would also facilitate evaluating and grading projects, +avoiding deployment and testing hassles to the teaching staff. + +The Nix Flake provides a Nix package which can be used to run the web +application in a production context as a [daemon], managed by a standard [init] +system. + +[daemon]: https://en.wikipedia.org/wiki/Daemon_(computing) +[init]: https://en.wikipedia.org/wiki/Init + ## Copyright and licensing -- cgit v1.2.3