feat(django-apps): allow adding extra init steps

This commit is contained in:
catvayor 2025-03-09 10:11:14 +01:00
parent 990206da3c
commit 4229835ec4
Signed by untrusted user: lbailly
GPG key ID: CE3E645251AC63F3

View file

@ -445,6 +445,15 @@ in
doBackups = mkEnableOption "backups for this site" // {
default = true;
};
extraInit = mkOption {
type = lines;
description = ''
Steps taken during the initialization after the migration is done
and the static files have been collected.
'';
default = '''';
};
};
}
)
@ -722,18 +731,24 @@ in
inherit after environment path;
preStart = ''
# Create the necessary directory with the correct user/group
mkdir -p ${config.mediaDirectory} ${config.staticDirectory}
if [ ! -f .initialized ]; then
# The previous initialization might have failed, so restart from the beginning
rm -rf source
# We need to download the application source and run the migrations first
${lib.getExe pkgs.git} clone --single-branch --branch ${config.branch} ${config.source} source
(cd source && python ${config.managePath} migrate --no-input && python ${config.managePath} collectstatic --no-input)
pushd source
python ${config.managePath} migrate --no-input
python ${config.managePath} collectstatic --no-input
${config.extraInit}
popd
touch .initialized
fi
# Create the necessary directory with the correct user/group
mkdir -p ${config.mediaDirectory} ${config.staticDirectory}
'';
requires = optional (config.application.type != "daphne") "dj-${name}.socket";