Last active
March 13, 2017 08:44
-
-
Save tungd/2ff8f2a1e91add29648f57b5df6bf695 to your computer and use it in GitHub Desktop.
Dockerize Heroku's Django Chat example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
postgres: | |
image: postgres | |
environment: | |
- POSTGRES_PASSWORD=password | |
redis: | |
image: redis | |
web: | |
build: . | |
command: daphne chat.asgi:channel_layer --port 8000 --bind 0.0.0.0 -v2 | |
ports: | |
- 8000:8000 | |
links: | |
- postgres | |
- redis | |
environment: | |
- PYTHONUNBUFFERED=1 | |
- POSTGRES_HOST=postgres | |
- POSTGRES_PASSWORD=password | |
- REDIS_URL=redis://redis:6379 | |
worker: | |
build: . | |
command: python manage.py runworker -v2 | |
links: | |
- postgres | |
- redis | |
environment: | |
- PYTHONUNBUFFERED=1 | |
- POSTGRES_HOST=postgres | |
- POSTGRES_PASSWORD=password | |
- REDIS_URL=redis://redis:6379 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:2 | |
RUN mkdir -p /usr/src/app | |
WORKDIR /usr/src/app | |
ADD requirements.txt /usr/src/app | |
RUN pip install --no-cache-dir -r requirements.txt | |
ADD . /usr/src/app | |
EXPOSE 8000 | |
CMD ["python", "manage.py", "runworker", "-v2"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 8522a682f93d3c3017435f0ff146d8ef85f51f64 | |
Author: Tung Dao <[email protected]> | |
Date: Sun Mar 12 12:44:34 2017 +0700 | |
dockerize the app | |
diff --git a/Dockerfile b/Dockerfile | |
new file mode 100644 | |
index 0000000..dab29ae | |
--- /dev/null | |
+++ b/Dockerfile | |
@@ -0,0 +1,12 @@ | |
+FROM python:2 | |
+ | |
+RUN mkdir -p /usr/src/app | |
+WORKDIR /usr/src/app | |
+ | |
+ADD requirements.txt /usr/src/app | |
+RUN pip install --no-cache-dir -r requirements.txt | |
+ | |
+ADD . /usr/src/app | |
+ | |
+EXPOSE 8000 | |
+CMD ["python", "manage.py", "runworker", "-v2"] | |
diff --git a/chat/settings.py b/chat/settings.py | |
index 6d7f2cf..91d374b 100644 | |
--- a/chat/settings.py | |
+++ b/chat/settings.py | |
@@ -1,12 +1,12 @@ | |
import os | |
-import random | |
+import uuid | |
import string | |
import dj_database_url | |
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) | |
-SECRET_KEY = os.environ.get("SECRET_KEY", "".join(random.choice(string.printable) for i in range(40))) | |
+SECRET_KEY = os.environ.get("SECRET_KEY", uuid.uuid4()) | |
DEBUG = os.environ.get("DEBUG", False) | |
# Application definition | |
@@ -55,7 +55,16 @@ TEMPLATES = ( | |
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases | |
DATABASES = { | |
- 'default': dj_database_url.config(default="postgres:///channels-example", conn_max_age=500) | |
+ # 'default': dj_database_url.config(default="postgres:///channels-example", | |
+ # conn_max_age=500) | |
+ 'default': { | |
+ 'ENGINE': 'django.db.backends.postgresql_psycopg2', | |
+ 'NAME': os.environ.get('POSTGRES_DB', 'postgres'), | |
+ 'USER': os.environ.get('POSTGRES_USER', 'postgres'), | |
+ 'PASSWORD': os.environ.get('POSTGRES_PASSWORD'), | |
+ 'HOST': os.environ.get('POSTGRES_HOST', 'localhost'), | |
+ 'PORT': os.environ.get('POSTGRES_PORT', ''), | |
+ } | |
} | |
AUTH_PASSWORD_VALIDATORS = ( | |
@@ -130,4 +139,4 @@ LOGGING = { | |
'level': 'DEBUG', | |
}, | |
}, | |
-} | |
\ No newline at end of file | |
+} | |
diff --git a/docker-compose.yml b/docker-compose.yml | |
new file mode 100644 | |
index 0000000..092ddbd | |
--- /dev/null | |
+++ b/docker-compose.yml | |
@@ -0,0 +1,35 @@ | |
+version: '2' | |
+services: | |
+ postgres: | |
+ image: postgres | |
+ environment: | |
+ - POSTGRES_PASSWORD=password | |
+ | |
+ redis: | |
+ image: redis | |
+ | |
+ web: | |
+ build: . | |
+ command: daphne chat.asgi:channel_layer --port 8000 --bind 0.0.0.0 -v2 | |
+ ports: | |
+ - 8000:8000 | |
+ links: | |
+ - postgres | |
+ - redis | |
+ environment: | |
+ - PYTHONUNBUFFERED=1 | |
+ - POSTGRES_HOST=postgres | |
+ - POSTGRES_PASSWORD=password | |
+ - REDIS_URL=redis://redis:6379 | |
+ | |
+ worker: | |
+ build: . | |
+ command: python manage.py runworker -v2 | |
+ links: | |
+ - postgres | |
+ - redis | |
+ environment: | |
+ - PYTHONUNBUFFERED=1 | |
+ - POSTGRES_HOST=postgres | |
+ - POSTGRES_PASSWORD=password | |
+ - REDIS_URL=redis://redis:6379 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment