Skip to content

Commit

Permalink
feat(docker): configure project to use docker in development
Browse files Browse the repository at this point in the history
This commit refactors the project to enable running it in
Docker for development.
  • Loading branch information
Samuel Paccoud - FUN MOOC committed Jan 5, 2018
1 parent c2aa724 commit 9f389f6
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 137 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Dockerfile
Pipefile
nginx/
media/
*.db
*.md
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.6-stretch
WORKDIR /app
ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8

# Add repository to install the connector to postgresql 9.6
# Remove the package lists after installation as a good practice
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' > /etc/apt/sources.list.d/pgdg.list && \
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
apt-get update && \
apt-get install -y python3-dev postgresql-server-dev-9.6 && \
rm -rf /var/lib/apt/lists/*

# Start by adding only the pipfile so that the next layer with all
# Python installs does not change each time our code changes
ADD Pipfile.lock /app/Pipfile.lock
RUN pip install pipenv && pipenv install --ignore-pipfile

ADD . /app

36 changes: 21 additions & 15 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,31 @@ python_version = ">=3.5"

[packages]

aldryn-newsblog = "*"
cmsplugin-filer = ">=1.1"
Django = "<2.0"
django-classy-tags = ">=0.7"
django-cms = "<3.5"
djangocms-admin-style = "<1.3,>=1.2"
django-filer = ">=1.2"
django-phonenumber-field = "<2.0.0" # Version 2 of django-phonenumber-field breaks Django dependencies
django-sekizai = ">=0.9"
django-treebeard = "<5.0,>=4.0"
djangocms-text-ckeditor = ">=3.2.1"
djangocms-link = ">=1.8"
djangocms-style = ">=1.7"
djangocms-admin-style = "<1.3,>=1.2"
djangocms-column = ">=1.6"
djangocms-googlemap = ">=0.5"
djangocms-link = ">=1.8"
djangocms-snippet = ">=1.9"
djangocms-style = ">=1.7"
djangocms-text-ckeditor = ">=3.2.1"
djangocms-video = ">=2.0"
djangocms-column = ">=1.6"
easy-thumbnails = "==2.4.2"
django-filer = ">=1.2"
cmsplugin-filer = ">=1.1"
Django = "<1.9"
pytz = "*"
django-classy-tags = ">=0.7"
"html5lib" = "<0.99999999,>=0.999999"
Pillow = ">=3.0"
django-sekizai = ">=0.9"
gunicorn = "*"
"psycopg2" = "*"
aldryn-newsblog = "*"
html5lib = "<0.99999999,>=0.999999"
Pillow = ">=3.0"
psycopg2 = "*"
pytz = "*"


[pipenv]

allow_prereleases = true
165 changes: 65 additions & 100 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "3"
services:
nginx:
build: ./nginx
image: fun_cms-nginx
ports:
- "8080:80"
db:
image: postgres:9.6
ports:
- "5440:5432"
environment:
POSTGRES_USER: "fun"
POTGRES_PASSWORD: "pass"
app:
build: ./
image: fun_cms-app
environment:
DATABASE_HOST: "db"
DATABASE_USER: "fun"
DATABASE_PASSWORD: "pass"
command: bash -c "pipenv run python manage.py runserver 0.0.0.0:8000"

2 changes: 1 addition & 1 deletion fun_cms/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(DATA_DIR, 'media')
STATIC_ROOT = os.path.join(DATA_DIR, 'static')
STATIC_ROOT = os.path.join(DATA_DIR, 'nginx', 'static')

STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
Expand Down
3 changes: 3 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM nginx:1.12.2
ADD conf.d /etc/nginx/conf.d
ADD static /app
19 changes: 19 additions & 0 deletions nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
server {

listen 80;
server_name localhost;
charset utf-8;

location /static {
alias /app;
}

location / {
proxy_pass http://app:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

}

21 changes: 0 additions & 21 deletions requirements.txt

This file was deleted.

0 comments on commit 9f389f6

Please sign in to comment.