network_inventory/dev.sh

117 lines
3.0 KiB
Bash
Raw Normal View History

2022-12-12 21:42:00 +01:00
#!/usr/bin/env bash
2023-07-22 16:29:34 +02:00
declare -A tasks
2022-12-12 21:42:00 +01:00
run () {
setup
find . -name __pycache__ -o -name "*.pyc" -delete
sudo iptables -I INPUT -p tcp --dport $WEBPORT -j ACCEPT
2023-07-22 16:37:49 +02:00
printf "\n---\n webserver: http://$(hostname -f):$WEBPORT\n---\n"
2023-07-22 17:24:15 +02:00
overmind start -D
2022-12-12 21:42:00 +01:00
}
2023-07-22 16:29:34 +02:00
tasks["run"]=run
tasks["start"]=run
2022-12-12 21:42:00 +01:00
2023-07-22 17:24:15 +02:00
stop () {
overmind quit
}
tasks["stop"]=stop
2022-12-12 21:42:00 +01:00
setup () {
2023-07-13 23:48:43 +02:00
overmind start -l db -D
2023-07-18 20:40:58 +02:00
if [ -f .direnv/first_run ]; then
2022-12-12 21:42:00 +01:00
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-18 20:58:39 +02:00
init
2023-07-18 20:40:58 +02:00
touch .direnv/first_run
2022-12-12 21:42:00 +01:00
fi
overmind quit
sleep 2
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
}
2023-07-22 16:29:34 +02:00
tasks["venv"]=venv
2022-12-12 21:42:00 +01:00
2023-07-22 16:29:34 +02:00
build-container (){
2022-12-12 21:42:00 +01:00
nix build && docker load < result && docker run --rm -ti network-inventory:latest
}
2023-07-22 16:29:34 +02:00
tasks["build-container"]=build-container
2022-12-12 21:42:00 +01:00
clean () {
find . \( -name __pycache__ -o -name "*.pyc" \) -delete
rm -rf htmlcov/
rm -f .direnv/first_run
rm -f src/*/migrations/0*.py
rm -rf .direnv/postgres/
2022-12-12 21:42:00 +01:00
}
2023-07-22 16:29:34 +02:00
tasks["clean"]=clean
2022-12-12 21:42:00 +01:00
cleanall () {
2023-07-18 20:44:01 +02:00
git clean -xdf
2022-12-12 21:42:00 +01:00
}
2023-07-22 16:29:34 +02:00
tasks["cleanall"]=cleanall
2022-12-12 21:42:00 +01:00
init () {
2023-07-18 20:58:39 +02:00
python ./src/manage.py loaddata src/network_inventory.yaml
2022-12-12 21:42:00 +01:00
}
debug () {
pytest --pdb --nomigrations --cov=. --cov-report=html ./src/
}
2023-07-22 16:29:34 +02:00
tasks["debug"]=debug
2022-12-12 21:42:00 +01:00
2023-03-07 21:53:03 +01:00
check (){
2022-12-12 21:42:00 +01:00
nix flake check
}
2023-07-22 16:29:34 +02:00
tasks["check"]=check
2022-12-12 21:42:00 +01:00
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-07-22 16:29:34 +02:00
tasks["test"]=test
2023-03-07 21:53:03 +01:00
2023-03-07 21:30:27 +01:00
update (){
poetry update --lock
}
2023-07-22 16:29:34 +02:00
tasks["update"]=update
2022-12-12 21:42:00 +01:00
# only one task at a time
if [ $# != 1 ]; then
2023-07-22 16:29:34 +02:00
echo "usage: dev <task_name>"
echo "All tasks: ${!tasks[@]}"
else
# Check if task is available
if [[ -v "tasks[$1]" ]] ; then
${tasks["$1"]}
else
echo "Task not found."
fi
2022-12-12 21:42:00 +01:00
fi