Skip to content

Commit 6bf44e0

Browse files
authored
Merge pull request #256 from sbs2001/dockerize
Dockerize vulnerablecode
2 parents 3e10ff3 + 81167ab commit 6bf44e0

File tree

4 files changed

+60
-22
lines changed

4 files changed

+60
-22
lines changed

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM python@sha256:e9b7e3b4e9569808066c5901b8a9ad315a9f14ae8d3949ece22ae339fff2cad0
2+
3+
# PYTHONUNBUFFERED=1 ensures that the python output is set straight
4+
# to the terminal without buffering it first
5+
ENV PYTHONUNBUFFERED 1
6+
RUN mkdir /vulnerablecode
7+
WORKDIR /vulnerablecode
8+
ADD . /vulnerablecode/
9+
RUN pip install -r requirements.txt
10+
11+
LABEL "base_image": "pkg:docker/python@sha256%3Ae9b7e3b4e9569808066c5901b8a9ad315a9f14ae8d3949ece22ae339fff2cad0"
12+
LABEL "dockerfile_url": "https://github.com/nexB/vulnerablecode/blob/develop/Dockerfile"
13+
LABEL "homepage_url": "https://github.com/nexB/vulnerablecode"
14+
LABEL "license": "Apache-2.0"

README.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,40 +38,45 @@ The web interface enables community curation of data by enabling addition of new
3838

3939
We also plan to mine for vulnerabilities which didn't receive any exposure due to various reasons like but not limited to the complicated procedure to receive CVE ID or not able to classify a bug as a security compromise. Check VulnerableCode at [Open Source Summit 2020](https://ossna2020.sched.com/event/c46p/why-is-there-no-free-software-vulnerability-database-philippe-ombredanne-aboutcodeorg-and-nexb-inc-michael-herzog-nexb-inc)
4040

41-
## Setup
41+
## Setting up VulnerableCode
4242

4343
Clone the source code:
4444

4545
```
46-
git clone https://github.com/nexB/vulnerablecode.git && cd vulnerablecode
46+
git clone https://github.com/nexB/vulnerablecode.git
47+
cd vulnerablecode
4748
```
4849

49-
### System requirements
50+
### Using Docker Compose
51+
An easy way to set up VulnerableCode is with docker containers and docker compose.
52+
For this you need to have the following installed.
53+
- Docker Engine. Find instructions to install it here
54+
- Docker Compose. Find instructions to install it here
5055

51-
- Python 3.8+
52-
53-
- PostgreSQL 9+ or [Docker](https://hub.docker.com/search/?type=edition&offering=community)
56+
Use `sudo docker-compose up` to start VulnerableCode.
57+
Access VulnerableCode at http://localhost:8000/ or at http://127.0.0.1:8000/ .
5458

55-
- Compiler toolchain and development files for Python and PostgreSQL
59+
Use `sudo docker-compose exec web bash` to access the VulnerableCode container. From here you can access `manage.py` and run management commands to import data as specified below.
5660

57-
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.
61+
### Without Docker Compose
62+
**System requirements**
5863

59-
### Database configuration
60-
61-
Either run PostgreSQL in Docker:
62-
`docker run --name pg-vulnerablecode -e POSTGRES_USER=vulnerablecode -e POSTGRES_PASSWORD=vulnerablecode -e POSTGRES_DB=vulnerablecode -p 5432:5432 postgres`
64+
- Python 3.8+
65+
- PostgreSQL 9+
66+
- Compiler toolchain and development files for Python and PostgreSQL
6367

64-
Or without:
68+
On Debian-based distros, these can be installed with `sudo apt install python3-venv python3-dev postgresql libpq-dev build-essential`.
6569

70+
**Database configuration**
6671
- Create a user named `vulnerablecode`. Use `vulnerablecode` as password when prompted:
6772
`sudo -u postgres createuser --no-createrole --no-superuser --login --inherit --createdb --pwprompt vulnerablecode`
6873

6974
- Create a databased named `vulnerablecode`:
7075
`createdb --encoding=utf-8 --owner=vulnerablecode --user=vulnerablecode --password --host=localhost --port=5432 vulnerablecode`
7176

72-
### Application dependencies
77+
**Application dependencies**
7378

74-
Activate a virtualenv, install dependencies, and run the database migrations:
79+
Create a virtualenv, install dependencies, and run the database migrations:
7580

7681
```
7782
python3 -m venv venv
@@ -132,13 +137,10 @@ systemctl --user daemon-reload && systemctl --user start vulnerablecode.timer
132137
## API
133138

134139
Start the webserver
135-
136140
```
137141
DJANGO_DEV=1 python manage.py runserver
138142
```
139-
140143
In your browser access:
141-
142144
```
143145
http://127.0.0.1:8000/api/docs
144146
```

docker-compose.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: '3'
2+
3+
services:
4+
web:
5+
environment:
6+
- DJANGO_DEV=1
7+
- VC_DB_HOST=db
8+
build: .
9+
command: bash -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
10+
container_name: "vulnerablecode"
11+
volumes:
12+
- .:/vulnerablecode
13+
ports:
14+
- "8000:8000"
15+
depends_on:
16+
- db
17+
db:
18+
image: postgres
19+
environment:
20+
- POSTGRES_DB=vulnerablecode
21+
- POSTGRES_USER=vulnerablecode
22+
- POSTGRES_PASSWORD=vulnerablecode

vulnerablecode/settings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@
9191
DATABASES = {
9292
'default': {
9393
'ENGINE': 'django.db.backends.postgresql',
94-
'NAME': 'vulnerablecode',
95-
'USER': 'vulnerablecode',
96-
'PASSWORD': 'vulnerablecode',
97-
'HOST': 'localhost',
94+
'NAME': os.environ.get('VC_DB_NAME','vulnerablecode'),
95+
'USER': os.environ.get('VC_DB_USER','vulnerablecode'),
96+
'PASSWORD': os.environ.get('VC_DB_PASSWORD','vulnerablecode'),
97+
'HOST': os.environ.get('VC_DB_HOST', 'localhost'),
9898
'PORT': '5432',
9999
}
100100
}

0 commit comments

Comments
 (0)