Use process-compose directly

This commit is contained in:
Andreas Zweili 2024-03-11 15:38:29 +01:00
parent bb2772cf67
commit 429a57d89a
3 changed files with 36 additions and 33 deletions

1
.gitignore vendored
View File

@ -182,3 +182,4 @@ db_data
/result
/static/
/.devenv/
/process-compose.yml

59
dev.sh
View File

@ -6,9 +6,30 @@ _init() {
python ./src/manage.py loaddata src/network_inventory.yaml
}
_open_url() {
if [[ ! -z "${DEFAULT_BROWSER}" ]]; then
$DEFAULT_BROWSER $url
elif type explorer.exe &>/dev/null; then
explorer.exe $url
fi
}
_create_url() {
if [ -f /etc/wsl.conf ]; then
echo "http://localhost:$WEBPORT"
else
echo "http://$(hostname -f):$WEBPORT"
fi
}
#}
# Main tasks start
declare -A tasks
declare -A descriptions
# Setup the database
_setup() {
sleep 5
setup() {
find . -name __pycache__ -o -name "*.pyc" -delete
if [ -f .direnv/first_run ]; then
python ./src/manage.py collectstatic --noinput
python ./src/manage.py makemigrations
@ -36,35 +57,15 @@ _setup() {
_init
touch .direnv/first_run
fi
}
_open_url() {
if [[ ! -z "${DEFAULT_BROWSER}" ]]; then
$DEFAULT_BROWSER $url
elif type explorer.exe &>/dev/null; then
explorer.exe $url
fi
}
_create_url() {
if [ -f /etc/wsl.conf ]; then
echo "http://localhost:$WEBPORT"
else
echo "http://$(hostname -f):$WEBPORT"
fi
}
#}
# Main tasks start
declare -A tasks
declare -A descriptions
run() {
_setup
find . -name __pycache__ -o -name "*.pyc" -delete
url=$(_create_url)
printf "\n---\n webserver: $url\n---\n"
_open_url $url
_open_url $url sleep 5
}
descriptions["setup"]="Setup the database and load example data."
tasks["setup"]=setup
run() {
process-compose up
}
descriptions["run"]="Start the webserver."
tasks["run"]=run

View File

@ -15,9 +15,6 @@
forEachSystem = nixpkgs.lib.genAttrs (import systems);
in
{
packages = forEachSystem (system: {
devenv-up = self.devShells.${system}.default.config.procfileScript;
});
devShells = forEachSystem
(system:
let
@ -30,6 +27,10 @@
{
packages = [
(pkgs.writeScriptBin "dev" "${builtins.readFile ./dev.sh}")
config = self.devShells.${system}.default.config;
enterShell = ''
ln -sf ${config.process-managers.process-compose.configFile} ${config.env.DEVENV_ROOT}/process-compose.yml
'';
];
env = {
DJANGO_SETTINGS_MODULE = "network_inventory.settings.local";
@ -55,7 +56,7 @@
# https://github.com/cachix/devenv/blob/main/examples/process-compose/devenv.nix
processes = {
webserver.exec = "poetry run python ./src/manage.py runserver 0.0.0.0:$WEBPORT";
setup.exec = "dev start";
setup.exec = "dev setup";
};
services.postgres = {
enable = true;