replace gunicorn with uwsgi
has an easier-to-work-with prometheus.
This commit is contained in:
parent
b983a2f59a
commit
50c34aa922
12
Makefile
12
Makefile
|
@ -11,10 +11,10 @@ format:
|
|||
run:
|
||||
app/manage.py runserver
|
||||
|
||||
.PHONY: run-gunicorn
|
||||
run-gunicorn:
|
||||
nix run .#e11sync-gunicorn
|
||||
.PHONY: run-backend
|
||||
run-backend:
|
||||
nix run .#e11sync-backend
|
||||
|
||||
.PHONY: run-caddy
|
||||
run-caddy:
|
||||
nix run .#e11sync-caddy
|
||||
.PHONY: run-frontend
|
||||
run-frontend:
|
||||
nix run .#e11sync-frontend
|
||||
|
|
23
flake.nix
23
flake.nix
|
@ -44,16 +44,19 @@
|
|||
|
||||
e11sync-static = pkgs.callPackage ./pkgs/e11sync-static.nix {};
|
||||
|
||||
e11sync-caddy = pkgs.callPackage ./pkgs/e11sync-caddy.nix {
|
||||
e11sync-frontend = pkgs.callPackage ./pkgs/e11sync-frontend.nix {
|
||||
inherit e11sync-static;
|
||||
};
|
||||
|
||||
e11sync = pkgs.callPackage ./pkgs/e11sync.nix {inherit geoip-mmdb;};
|
||||
e11sync = pkgs.callPackage ./pkgs/e11sync.nix {
|
||||
inherit geoip-mmdb;
|
||||
uwsgi = pkgs.uwsgi.override {plugins = ["python3"];};
|
||||
};
|
||||
in {
|
||||
packages = {
|
||||
inherit geoip-mmdb;
|
||||
inherit e11sync-static;
|
||||
inherit e11sync-caddy;
|
||||
inherit e11sync-frontend;
|
||||
inherit e11sync;
|
||||
};
|
||||
|
||||
|
@ -85,18 +88,18 @@
|
|||
exec ${e11sync}/bin/e11sync
|
||||
'');
|
||||
};
|
||||
# wsgi/gunicorn
|
||||
e11sync-gunicorn = {
|
||||
# uwsgi
|
||||
e11sync-backend = {
|
||||
type = "app";
|
||||
name = "e11sync-gunicorn";
|
||||
name = "e11sync-backend";
|
||||
program = toString (pkgs.writeShellScript "wrapper" ''
|
||||
export E11SYNC_DATABASE_PATH=$PWD/db.sqlite3
|
||||
exec ${e11sync}/bin/e11sync-gunicorn
|
||||
exec ${e11sync}/bin/e11sync-backend
|
||||
'');
|
||||
};
|
||||
e11sync-caddy = {
|
||||
e11sync-frontend = {
|
||||
type = "app";
|
||||
name = "e11sync-caddy";
|
||||
name = "e11sync-frontend";
|
||||
program = let
|
||||
caddyFile = pkgs.writeTextFile {
|
||||
name = "Caddyfile";
|
||||
|
@ -108,7 +111,7 @@
|
|||
}
|
||||
:8001
|
||||
|
||||
${builtins.readFile "${e11sync-caddy}"}
|
||||
${builtins.readFile "${e11sync-frontend}"}
|
||||
'';
|
||||
};
|
||||
in
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
writeTextFile,
|
||||
e11sync-static,
|
||||
gunicornPort ? 8002,
|
||||
backendPort ? 8002,
|
||||
}:
|
||||
writeTextFile {
|
||||
name = "e11sync-caddy";
|
||||
name = "e11sync-frontend";
|
||||
text = ''
|
||||
header Strict-Transport-Security "max-age=31536000"
|
||||
header /static/CACHE/* Cache-Control "public, max-age=31536000, immutable"
|
||||
|
@ -17,6 +17,6 @@ writeTextFile {
|
|||
}
|
||||
}
|
||||
|
||||
reverse_proxy http://127.0.0.1:${toString gunicornPort}
|
||||
reverse_proxy http://127.0.0.1:${toString backendPort}
|
||||
'';
|
||||
}
|
|
@ -6,7 +6,8 @@
|
|||
python3Packages,
|
||||
libmaxminddb,
|
||||
dart-sass,
|
||||
gunicornPort ? 8002,
|
||||
uwsgi,
|
||||
backendPort ? 8002,
|
||||
database-path ? null,
|
||||
geoip-mmdb,
|
||||
}:
|
||||
|
@ -24,20 +25,22 @@ stdenv.mkDerivation {
|
|||
buildPhase = ''mkdir -p $out'';
|
||||
installPhase = ''
|
||||
cp -r . $out/app
|
||||
makeWrapper ${python3Packages.gunicorn}/bin/gunicorn $out/bin/e11sync-gunicorn \
|
||||
makeWrapper $out/app/manage.py $out/bin/e11sync \
|
||||
--set GEOIP_PATH "${geoip-mmdb}"
|
||||
|
||||
makeWrapper ${uwsgi}/bin/uwsgi $out/bin/e11sync-backend \
|
||||
--chdir $out/app \
|
||||
--set-default E11SYNC_HTTP_PORT ${toString gunicornPort} \
|
||||
--set-default E11SYNC_HTTP_PORT ${toString backendPort} \
|
||||
--add-flags "--plugin ${uwsgi}/lib/uwsgi/python3_plugin.so" \
|
||||
--add-flags "--http-socket 127.0.0.1:${toString backendPort}" \
|
||||
--add-flags "--wsgi-file e11sync/wsgi.py" \
|
||||
--add-flags --master \
|
||||
${lib.optionalString (database-path != null) ''
|
||||
--set E11SYNC_DATABASE_PATH "${database-path}" \
|
||||
''} \
|
||||
--set E11SYNC_DEBUG "" \
|
||||
--set E11SYNC_COMPRESS_OFFLINE 1 \
|
||||
--set GEOIP_PATH "${geoip-mmdb}" \
|
||||
--add-flags --bind=127.0.0.1:\$E11SYNC_HTTP_PORT \
|
||||
--add-flags e11sync.wsgi
|
||||
|
||||
makeWrapper $out/app/manage.py $out/bin/e11sync \
|
||||
--set GEOIP_PATH "${geoip-mmdb}"
|
||||
'';
|
||||
passthru.tests.unit =
|
||||
runCommand "e11sync-test" {
|
||||
|
|
Loading…
Reference in New Issue