Skip to content

Commit

Permalink
Add docker support (#359)
Browse files Browse the repository at this point in the history
* Initial Dockerfile and entrypoints for docker-compose

* Fix building dockerfile.

* Add docker-compose.

* Add settings_local.py

* Rename silver image.

* Add drone file.

* Run test with mysql.

* Make tests run on sqllite.
  • Loading branch information
vtemian authored and AMecea committed Nov 16, 2016
1 parent 46468a5 commit d28e8b5
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 7 deletions.
21 changes: 15 additions & 6 deletions .drone.yml
@@ -1,5 +1,16 @@
build:
image: python:2.7
image: presslabs/silver
pull: true
auth_config:
username: presslabsbot
password: $$DOCKER_PASSWORD
email: ping@presslabs.com
environment:
- SILVER_DB_ENGINE=django.db.backends.mysql
- SILVER_DB_NAME=test_db
- SILVER_DB_HOST=127.0.0.1
- SILVER_DB_USER=silver
- SILVER_DB_PASSWORD=silver
commands:
- pip install -U -r requirements/test.txt
- mkdir /var/log/silver && python manage.py test -v2
Expand All @@ -9,8 +20,6 @@ compose:
image: mysql:5.5
environment:
- MYSQL_DATABASE=test_db

cache:
mount:
- /root/.cache/pip
- /usr/local/lib/python2.7/site-packages
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_USER=silver
- MYSQL_PASSWORD=silver
46 changes: 46 additions & 0 deletions Dockerfile
@@ -0,0 +1,46 @@
FROM python:2.7.11-alpine
MAINTAINER Presslabs ping@presslabs.com

# Ensure that Python outputs everything that's printed inside
# the application rather than buffering it, maily for logging purposes
ENV PYTHONUNBUFFERED 1

# Set default django settings module
ENV DJANGO_SETTINGS_MODULE settings_local

# silver app runs on port 8080
EXPOSE 8080

RUN set -ex && mkdir -p /silver
WORKDIR /silver

# Install silver
COPY ./requirements /silver/requirements

RUN set -ex \
&& apk update \
&& apk add --no-cache \
mariadb-client-libs \
libjpeg-turbo \
jpeg \
zlib \
ca-certificates wget \
openssl \
&& apk add --no-cache --virtual .build-deps \
build-base \
mariadb-dev \
jpeg-dev \
zlib-dev \
&& update-ca-certificates \
&& pip install --no-cache-dir -r requirements/common.txt \
&& pip install --no-cache-dir gunicorn==19.4.5 \
&& pip install --no-cache-dir mysql-python \
&& apk del .build-deps \
&& wget -qO- https://github.com/jwilder/dockerize/releases/download/v0.2.0/dockerize-linux-amd64-v0.2.0.tar.gz | tar -zxf - -C /usr/bin \
&& chown root:root /usr/bin/dockerize

COPY ./ /silver

VOLUME /silver

CMD ["/docker-entrypoint"]
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -13,6 +13,6 @@ lint-python:
@echo ""

test:
@DJANGO_SETTINGS_MODULE=settings PYTHONPATH=`pwd` py.test -s
@DJANGO_SETTINGS_MODULE=settings PYTHONPATH=`pwd` py.test -s

.PHONY: develop setup-git lint-python test
5 changes: 5 additions & 0 deletions docker-compose.env
@@ -0,0 +1,5 @@
SILVER_DB_ENGINE=django.db.backends.mysql
SILVER_DB_NAME=silver
SILVER_DB_HOST=db
SILVER_MIGRATE=yes
SILVER_LOAD_DEV_DATA=yes
18 changes: 18 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,18 @@
version: '2'
services:
silver:
image: presslabs/silver:latest
command: dockerize -wait tcp://db:3306 -timeout 30s /silver/docker-entrypoint
env_file: ./docker-compose.env
ports:
- "8080:8080"
volumes:
- .:/silver

db:
image: mysql:5.5
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: silver
MYSQL_USER: silver
MYSQL_PASSWORD: password
13 changes: 13 additions & 0 deletions docker-entrypoint
@@ -0,0 +1,13 @@
#!/bin/sh
set -e

if [ "$SILVER_MIGRATE" == "yes" ] ; then
/usr/local/bin/python2 /silver/manage.py migrate --noinput
fi

if [ "$SILVER_LOAD_DEV_DATA" == "yes" ] ; then
/usr/local/bin/python2 /silver/manage.py loaddata -i fixtures/initial_dev_data.json
fi

exec /usr/local/bin/python2 /silver/manage.py runserver 0.0.0.0:8080

1 change: 1 addition & 0 deletions settings.py
Expand Up @@ -20,6 +20,7 @@
These settings are used by the ``manage.py`` command.
"""

import os

DEBUG = False
Expand Down
43 changes: 43 additions & 0 deletions settings_local.py
@@ -0,0 +1,43 @@
import sys

from settings import *

DEBUG = True
TEMPLATE_DEBUG = True

DATABASES = {
'default': {
'ENGINE': os.getenv('SILVER_DB_ENGINE', 'django.db.backends.sqlite3'),
'NAME': os.getenv('SILVER_DB_NAME', 'db.sqlite3'),
'USER': os.getenv('SILVER_DB_USER', 'silver'),
'PASSWORD': os.getenv('SILVER_DB_PASSWORD', 'password'),
'HOST': os.getenv('SILVER_DB_HOST', ''),
'PORT': os.getenv('SILVER_DB_PORT', '3306'),
'TEST': {
'CHARSET': 'utf8'
}
}
}

ALLOWED_HOSTS = ['127.0.0.1', 'localhost', '0.0.0.0']

if 'test' in sys.argv:
# faster tests
PASSWORD_HASHERS = [
'django.contrib.auth.hashers.MD5PasswordHasher',
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
'django.contrib.auth.hashers.BCryptPasswordHasher',
'django.contrib.auth.hashers.SHA1PasswordHasher',
'django.contrib.auth.hashers.CryptPasswordHasher',
]
DEBUG = False
TEMPLATE_DEBUG = False

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db.sqlite',
}
}

0 comments on commit d28e8b5

Please sign in to comment.