Skip to content

Commit

Permalink
Docker-compose setup
Browse files Browse the repository at this point in the history
- Externalise requirements to pip format
- Add entry-point script
- Update Travis-CI configuration
- Fix test data
  • Loading branch information
dbuxton authored and JeanFred committed Sep 20, 2016
1 parent b72864e commit 27f65a2
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 83 deletions.
38 changes: 13 additions & 25 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
language: python

python:
- "2.7"

sudo: required
services:
- redis-server
- docker

env:
COMPOSE_VERSION: 1.8.0

# install deps
install:
- sudo apt-get update
- sudo apt-get install -y python-software-properties
- sudo apt-get install gcc python-dev git python-pip libpq-dev npm rubygems
-
- sudo npm install -g coffee-script [email protected] --registry http://registry.npmjs.org/
- gem install foreman
-
- sudo pip install virtualenv
- sudo virtualenv venv
- sudo ./venv/bin/pip install --upgrade setuptools
- CABOT_PLUGINS_ENABLED=cabot_alert_hipchat,cabot_alert_twilio,cabot_alert_email
- sudo ./venv/bin/pip install --timeout=30 --exists-action=w -e . --no-use-wheel
before_install:
- curl -L https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin

# setup databases
before_script:
- cp conf/development.env.example conf/development.env
- cp conf/production.env.example conf/production.env
- . venv/bin/activate
- foreman run python manage.py syncdb --migrate --noinput
- docker-compose build
- docker-compose up -d
- sleep 20

# tests
script:
- foreman run python manage.py test cabot
- docker-compose run web python manage.py test cabot
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM python:2.7

ENV PYTHONUNBUFFERED 1

RUN mkdir /code

WORKDIR /code

RUN apt-get update && apt-get install -y \
python-dev \
libsasl2-dev \
libldap2-dev \
libpq-dev \
npm

RUN npm install -g \
--registry http://registry.npmjs.org/ \
coffee-script \
[email protected]

RUN ln -s `which nodejs` /usr/bin/node

RUN pip install --upgrade pip

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY requirements-plugins.txt ./
RUN pip install --no-cache-dir -r requirements-plugins.txt

RUN pip install ipdb

ADD . /code/

ENTRYPOINT ["./docker-entrypoint.sh"]
30 changes: 15 additions & 15 deletions cabot/cabotapp/tests/tests_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,11 @@ def setUp(self):
'name': u'Service',
'users_to_notify': [],
'alerts_enabled': True,
'status_checks': [1, 2, 3],
'status_checks': [5, 6, 7],
'alerts': [],
'hackpad_id': None,
'instances': [],
'id': 1,
'id': 2,
'url': u'',
'overall_status': u'PASSING'
},
Expand All @@ -550,11 +550,11 @@ def setUp(self):
'name': u'Hello',
'users_to_notify': [],
'alerts_enabled': True,
'status_checks': [4],
'status_checks': [8],
'alerts': [],
'hackpad_id': None,
'address': u'192.168.0.1',
'id': 1,
'id': 2,
'overall_status': u'PASSING'
},
],
Expand All @@ -565,7 +565,7 @@ def setUp(self):
'importance': u'ERROR',
'frequency': 5,
'debounce': 0,
'id': 1,
'id': 5,
'calculated_status': u'passing',
},
{
Expand All @@ -574,7 +574,7 @@ def setUp(self):
'importance': u'ERROR',
'frequency': 5,
'debounce': 0,
'id': 2,
'id': 6,
'calculated_status': u'passing',
},
{
Expand All @@ -583,7 +583,7 @@ def setUp(self):
'importance': u'CRITICAL',
'frequency': 5,
'debounce': 0,
'id': 3,
'id': 7,
'calculated_status': u'passing',
},
{
Expand All @@ -592,7 +592,7 @@ def setUp(self):
'importance': u'ERROR',
'frequency': 5,
'debounce': 0,
'id': 4,
'id': 8,
'calculated_status': u'passing',
},
],
Expand All @@ -608,7 +608,7 @@ def setUp(self):
'value': u'9.0',
'expected_num_hosts': 0,
'allowed_num_failures': 0,
'id': 1,
'id': 5,
'calculated_status': u'passing',
},
],
Expand All @@ -626,7 +626,7 @@ def setUp(self):
'status_code': u'200',
'timeout': 10,
'verify_ssl_certificate': True,
'id': 3,
'id': 7,
'calculated_status': u'passing',
},
],
Expand All @@ -638,7 +638,7 @@ def setUp(self):
'frequency': 5,
'debounce': 0,
'max_queued_build_time': 10,
'id': 2,
'id': 6,
'calculated_status': u'passing',
},
],
Expand All @@ -649,7 +649,7 @@ def setUp(self):
'importance': u'ERROR',
'frequency': 5,
'debounce': 0,
'id': 4,
'id': 8,
'calculated_status': u'passing',
},
],
Expand Down Expand Up @@ -768,7 +768,7 @@ def test_gets(self):
def test_posts(self):
for model, items in self.post_data.items():
for item in items:
# hackpad_id and other null text fields omitted on create
# hackpad_id and other null text fields omitted on create
# for now due to rest_framework bug:
# https://github.com/tomchristie/django-rest-framework/issues/1879
# Update: This has been fixed in master:
Expand All @@ -786,7 +786,7 @@ def test_posts(self):
item[field] = None
self.assertEqual(self.normalize_dict(create_response.data), item)
get_response = self.client.get(api_reverse('{}-detail'.format(model), args=[item['id']]),
format='json', HTTP_AUTHORIZATION=self.basic_auth)
format='json', HTTP_AUTHORIZATION=self.basic_auth)
self.assertEqual(self.normalize_dict(get_response.data), item)

class TestAPIFiltering(LocalTestCase):
Expand Down Expand Up @@ -901,7 +901,7 @@ def setUp(self):

def test_users_to_notify(self):
self.assertEqual(self.service.users_to_notify.all().count(), 1)
self.assertEqual(self.service.users_to_notify.get(pk=1).username, self.user.username)
self.assertEqual(self.service.users_to_notify.get().username, self.user.username)

@patch('cabot.cabotapp.models.send_alert')
def test_alert(self, fake_send_alert):
Expand Down
6 changes: 3 additions & 3 deletions conf/development.env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Plugins to be loaded at launch
CABOT_PLUGINS_ENABLED=cabot_alert_hipchat==1.7.0,cabot_alert_twilio==1.6.1,cabot_alert_email==1.3.1
CABOT_PLUGINS_ENABLED=cabot_alert_hipchat==1.7.0,cabot_alert_twilio==1.1.4,cabot_alert_email==1.3.1

DEBUG=t
DATABASE_URL=sqlite:///dev.db
DATABASE_URL=postgres://postgres@db:5432/postgres
DJANGO_SETTINGS_MODULE=cabot.settings
HIPCHAT_URL=https://api.hipchat.com/v1/rooms/message
LOG_FILE=/dev/null
Expand All @@ -22,7 +22,7 @@ [email protected]
CALENDAR_ICAL_URL=http://www.google.com/calendar/ical/example.ics

# Django settings
CELERY_BROKER_URL=redis://localhost:6379/1
CELERY_BROKER_URL=redis://redis:6379/1
DJANGO_SECRET_KEY=2FL6ORhHwr5eX34pP9mMugnIOd3jzVuT45f7w430Mt5PnEwbcJgma0q8zUXNZ68A

# Hostname of your Graphite server instance
Expand Down
32 changes: 32 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '2'
services:
web:
env_file:
- conf/development.env
build: .
image: cabot:web
command: python manage.py runserver 0.0.0.0:5001
ports:
- "5001:5001"
volumes:
- .:/code
links:
- redis
- db

worker:
env_file:
- conf/development.env
image: cabot:web
command: python manage.py celery worker -B -A cabot --loglevel=DEBUG --concurrency=16 -Ofair
volumes:
- .:/code
links:
- redis
- db

redis:
image: redis

db:
image: postgres
23 changes: 23 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -e

# first check if we're passing flags, if so
# prepend with sentry
if [ "${1:0:1}" = '-' ]; then
set -- python manage.py "$@"
fi

case "$1" in
"web")
set -- gunicorn cabot.wsgi:application --config gunicorn.conf
;;
"beatworker")
set -- celery worker -B -A cabot --loglevel=INFO --concurrency=16 -Ofair
;;
"worker")
set -- celery worker -A cabot --loglevel=INFO --concurrency=16 -Ofair
;;
esac

exec "$@"
3 changes: 3 additions & 0 deletions requirements-plugins.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cabot_alert_email==1.3.1
cabot_alert_hipchat==1.7.0
cabot_alert_twilio==1.1.4
32 changes: 32 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Django==1.6.11
Markdown==2.5
PyJWT==0.1.2
South==1.0
amqp>=1.4.9
anyjson==0.3.3
argparse==1.2.1
celery[redis]==3.1.23
dj-database-url==0.2.2
django-appconf==0.6
django-celery==3.1.17
django-compressor==1.4
django-filter==0.7
django-jsonify==0.2.1
django-mptt==0.6.0
django-polymorphic==0.5.6
django-redis==1.4.5
django-smtp-ssl==1.0
djangorestframework==2.4.2
gunicorn==18.0
gevent==1.0.1
httplib2==0.7.7
icalendar==3.2
mock==1.0.1
psycogreen==1.0
psycopg2==2.5.1
pytz==2014.10
requests==2.7.0
twilio==3.4.1
wsgiref==0.1.2
python-dateutil==2.1
django-auth-ldap==1.2.6
48 changes: 8 additions & 40 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#!/usr/bin/env python
import os
from setuptools import setup, find_packages
from os import environ as env

requirements_file = os.path.join(os.path.dirname(__file__), 'requirements.txt')
with open(requirements_file) as f:
requirements = [line.rstrip('\n')
for line in f
if line and not line.startswith('#')]

# pull in active plugins
plugins = env['CABOT_PLUGINS_ENABLED'].split(',') if 'CABOT_PLUGINS_ENABLED' in env else ["cabot_alert_hipchat", "cabot_alert_twilio", "cabot_alert_email"]

Expand All @@ -15,46 +22,7 @@
author_email='[email protected]',
url='http://cabotapp.com',
license='MIT',
install_requires=[
'Django==1.6.8',
'Markdown==2.5',
'PyJWT==0.1.2',
'South==1.0',
'amqp==1.4.9',
'anyjson==0.3.3',
'argparse==1.2.1',
'billiard==3.3.0.23',
'celery==3.1.23',
'distribute==0.7.3',
'dj-database-url==0.2.2',
'django-appconf==0.6',
'django-celery==3.1.1',
'django-celery-with-redis==3.0',
'django-compressor==1.4',
'django-filter==0.7',
'django-jsonify==0.2.1',
'django-polymorphic==0.5.6',
'django-redis==1.4.5',
'django-smtp-ssl==1.0',
'djangorestframework==2.4.2',
'gunicorn==18.0',
'gevent==1.0.1',
'hiredis==0.1.1',
'httplib2==0.7.7',
'icalendar==3.2',
'kombu==3.0.34',
'mock==1.0.1',
'psycogreen==1.0',
'psycopg2==2.5.1',
'pytz==2014.10',
'redis==2.9.0',
'requests==2.9.1',
'six==1.5.1',
'twilio==3.4.1',
'wsgiref==0.1.2',
'python-dateutil==2.1',
'django-auth-ldap==1.2.6',
] + plugins,
install_requires=requirements + plugins,
packages=find_packages(),
include_package_data=True,
zip_safe=False,
Expand Down

0 comments on commit 27f65a2

Please sign in to comment.