From af7647dd955ee21a5580954a953eaa0f0c3ef404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Sat, 13 Jan 2024 17:40:12 +0200 Subject: [PATCH] move to gunicorn I didn't manage to get the uwsgi python plugin to work. It complained about unrecognized argument `--module`. --- app/e11sync/settings.py | 2 +- flake.nix | 28 ++++++++++------------------ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/app/e11sync/settings.py b/app/e11sync/settings.py index 0ad27fd..2157271 100644 --- a/app/e11sync/settings.py +++ b/app/e11sync/settings.py @@ -16,7 +16,7 @@ SECRET_KEY = 'django-insecure-$e2!=equ(efm0e%f9&t+xjtz0)$*$@pw%rnjdqcl8f@5o5hw!l DEBUG = _DEBUG -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ["127.0.0.1"] INTERNAL_IPS = ["127.0.0.1"] diff --git a/flake.nix b/flake.nix index a801eb5..74e9668 100644 --- a/flake.nix +++ b/flake.nix @@ -31,12 +31,7 @@ }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs {inherit system;}; - uwsgiPort = 8001; - - uwsgi = pkgs.uwsgi.override { - plugins = ["python3"]; - python3 = pkgs.python3; - }; + gunicornPort = 8001; appDeps = with pkgs; [ python3Packages.django_5 @@ -80,8 +75,8 @@ "${pkgs.zopfli}/bin/zopfli {} && ${pkgs.brotli}/bin/brotli {}" ''; }; - packages.e11sync-uwsgi = pkgs.stdenv.mkDerivation { - name = "e11sync-uwsgi"; + packages.e11sync-gunicorn = pkgs.stdenv.mkDerivation { + name = "e11sync-gunicorn"; propagatedBuildInputs = [runtimeDeps]; nativeBuildInputs = [pkgs.makeWrapper]; src = self; @@ -89,16 +84,13 @@ buildPhase = '' mkdir -p $out; cp -r ${self}/app $out - makeWrapper ${uwsgi}/bin/uwsgi $out/bin/entrypoint-uwsgi \ - --add-flags '\ - --chdir='"$out"'/app \ - --module=e11sync.wsgi:application \ - --master \ - --http-socket=127.0.0.1:${toString uwsgiPort} \ - --processes=5 \ - --harakiri=20 \ - --max-requests=10000 \ - --vacuum' + makeWrapper ${pkgs.python3Packages.gunicorn}/bin/gunicorn $out/bin/entrypoint \ + --chdir $out/app \ + --set E11SYNC_DEBUG "" \ + --set E11SYNC_COMPRESS_OFFLINE 1 \ + --set GEOIP_PATH "${geoip}" \ + --add-flags e11sync.wsgi \ + --add-flags --bind=127.0.0.1:${toString gunicornPort} ''; };