Skip to content

Commit

Permalink
Refine Docker installation
Browse files Browse the repository at this point in the history
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 overpopulate docker
images, improving build times.  A common environment variable for
containers is kept in docker.env
The python image we are using now explicitly states python:3.8

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 <[email protected]>
  • Loading branch information
Hritik14 committed Jul 28, 2021
1 parent e01dc44 commit 25292dd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
.github

venv
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FROM python:3.9.6
FROM python:3.8

# Force unbuffered stdout and stderr (i.e. they are flushed to terminal immediately)
ENV PYTHONUNBUFFERED 1

RUN mkdir /vulnerablecode
WORKDIR /vulnerablecode
COPY . /vulnerablecode/
RUN mkdir /opt/vulnerablecode && \
mkdir -p /var/vulnerablecode/static/
WORKDIR /opt/vulnerablecode
COPY . .
RUN python -m pip install --upgrade pip && \
pip install -r requirements.txt
pip install -r requirements.txt
11 changes: 8 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ services:
image: postgres
env_file:
- docker.env
volumes:
- db_data:/var/lib/postgresql/data/

vulnerablecode:
build: .
Expand All @@ -15,7 +17,8 @@ services:
env_file:
- docker.env
volumes:
- vulnerablecode:/vulnerablecode
- static:/var/vulnerablecode/static/
restart: on-failure
depends_on:
- db

Expand All @@ -24,7 +27,7 @@ services:
env_file:
- docker.env
volumes:
- vulnerablecode:/vulnerablecode
- static:/var/vulnerablecode/static/
- ./etc/nginx/templates/:/etc/nginx/templates/
ports:
- ${NGINX_PORT:-8000}:80
Expand All @@ -33,4 +36,6 @@ services:


volumes:
vulnerablecode:
static:
db_data:

7 changes: 3 additions & 4 deletions docker.env
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
DJANGO_SETTINGS_MODULE=vulnerablecode.settings

POSTGRES_DB=vulnerablecode
POSTGRES_USER=vulnerablecode
POSTGRES_PASSWORD=vulnerablecode

GUNICORN_SERVER=vulnerablecode
DJANGO_SETTINGS_MODULE=vulnerablecode.settings
VULNERABLECODE_DB_HOST=db

VC_DB_HOST=db
GUNICORN_SERVER=vulnerablecode
2 changes: 1 addition & 1 deletion etc/nginx/templates/default.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ server {
}

location /static/ {
alias /vulnerablecode/static/;
alias /var/vulnerablecode/static/;
}
}

0 comments on commit 25292dd

Please sign in to comment.