Skip to content

Commit

Permalink
improvements to Dockerfile, docker-compose etc
Browse files Browse the repository at this point in the history
  • Loading branch information
pacharanero committed Apr 12, 2023
1 parent 247f855 commit 0768251
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 17 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# patterns matched in this file are excluded from the Dockerfile image build
# This reduces image size and improves security

.git
.github
.gitignore
*.env
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,7 @@ start/hermes-v0.7.5.jar
# VS Ccode
.code-workspace
.vscode/
.vscode/*
.vscode/*

# exclude dev data files
.data
30 changes: 24 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
# Base Docker image Official Python 3.10
FROM python:3.10

# Create & set working directory
RUN mkdir -p /home/app/webapp
WORKDIR /home/app/webapp

# Set environment variables
# Set 'build-time' environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PYTHONUNBUFFERED 1

# Add Development requirements
COPY requirements/development-requirements.txt /app/requirements/development-requirements.txt
COPY requirements/common-requirements.txt /app/requirements/common-requirements.txt

# Set working directory for requirements installation
WORKDIR /app/requirements/

# Run installation of requirements
RUN pip install --upgrade pip
RUN pip install -r /app/requirements/development-requirements.txt

# Set working directory back to main app
WORKDIR /app/

# Copy application code into image
# (Excludes any files/dirs matched by patterns in .dockerignore)
COPY . /app/

# Use port 8000 in development (may be overridden by docker-compose file)
EXPOSE 8000

10 changes: 4 additions & 6 deletions docker-compose.dev-init.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
depends_on:
- db
volumes:
- .:/home/app/webapp
- .:/app/
environment:
# these env vars are ONLY for development
- E12_POSTGRES_DB_USER=epilepsy12user
Expand All @@ -40,9 +40,7 @@ services:
env_file:
- .env # this contains the token for RCPCH Census Platform and is not entered into git
command: >
sh -c "pip install --upgrade pip &&
pip install -r requirements/development-requirements.txt &&
python manage.py collectstatic --noinput &&
sh -c "python manage.py collectstatic --noinput &&
python manage.py makemigrations &&
python manage.py migrate &&
python manage.py seed --mode=seed_organisations &&
Expand All @@ -61,8 +59,8 @@ services:
# db container - runs postgres
db:
image: postgres:latest
# volumes:
# - ./data/db:/var/lib/postgresql/data
volumes:
- ./.data/db:/var/lib/postgresql/data
environment:
- POSTGRES_USER=epilepsy12user
- POSTGRES_PASSWORD=password
Expand Down
12 changes: 9 additions & 3 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
depends_on:
- db
volumes:
- .:/home/app/webapp
- .:/app/
environment:
# these env vars are ONLY for development
- E12_POSTGRES_DB_USER=epilepsy12user
Expand All @@ -27,14 +27,20 @@ services:
- DJANGO_ALLOWED_HOSTS=0.0.0.0
command: >
sh -c "python manage.py runserver 0.0.0.0:8000"
# ensures that docker compose always displays log output
tty: true
stdin_open: true

# db container - runs postgres
db:
image: postgres:latest
# volumes:
# - ./data/db:/var/lib/postgresql/data
volumes:
- ./.data/db:/var/lib/postgresql/data
environment:
- POSTGRES_USER=epilepsy12user
- POSTGRES_PASSWORD=password
- POSTGRES_DB=epilepsy12db
- TZ="Europe/London"
# ensures that docker compose always displays log output
tty: true
stdin_open: true
2 changes: 1 addition & 1 deletion s/docker-init
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
# starts the postgres and application containers
# migrates db, seeds db, creates superuser, runs server

docker compose -f docker-compose.dev.yml down
mkdir .data/db
docker compose -f docker-compose.dev-init.yml up

0 comments on commit 0768251

Please sign in to comment.