Skip to content

Commit ec15085

Browse files
committed
Improve setup instructions in README
- Fix instructions for Debian-based distros - Add instructions for running Postgres in Docker - Set DJANGO_DEV=1 in runserver call to have localhost in - ALLOWED_HOSTS closes #47 Signed-off-by: Haiko Schol <hs@haikoschol.com>
1 parent 1dfae11 commit ec15085

2 files changed

Lines changed: 28 additions & 36 deletions

File tree

README.md

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,61 @@
22

33
[![Build Status](https://travis-ci.org/nexB/vulnerablecode.svg?branch=develop)](https://travis-ci.org/nexB/vulnerablecode)
44

5-
Setup
6-
-----
7-
VulnerableCode requires Python 3.6+, get the latest version at https://www.python.org/
5+
## Setup
86

97
Clone the source code:
108

119
```
1210
git clone https://github.com/nexB/vulnerablecode.git && cd vulnerablecode
1311
```
1412

15-
System requirements
13+
### System requirements
1614

17-
- Get Python 3.6+ installed first and pip (pip is included in the
18-
Python.org downloads since Python 2.7.9)
15+
- Python 3.6+
1916

20-
- Install PostgreSQL 9 of later. (11.2 preferred)
21-
On Debian distros use: `sudo apt-get install postgresql`
17+
- PostgreSQL 9+ or [Docker](https://hub.docker.com/search/?type=edition&offering=community)
2218

23-
- Install extra utilities if needed: `sudo apt-get install wget build-essential redis-server`
19+
- Compiler toolchain and development files for Python and PostgreSQL
2420

21+
On Debian-based distros, these can be installed with `sudo apt install python3-venv python3-dev postgresql libpq-dev build-essential`. Leave out `postgresql` if you want to run it in Docker.
2522

26-
Configure a local test database
23+
### Database configuration
2724

28-
- Create a local test `vulnerablecode` database user. Use `vulnerablecode` as password when prompted
29-
(otherwise use any password and update your settings locally).
25+
Either run PostgreSQL in Docker:
26+
`docker run --name pg-vulnerablecode -e POSTGRES_USER=vulnerablecode -e POSTGRES_PASSWORD=vulnerablecode -e POSTGRES_DB=vulnerablecode -p 5432:5432 postgres`
27+
28+
Or without:
29+
30+
- Create a user named `vulnerablecode`. Use `vulnerablecode` as password when prompted:
3031
`sudo -u postgres createuser --no-createrole --no-superuser --login --inherit --createdb --pwprompt vulnerablecode`
3132

32-
- Create a local test `vulnerablecode` database.
33+
- Create a databased named `vulnerablecode`:
3334
`createdb --encoding=utf-8 --owner=vulnerablecode --user=vulnerablecode --password --host=localhost --port=5432 vulnerablecode`
3435

36+
### Application dependencies
37+
3538
Activate a virtualenv, install dependencies, and run the database migrations:
3639

3740
```
38-
python3 -m venv .
39-
source bin/activate
41+
python3 -m venv venv
42+
source venv/bin/activate
4043
pip install -r requirements.txt
4144
python manage.py migrate
4245
```
4346

44-
Tests
45-
-----
47+
## Tests
4648

4749
```
48-
pycodestyle --exclude=migrations,settings.py,lib,tests --max-line-length=100 .
49-
python3.6 -m pytest -v vulnerabilities/tests/test_scrapers.py vulnerabilities/tests/test_api_data.py
50+
pycodestyle --exclude=migrations,settings.py,venv,tests --max-line-length=100 .
51+
python -m pytest -v vulnerabilities/tests/test_scrapers.py vulnerabilities/tests/test_api_data.py
5052
```
5153

5254
For Django based tests
5355
```
5456
python manage.py test vulnerabilities/tests
5557
```
5658

57-
Scrape and save to the database
58-
-------------------------------
59+
## Data import
5960

6061
```
6162
python manage.py shell
@@ -78,22 +79,22 @@ archlinux_vulnerabilities = archlinux.scrape_vulnerabilities()
7879
archlinux_dump(archlinux_vulnerabilities)
7980
```
8081

81-
API
82-
----
82+
## API
83+
8384
Start the webserver
8485

8586
```
86-
python manage.py runserver
87+
DJANGO_DEV=1 python manage.py runserver
8788
```
8889

8990
In your browser access:
91+
9092
```
9193
http://127.0.0.1:8000/api/
9294
http://127.0.0.1:8000/api/packages/?name=<package_name>
9395
```
9496

95-
Deployment on Heroku
96-
--------------------
97+
## Deployment on Heroku
9798

9899
See https://devcenter.heroku.com/articles/django-app-configuration#creating-a-new-django-project
99100
https://devcenter.heroku.com/articles/deploying-python#how-to-keep-build-artifacts-out-of-git
@@ -112,6 +113,6 @@ https://devcenter.heroku.com/articles/deploying-python#how-to-keep-build-artifac
112113

113114
7. Migrate the database: `heroku run python manage.py migrate`
114115

115-
8. Load the data referring to chapter "Scrape and save to the database" above.
116+
8. Load the data referring to chapter "Data import" above.
116117

117118
9. To check the logs: `heroku logs --tail`

vulnerablecode/dev.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
import os
22

3-
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
4-
53
DEBUG = True
64

75
ALLOWED_HOSTS = ['localhost', '127.0.0.1', '::1']
8-
9-
DATABASES = {
10-
'default': {
11-
'ENGINE': 'django.db.backends.sqlite3',
12-
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
13-
}
14-
}

0 commit comments

Comments
 (0)