Skip to content

Commit c446b0d

Browse files
committed
Refine Docker installation
File hierarchy inside docker container now looks similar to scancodeio. postgres data is now a docker volume, so it will persist even after recreation. .dockerignores makes sure that we don't overpopulated dockerfile, improving build times. A common environment variable for containers is kept in docker.env NOTE: We should have a postgres health check script which uses python manage.py check --database default which comes with max_retries and backoffs for `vulnerablecode` container. Currently, docker's `restart:` option is used but it has a caveat that it'll restart on non-db errors as well. Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
1 parent 2c4da22 commit c446b0d

5 files changed

Lines changed: 20 additions & 11 deletions

File tree

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.git
2+
.github
3+
4+
venv

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ FROM python:3.9.6
33
# Force unbuffered stdout and stderr (i.e. they are flushed to terminal immediately)
44
ENV PYTHONUNBUFFERED 1
55

6-
RUN mkdir /vulnerablecode
7-
WORKDIR /vulnerablecode
8-
COPY . /vulnerablecode/
6+
RUN mkdir /opt/vulnerablecode && \
7+
mkdir -p /var/vulnerablecode/static/
8+
WORKDIR /opt/vulnerablecode
9+
COPY . .
910
RUN python -m pip install --upgrade pip && \
1011
pip install -r requirements.txt

docker-compose.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ services:
55
image: postgres
66
env_file:
77
- docker.env
8+
volumes:
9+
- db_data:/var/lib/postgresql/data/
810

911
vulnerablecode:
1012
build: .
@@ -15,7 +17,8 @@ services:
1517
env_file:
1618
- docker.env
1719
volumes:
18-
- vulnerablecode:/vulnerablecode
20+
- static:/var/vulnerablecode/static/
21+
restart: on-failure
1922
depends_on:
2023
- db
2124

@@ -24,7 +27,7 @@ services:
2427
env_file:
2528
- docker.env
2629
volumes:
27-
- vulnerablecode:/vulnerablecode
30+
- static:/var/vulnerablecode/static/
2831
- ./etc/nginx/templates/:/etc/nginx/templates/
2932
ports:
3033
- ${NGINX_PORT:-8000}:80
@@ -33,4 +36,6 @@ services:
3336

3437

3538
volumes:
36-
vulnerablecode:
39+
static:
40+
db_data:
41+

docker.env

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
DJANGO_SETTINGS_MODULE=vulnerablecode.settings
2-
31
POSTGRES_DB=vulnerablecode
42
POSTGRES_USER=vulnerablecode
53
POSTGRES_PASSWORD=vulnerablecode
64

7-
GUNICORN_SERVER=vulnerablecode
5+
DJANGO_SETTINGS_MODULE=vulnerablecode.settings
6+
VULNERABLECODE_DB_HOST=db
87

9-
VC_DB_HOST=db
8+
GUNICORN_SERVER=vulnerablecode

etc/nginx/templates/default.conf.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ server {
1515
}
1616

1717
location /static/ {
18-
alias /vulnerablecode/static/;
18+
alias /var/vulnerablecode/static/;
1919
}
2020
}

0 commit comments

Comments
 (0)