forked from DGNum/infrastructure
feat(django-apps): Finish the daphne-specific setup
This commit is contained in:
parent
03541914ae
commit
a7b34850f4
1 changed files with 30 additions and 26 deletions
|
@ -264,6 +264,7 @@ in
|
||||||
ps:
|
ps:
|
||||||
[ (config.django ps) ]
|
[ (config.django ps) ]
|
||||||
++ (optional (config.application.type != "daphne") ps.gunicorn)
|
++ (optional (config.application.type != "daphne") ps.gunicorn)
|
||||||
|
++ (optional (config.application.type == "daphne") ps.daphne)
|
||||||
++ (optional (config.application.type == "asgi") ps.uvicorn)
|
++ (optional (config.application.type == "asgi") ps.uvicorn)
|
||||||
++ (optional (config.dbType == "postgresql") ps.psycopg)
|
++ (optional (config.dbType == "postgresql") ps.psycopg)
|
||||||
++ (config.dependencies ps)
|
++ (config.dependencies ps)
|
||||||
|
@ -547,6 +548,7 @@ in
|
||||||
virtualHosts = mapAttrs' (
|
virtualHosts = mapAttrs' (
|
||||||
name:
|
name:
|
||||||
{
|
{
|
||||||
|
application,
|
||||||
domain,
|
domain,
|
||||||
nginx,
|
nginx,
|
||||||
serveMedia,
|
serveMedia,
|
||||||
|
@ -555,7 +557,11 @@ in
|
||||||
nameValuePair domain (
|
nameValuePair domain (
|
||||||
recursiveUpdate {
|
recursiveUpdate {
|
||||||
locations = {
|
locations = {
|
||||||
"/".proxyPass = "http://unix:/run/django-apps/${name}.sock";
|
"/".proxyPass =
|
||||||
|
if application.type == "daphne" then
|
||||||
|
"http://unix:/run/django-apps/${name}/socket"
|
||||||
|
else
|
||||||
|
"http://unix:/run/django-apps/${name}.sock";
|
||||||
"/static/".root = "/run/django-apps/${name}";
|
"/static/".root = "/run/django-apps/${name}";
|
||||||
"/media/".root = mkIf serveMedia "/run/django-apps/${name}";
|
"/media/".root = mkIf serveMedia "/run/django-apps/${name}";
|
||||||
};
|
};
|
||||||
|
@ -600,7 +606,7 @@ in
|
||||||
SocketUser = config'.services.nginx.user;
|
SocketUser = config'.services.nginx.user;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
) cfg.sites;
|
) (filterAttrs (_: { application, ... }: application.type != "daphne") cfg.sites);
|
||||||
|
|
||||||
mounts = concatLists (
|
mounts = concatLists (
|
||||||
mapAttrsToList (
|
mapAttrsToList (
|
||||||
|
@ -704,9 +710,15 @@ in
|
||||||
mkdir -p ${config.mediaDirectory} ${config.staticDirectory}
|
mkdir -p ${config.mediaDirectory} ${config.staticDirectory}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
requires = [ "dj-${name}.socket" ];
|
requires = optional (config.application.type != "daphne") "dj-${name}.socket";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
|
||||||
|
script = mkIf (config.application.type == "daphne") ''
|
||||||
|
cd source && ${getExe' config.djangoEnv "daphne"} \
|
||||||
|
-u /run/django-apps/${name}/socket \
|
||||||
|
${config.application.module}.asgi:application
|
||||||
|
'';
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
inherit
|
inherit
|
||||||
Group
|
Group
|
||||||
|
@ -719,16 +731,8 @@ in
|
||||||
;
|
;
|
||||||
|
|
||||||
DynamicUser = true;
|
DynamicUser = true;
|
||||||
ExecStart = escapeSystemdExecArgs (
|
ExecStart = mkIf (config.application.type != "daphne") (
|
||||||
if (config.application.type == "daphne") then
|
escapeSystemdExecArgs (
|
||||||
[
|
|
||||||
(getExe' config.djangoEnv "daphne")
|
|
||||||
"-u"
|
|
||||||
"/run/django-apps/${name}.sock"
|
|
||||||
"${config.application.module}.asgi:${config.application.channelLayer}"
|
|
||||||
]
|
|
||||||
else
|
|
||||||
(
|
|
||||||
[
|
[
|
||||||
(getExe' config.djangoEnv "gunicorn")
|
(getExe' config.djangoEnv "gunicorn")
|
||||||
"--workers"
|
"--workers"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue