feat(manage commmand): Add manage command with nsenter
This commit is contained in:
parent
5ea9469cc2
commit
a61afb48e2
2 changed files with 52 additions and 33 deletions
24
module.nix
24
module.nix
|
@ -6,9 +6,20 @@
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
mkManagePy = pkgs.callPackage ./utils/mkManagePy.nix { };
|
mkManagePy = pkgs.callPackage ./utils/mkManagePy.nix { };
|
||||||
|
|
||||||
|
mkManageCommand =
|
||||||
|
app: cfg:
|
||||||
|
pkgs.writeShellScriptBin "manage-${app}" ''
|
||||||
|
eval "$(${config.systemd.package}/bin/systemctl show -pMainPID django-${app}.service)"
|
||||||
|
${pkgs.util-linux}/bin/nsenter -e -a -t $MainPID -G follow -S follow ${lib.getExe cfg.managePy} "$@"
|
||||||
|
'';
|
||||||
mkStaticAssets =
|
mkStaticAssets =
|
||||||
{ app, managePy, mainModule }:
|
{
|
||||||
pkgs.runCommand "django-${app}-static" {} ''
|
app,
|
||||||
|
managePy,
|
||||||
|
mainModule,
|
||||||
|
}:
|
||||||
|
pkgs.runCommand "django-${app}-static" { } ''
|
||||||
mkdir -p "$out/static"
|
mkdir -p "$out/static"
|
||||||
STATIC_ROOT="\"$out/static\"" \
|
STATIC_ROOT="\"$out/static\"" \
|
||||||
DJANGO_SETTINGS_MODULE="${mainModule}_settings.mock" \
|
DJANGO_SETTINGS_MODULE="${mainModule}_settings.mock" \
|
||||||
|
@ -73,7 +84,7 @@ let
|
||||||
};
|
};
|
||||||
runtimeSettings = lib.mkOption {
|
runtimeSettings = lib.mkOption {
|
||||||
type = with lib.types; attrsOf str;
|
type = with lib.types; attrsOf str;
|
||||||
default= {};
|
default = { };
|
||||||
description = ''
|
description = ''
|
||||||
Settings to pass to only at runtime.
|
Settings to pass to only at runtime.
|
||||||
|
|
||||||
|
@ -166,7 +177,7 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config = {
|
config = {
|
||||||
runtimeSettings.STATIC_ROOT = "";#config.staticAssets;
|
runtimeSettings.STATIC_ROOT = ""; # config.staticAssets;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -178,7 +189,8 @@ in
|
||||||
description = "Attribute set of djanfo app modules";
|
description = "Attribute set of djanfo app modules";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config.systemd.services = lib.mapAttrs' (
|
config = {
|
||||||
|
systemd.services = lib.mapAttrs' (
|
||||||
app: cfg:
|
app: cfg:
|
||||||
lib.nameValuePair "django-${app}" (
|
lib.nameValuePair "django-${app}" (
|
||||||
lib.mkIf cfg.enable {
|
lib.mkIf cfg.enable {
|
||||||
|
@ -208,4 +220,6 @@ in
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
) config.services.django;
|
) config.services.django;
|
||||||
|
environment.systemPackages = lib.mapAttrsToList (k: v: mkManageCommand k v) config.services.django;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
5
test.nix
5
test.nix
|
@ -82,6 +82,11 @@ pkgs.testers.runNixOSTest (
|
||||||
if status != 0 or json.loads(out) != json.loads('${builtins.toJSON settings.JSON_SMOKE_TEST}'):
|
if status != 0 or json.loads(out) != json.loads('${builtins.toJSON settings.JSON_SMOKE_TEST}'):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
with subtest("Manage command"):
|
||||||
|
out = machine.succeed('manage-smoke-test shell -c "from django.conf import settings; print(settings.SMOKE_TEST)"')
|
||||||
|
if out.strip() != "${settings.SMOKE_TEST}".strip():
|
||||||
|
print(out)
|
||||||
|
sys.exit(1)
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue