diff --git a/Makefile b/Makefile deleted file mode 100644 index 651eaf3..0000000 --- a/Makefile +++ /dev/null @@ -1,75 +0,0 @@ -SHELL=/usr/bin/env bash - -.DEFAULT_GOAL := run - -.PHONY: run -run: setup - ( \ - find . -name __pycache__ -o -name "*.pyc" -delete; \ - sudo iptables -I INPUT -p tcp --dport 8000 -j ACCEPT; \ - cd src/; \ - python manage.py runserver 0.0.0.0:8000; \ - ) - -.PHONY: setup -setup: - ( \ - docker-compose -f docker-compose-development.yml up -d; \ - cd src/; \ - if [ -f .second_run ]; then \ - sleep 2; \ - python manage.py collectstatic --noinput; \ - python manage.py makemigrations; \ - python manage.py migrate; \ - else \ - python manage.py collectstatic --noinput; \ - python manage.py makemigrations backups; \ - python manage.py makemigrations computers; \ - python manage.py makemigrations core; \ - python manage.py makemigrations customers; \ - python manage.py makemigrations devices; \ - python manage.py makemigrations licenses; \ - python manage.py makemigrations nets; \ - python manage.py makemigrations softwares; \ - python manage.py makemigrations users; \ - python manage.py makemigrations; \ - python manage.py migrate; \ - python manage.py loaddata backups; \ - python manage.py loaddata computers; \ - python manage.py loaddata core; \ - python manage.py loaddata devices; \ - python manage.py loaddata nets; \ - python manage.py loaddata softwares; \ - python 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')"; \ - touch .second_run; \ - fi; \ - ) - -.PHONY: venv -venv: - nix build .#venv -o venv - -.PHONY: clean -clean: - docker-compose -f docker-compose-development.yml down -v - find . \( -name __pycache__ -o -name "*.pyc" \) -delete - rm -rf htmlcov/ - rm -f */migrations/0*.py - rm .second_run - -.PHONY: cleanall -cleanall: clean - docker-compose -f docker-compose-development.yml down -v --rmi local - rm -r .venv - -.PHONY: init -init: - ( \ - python manage.py loaddata network_inventory.yaml; \ - ) - -.PHONY: debug -debug: - ( \ - pytest --pdb --nomigrations --cov=. --cov-report=html; \ - ) diff --git a/README.md b/README.md index 0d74f6a..8ca6782 100644 --- a/README.md +++ b/README.md @@ -28,10 +28,11 @@ Please note that I will only use and test the first method. [^2]: https://python-poetry.org After you've entered the development environment with either method you can -start the server with `make`. This will start a PostgreSQL database running -inside a docker container and start the Django development server. -You can then access it in the browser under the FQDN of your computer. E.g. -`mypc.domain.local`. +start the server. With the nix version you can start it with `dev run`. With +poetry `./dev.sh run`. This will start a PostgreSQL database running inside a +docker container and start the Django development server. You can then access +it in the browser under the FQDN of your computer. E.g. `mypc.domain.local`. +Run the `dev` command without an argument to see all options. ## Environment Variables diff --git a/dev.sh b/dev.sh new file mode 100755 index 0000000..0dd602b --- /dev/null +++ b/dev.sh @@ -0,0 +1,92 @@ +#!/usr/bin/env bash + +run () { + setup + find . -name __pycache__ -o -name "*.pyc" -delete + sudo iptables -I INPUT -p tcp --dport 8000 -j ACCEPT + python ./src/manage.py runserver 0.0.0.0:8000 +} + +setup () { + docker-compose -f docker-compose-development.yml up -d + 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')" + touch .second_run + fi +} + +venv () { + nix build .#venv -o venv +} + +docker (){ + nix build && docker load < result && docker run --rm -ti network-inventory:latest +} + +clean () { + docker-compose -f docker-compose-development.yml down -v + find . \( -name __pycache__ -o -name "*.pyc" \) -delete + rm -rf htmlcov/ + rm -f */migrations/0*.py + rm .second_run +} + +cleanall () { + clean + docker-compose -f docker-compose-development.yml down -v --rmi local + rm -r .venv +} + +init () { + python ./src/manage.py loaddata network_inventory.yaml +} + +debug () { + pytest --pdb --nomigrations --cov=. --cov-report=html ./src/ +} + +test (){ + nix flake check +} + +tasks=("clean" "cleanall" "debug" "docker" "run" "test" "venv") + +# only one task at a time +if [ $# != 1 ]; then + echo "usage: $0 " + echo "All tasks: ${tasks[@]}" +fi + + +case $1 in + "${tasks[0]}") clean;; + "${tasks[1]}") cleanall;; + "${tasks[2]}") debug;; + "${tasks[3]}") docker;; + "${tasks[4]}") run;; + "${tasks[5]}") test;; + "${tasks[6]}") venv;; +esac diff --git a/flake.nix b/flake.nix index dd16819..7a551fa 100644 --- a/flake.nix +++ b/flake.nix @@ -49,6 +49,7 @@ pkgs.inventoryDevEnv pkgs.poetry pkgs.python310Packages.pip + (pkgs.writeScriptBin "dev" "${builtins.readFile ./dev.sh}") ]; shellHook = '' export DJANGO_SETTINGS_MODULE=network_inventory.settings.local