Skip to content

Commit

Permalink
implemented method for running webchat in production using docker-com…
Browse files Browse the repository at this point in the history
…pose using postgres, postfix and uwsgi.
  • Loading branch information
dhedegaard committed Aug 16, 2015
1 parent 79e8982 commit fb3783d
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
@@ -0,0 +1,3 @@
data
.git
static_collect
17 changes: 17 additions & 0 deletions Dockerfile.prod
@@ -0,0 +1,17 @@
FROM python:3
MAINTAINER dennis@dhedegaard.dk
EXPOSE 9090
VOLUME ./static_collect
ADD requirements.txt .
RUN pip install -q -r requirements.txt
ADD requirements-prod.txt .
RUN pip install -q -r requirements-prod.txt
ADD . .
CMD python manage.py migrate &&\
python manage.py collectstatic --noinput &&\
uwsgi --socket :9090 \
--processes=5 \
--harakiri=60 \
--max-requests=5000 \
--static-map /static=./static_collect \
--wsgi-file webchat/wsgi.py
20 changes: 18 additions & 2 deletions README.md
Expand Up @@ -4,10 +4,26 @@
[![Coverage Status](https://coveralls.io/repos/dhedegaard/webchat/badge.svg?branch=master)](https://coveralls.io/r/dhedegaard/webchat?branch=master)
[![Requirements Status](https://requires.io/github/dhedegaard/webchat/requirements.svg?branch=master)](https://requires.io/github/dhedegaard/webchat/requirements/?branch=master)

A simple Django app for doing webchat over HTTP, it is implemented using long polling over AJAX using XHR.
A simple Django app for doing webchat over HTTP, it is implemented using long
polling over AJAX using XHR.

## How to get it running.

You can either use `docker`, if you run using the default `Dockerfile` you will
run the Django debug server.

You can also run it using docker-compose, this setup is using postgres,
postfix and uwsgi for a complete setup.

A simple `docker-compose build` and `docker-compose run` will sufficem then
simply forward through nginx, apache or similar.

The third option is setting up a virtualenv and installing the packages in
`requirements.txt` and `requirements-prod.txt`.

## TODO

Future development might involve:
- Using websockets
- More structure on the javascript, for instance using backbone.js
- Test coverage on javascript
- Running the whole thing from docker.
36 changes: 36 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,36 @@
# Docker compose for running the project in production.
# It exposes
# Remember to:
# - change the django secret in settings.
# - change the postfix user/pass.
# - change the postgres pass.
uwsgi:
build: .
volumes:
- ./static_collect:./static_collect
dockerfile: Dockerfile.prod
restart: always
environment:
- WEBCHAT_DEBUG=True
- WEBCHAT_DATABASE=postgres
ports:
- "9090"
links:
- db
- mail

db:
image: postgres
restart: always
environment:
- POSTGRES_USER=webchat
- POSTGRES_PASSWORD=webchat123
volumes:
- ./data:/var/lib/postgresql/data

mail:
image: catatnight/postfix
restart: always
environment:
- maildomain=webchat.dhedegaard.dk
- smtp_user=webchat:webchat123
2 changes: 2 additions & 0 deletions requirements-prod.txt
@@ -0,0 +1,2 @@
uwsgi==2.0.11.1
psycopg2==2.6.1
46 changes: 35 additions & 11 deletions webchat/settings.py
@@ -1,29 +1,53 @@
# Django settings for webchat project.
import os

DEBUG = True
# DEBUG by default.
DEBUG = os.environ.get('WEBCHAT_DEBUG', 'True') == 'True'
TEMPLATE_DEBUG = DEBUG

ADMINS = (
('Dennis Hedegaard', 'dennis@dhedegaard.dk'),
)

import os
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')).replace('\\', '/')

MANAGERS = ADMINS

ALLOWED_HOSTS = ['wc.dhedegaard.dk', 'webchat.dhedegaard.dk',
'wc.neo2k.dk', 'webchat.neo2k.dk']

# Mail server settings, reference the docker container.
EMAIL_HOST = 'mail'
EMAIL_HOST_USER = 'webchat'
EMAIL_HOST_PASSWORD = 'webchat123'
EMAIL_SUBJECT_PREFIX = '[webchat] '
SERVER_EMAIL = 'webchat@webchat.dhedegaard.dk'

# For running development (default).
DATABASE_SQLITE = {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'webchat.db',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}

# For running in production.
DATABASE_POSTGRES = {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'webchat',
'USER': 'webchat',
'PASSWORD': 'webchat123',
'HOST': 'db',
'PORT': '',
}

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'webchat.db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
'default': (
DATABASE_POSTGRES
if os.environ.get('WEBCHAT_DATABASE', 'sqlite') == 'postgres' else
DATABASE_SQLITE),
}

# Local time zone for this installation. Choices can be found here:
Expand Down Expand Up @@ -145,4 +169,4 @@
}
}

TEST_RUNNER = 'django.test.runner.DiscoverRunner'
TEST_RUNNER = 'django.test.runner.DiscoverRunner'

0 comments on commit fb3783d

Please sign in to comment.