Add a Makefile

This commit is contained in:
Andreas Zweili 2019-07-13 15:25:32 +02:00
parent 99747257b0
commit ff5da6f114
5 changed files with 52 additions and 16 deletions

32
Makefile Normal file
View File

@ -0,0 +1,32 @@
SHELL=/bin/bash
.PHONY: docker
docker:
docker-compose up
venv/bin/activate: requirements/local.txt
test -d venv || python3 -m venv venv
. venv/bin/activate; pip3 install wheel; pip3 install -Ur requirements/local.txt
touch venv/bin/activate
local:
python3 -m venv venv
( \
source venv/bin/activate; \
pip3 install -r requirements/local.txt; \
)
local_test:
( \
export DJANGO_SETTINGS_MODULE=network_inventory.settings.local; \
source venv/bin/activate; \
cd network_inventory/inventory/tests/; \
pytest; \
)
clean:
rm -f network_inventory/network_inventory/db.sqlite3
rm -rf venv/
sudo find . \( -name __pycache__ -o -name "*.pyc" \) -delete
docker-compose down -v --rmi local

View File

@ -6,16 +6,21 @@ inventory over my various servers and other network equipment.
## Setup
1. Clone the repository
2. Run `./setup.sh` to setup the docker container.
3. Run `docker-compose up` to start the development server. You can access it at
2. Now decide if you want to develop fully locally or inside the docker
container. Locally you'll use SQlite for the database and inside the Docker
container you'll use Postgres for the database. For the moment there aren't
any features implemented which require Postgres. However this might change
in the future and SQlite is not supported for production.
### Local Setup
3. Run `make local` to create a virtual environment.
4. Run `run.sh` to start the development server. You can access it at
http://localhost:8000 . You're now all set to start developing.
If you need to run migrations you can create and apply them with the following
two commands.
```
docker-compose run web python manage.py makemigrations inventory
docker-compose run web python manage.py migrate
```
### Docker Setup
3. Run `make` to start the development server. You can access it
at http://localhost:8000 . You're now all set to start developing. \
If you need to run migrations you can simply restart the Docker container.
## Todos
- [ ] Create an Apache configuration

View File

@ -1,2 +0,0 @@
sudo find . \( -name __pycache__ -o -name "*.pyc" \) -delete
rm network_inventory/network_inventory/db.sqlite3

View File

@ -13,12 +13,12 @@ services:
web:
build: .
command: ./run.sh network_inventory.settings.docker
command: ./run.sh
volumes:
- .:/code
ports:
- "8000:8000"
environment:
- DJANGO_SETTINGS_MODULE=network_inventory.settings.local
- DJANGO_SETTINGS_MODULE=network_inventory.settings.docker
depends_on:
- db

9
run.sh
View File

@ -1,6 +1,7 @@
#!/bin/bash
cd network_inventory
python manage.py migrate --settings=$1
python manage.py loaddata inventory --settings=$1
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')" --settings=$1
python manage.py runserver 0.0.0.0:8000 --settings=$1
python manage.py makemigrations
python manage.py migrate
python manage.py loaddata inventory
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')"
python manage.py runserver 0.0.0.0:8000