e11sync-gunicorn is a bit easier to use
This commit is contained in:
parent
4555d5f1f9
commit
96181f5075
|
@ -1,13 +1,29 @@
|
|||
from pathlib import Path
|
||||
from os import environ
|
||||
from os import environ, path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
_DEBUG = bool(environ.get('E11SYNC_DEBUG', False))
|
||||
_COMPRESS_OFFLINE = bool(environ.get('E11SYNC_COMPRESS_OFFLINE', False))
|
||||
_STATIC_ROOT = environ.get('E11SYNC_STATIC_ROOT', '/tmp/e11sync-static')
|
||||
_GEOIP_PATH = environ.get('GEOIP_PATH')
|
||||
if db := environ.get('E11SYNC_DATABASE_PATH'):
|
||||
_DATABASE_PATH = db
|
||||
else:
|
||||
if statedir := environ.get('STATE_DIRECTORY'):
|
||||
_DATABASE_PATH = path.join(statedir, 'db.sqlite3')
|
||||
else:
|
||||
_DATABASE_PATH = BASE_DIR / 'db.sqlite3'
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
# otherwise it gets printed twice
|
||||
if not environ.get("E11SYNC_DEBUG_PRINTED"):
|
||||
print("DEBUG={}".format(_DEBUG))
|
||||
print("COMPRESS_OFFLINE={}".format(_COMPRESS_OFFLINE))
|
||||
print("STATIC_ROOT={}".format(_STATIC_ROOT))
|
||||
print("GEOIP_PATH={}".format(_GEOIP_PATH))
|
||||
print("DATABASE_PATH={}".format(_DATABASE_PATH))
|
||||
environ["E11SYNC_DEBUG_PRINTED"] = "1"
|
||||
|
||||
########################################
|
||||
## No more side effects after this place
|
||||
|
@ -67,7 +83,7 @@ WSGI_APPLICATION = 'e11sync.wsgi.application'
|
|||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
'NAME': _DATABASE_PATH,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
18
flake.nix
18
flake.nix
|
@ -68,8 +68,8 @@
|
|||
'';
|
||||
installPhase = ''mv static $out'';
|
||||
};
|
||||
packages.e11sync-gunicorn = pkgs.stdenv.mkDerivation {
|
||||
name = "e11sync-gunicorn";
|
||||
packages.e11sync = pkgs.stdenv.mkDerivation {
|
||||
name = "e11sync";
|
||||
propagatedBuildInputs = [runtimeDeps];
|
||||
nativeBuildInputs = [pkgs.makeWrapper];
|
||||
src = self;
|
||||
|
@ -77,7 +77,7 @@
|
|||
buildPhase = ''
|
||||
mkdir -p $out;
|
||||
cp -r ${self}/app $out
|
||||
makeWrapper ${pkgs.python3Packages.gunicorn}/bin/gunicorn $out/bin/entrypoint \
|
||||
makeWrapper ${pkgs.python3Packages.gunicorn}/bin/gunicorn $out/bin/e11sync-gunicorn \
|
||||
--chdir $out/app \
|
||||
--set-default E11SYNC_HTTP_PORT ${toString gunicornPort} \
|
||||
--set E11SYNC_DEBUG "" \
|
||||
|
@ -85,6 +85,9 @@
|
|||
--set GEOIP_PATH "${geoip}" \
|
||||
--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}"
|
||||
'';
|
||||
passthru.tests = {
|
||||
simple =
|
||||
|
@ -100,12 +103,17 @@
|
|||
};
|
||||
};
|
||||
|
||||
checks.e11sync = packages.e11sync-gunicorn.passthru.tests.simple;
|
||||
checks.e11sync = packages.e11sync.passthru.tests.simple;
|
||||
|
||||
apps.e11sync-gunicorn = {
|
||||
type = "app";
|
||||
name = "e11sync-gunicorn";
|
||||
program = "${packages.e11sync-gunicorn}/bin/entrypoint";
|
||||
program = let
|
||||
wrapper = pkgs.writeShellScript "wrapper" ''
|
||||
export E11SYNC_DATABASE_PATH=$PWD/db.sqlite3
|
||||
exec ${packages.e11sync}/bin/e11sync-gunicorn
|
||||
'';
|
||||
in "${wrapper}";
|
||||
};
|
||||
|
||||
devShells.default = pkgs.mkShellNoCC {
|
||||
|
|
Loading…
Reference in New Issue