network_inventory/dev.sh

103 lines
2.8 KiB
Bash
Raw Normal View History

2022-12-12 21:42:00 +01:00
#!/usr/bin/env bash
run () {
setup
find . -name __pycache__ -o -name "*.pyc" -delete
sudo iptables -I INPUT -p tcp --dport 8000 -j ACCEPT
2023-07-13 22:25:50 +02:00
overmind start
2022-12-12 21:42:00 +01:00
}
setup () {
2023-07-13 23:48:43 +02:00
overmind start -l db -D
2022-12-12 21:42:00 +01:00
if [ -f .second_run ]; then
sleep 2
python ./src/manage.py collectstatic --noinput
python ./src/manage.py makemigrations
python ./src/manage.py migrate
else
python ./src/manage.py collectstatic --noinput
python ./src/manage.py makemigrations backups
python ./src/manage.py makemigrations computers
python ./src/manage.py makemigrations core
python ./src/manage.py makemigrations customers
python ./src/manage.py makemigrations devices
python ./src/manage.py makemigrations licenses
python ./src/manage.py makemigrations nets
python ./src/manage.py makemigrations softwares
python ./src/manage.py makemigrations users
python ./src/manage.py makemigrations
python ./src/manage.py migrate
python ./src/manage.py loaddata backups
python ./src/manage.py loaddata computers
python ./src/manage.py loaddata core
python ./src/manage.py loaddata devices
python ./src/manage.py loaddata nets
python ./src/manage.py loaddata softwares
python ./src/manage.py shell -c "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('admin', 'admin@example.com', 'password')"
2023-07-13 23:48:43 +02:00
touch .direnv/.second_run
2022-12-12 21:42:00 +01:00
fi
overmind quit
2022-12-12 21:42:00 +01:00
}
venv () {
2023-07-13 22:22:03 +02:00
nix build .#venv -o .venv
2022-12-12 21:42:00 +01:00
}
docker (){
nix build && docker load < result && docker run --rm -ti network-inventory:latest
}
clean () {
find . \( -name __pycache__ -o -name "*.pyc" \) -delete
rm -rf htmlcov/
2023-07-13 23:48:59 +02:00
rm -f src/*/migrations/0*.py .direnv/.second_run
2022-12-12 21:42:00 +01:00
}
cleanall () {
clean
2023-07-13 23:48:59 +02:00
rm -rf .venv .direnv/
2022-12-12 21:42:00 +01:00
}
init () {
python ./src/manage.py loaddata network_inventory.yaml
}
debug () {
pytest --pdb --nomigrations --cov=. --cov-report=html ./src/
}
2023-03-07 21:53:03 +01:00
check (){
2022-12-12 21:42:00 +01:00
nix flake check
}
2023-03-07 21:53:03 +01:00
test (){
2023-07-13 22:07:32 +02:00
export DJANGO_SETTINGS_MODULE=network_inventory.settings.ram_test
2023-07-13 23:02:56 +02:00
pytest -nauto --nomigrations --cov-config="$PROJECT_DIR/.coveragerc" --cov-report=html "$PROJECT_DIR/src"
2023-03-07 21:53:03 +01:00
}
2023-03-07 21:30:27 +01:00
update (){
poetry update --lock
}
2023-03-07 21:53:03 +01:00
tasks=("check" "clean" "cleanall" "debug" "docker" "run" "test" "update" "venv")
2022-12-12 21:42:00 +01:00
# only one task at a time
if [ $# != 1 ]; then
echo "usage: $0 <task_name>"
echo "All tasks: ${tasks[@]}"
fi
case $1 in
2023-03-07 21:53:03 +01:00
"${tasks[0]}") check;;
"${tasks[1]}") clean;;
"${tasks[2]}") cleanall;;
"${tasks[3]}") debug;;
"${tasks[4]}") docker;;
"${tasks[5]}") run;;
"${tasks[6]}") test;;
"${tasks[7]}") update;;
"${tasks[8]}") venv;;
2022-12-12 21:42:00 +01:00
esac