Skip to content

Commit

Permalink
Add default.env and test.env and multiple docker-compose files to ove…
Browse files Browse the repository at this point in the history
…rride settings
  • Loading branch information
frankh committed Feb 13, 2017
1 parent 2f79bc5 commit ec5f682
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ before_script:

script:
- tox
- docker-compose run --rm web bash bin/test_with_coverage
- docker-compose run --rm -e SKIP_INIT=1 -e DATABASE_URL='sqlite://:memory:' web bash bin/test_with_coverage -v2
- docker-compose run --rm -e CABOT_SUPERUSER_USERNAME='admin' -e CABOT_SUPERUSER_PASSWORD='pass' web true

after_success:
Expand Down
3 changes: 2 additions & 1 deletion cabot/celeryconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
BROKER_URL = os.environ['CELERY_BROKER_URL']
# Set environment variable if you want to run tests without a redis instance
CELERY_ALWAYS_EAGER = os.environ.get('CELERY_ALWAYS_EAGER', False)
CELERY_RESULT_BACKEND = os.environ.get('CELERY_RESULT_BACKEND', None)
CELERY_IMPORTS = ('cabot.cabotapp.tasks', )
CELERYBEAT_SCHEDULER = "djcelery.schedulers.DatabaseScheduler"
CELERY_TASK_SERIALIZER = "json"
Expand All @@ -22,7 +23,7 @@
},
'clean-db': {
'task': 'cabot.cabotapp.tasks.clean_db',
'schedule': timedelta(seconds=60*60*24),
'schedule': timedelta(seconds=60 * 60 * 24),
},
}

Expand Down
74 changes: 74 additions & 0 deletions conf/default.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Plugins to be loaded at launch
CABOT_PLUGINS_ENABLED=cabot_alert_hipchat==1.8.3,cabot_alert_twilio==1.2.0,cabot_alert_email==1.4.3

DEBUG=t
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
PORT=5001

# You shouldn't need to change anything above this line

# Base path to include before generated URLs. If not defined, uses `/`
# URL_PREFIX=/

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
TIME_ZONE=Etc/UTC

# URL of calendar to synchronise rota with
CALENDAR_ICAL_URL=http://www.google.com/calendar/ical/example.ics

# Django settings
CELERY_BROKER_URL=redis://redis:6379/1

# From parameter for the graphite request. If not defined, by default take -10 minutes
# GRAPHITE_FROM=-10minute

# User-Agent string used for HTTP checks
HTTP_USER_AGENT=Cabot

# Used for pointing links back in alerts etc.
WWW_HTTP_HOST=localhost
WWW_SCHEME=http

# OPTIONAL SETTINGS
#
# # Django admin email
# ADMIN_EMAIL=you@example.com
# CABOT_FROM_EMAIL=cabot@example.com
#
# DJANGO_SECRET_KEY=
#
# Hostname of your Graphite server instance
GRAPHITE_API=http://graphite.example.com/
GRAPHITE_USER=username
GRAPHITE_PASS=password

# Hipchat integration
HIPCHAT_ALERT_ROOM=48052
HIPCHAT_API_KEY=your_hipchat_api_key

# Jenkins integration
JENKINS_API=https://jenkins.example.com/
JENKINS_USER=username
JENKINS_PASS=password

# SMTP settings
SES_HOST=email-smtp.us-east-1.amazonaws.com
SES_USER=username
SES_PASS=password
SES_PORT=465

# Twilio integration for SMS and telephone alerts
TWILIO_ACCOUNT_SID=your_account_sid
TWILIO_AUTH_TOKEN=your_auth_token
TWILIO_OUTGOING_NUMBER=+14155551234

# Use for LDAP authentication
AUTH_LDAP=true
AUTH_LDAP_SERVER_URI=ldap://ldap.example.com
AUTH_LDAP_BIND_DN="cn=Manager,dc=example,dc=com"
AUTH_LDAP_BIND_PASSWORD=""
AUTH_LDAP_USER_SEARCH="ou=People,dc=example,dc=com"
7 changes: 7 additions & 0 deletions conf/test.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DATABASE_URL=sqlite://:memory:

CELERY_BROKER_URL=sqla+sqlite://:memory:
CELERY_RESULT_BACKEND=db+sqlite://:memory:
CELERY_ALWAYS_EAGER=true

SKIP_INIT=true
10 changes: 10 additions & 0 deletions docker-compose-base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '2'
services:
base:
build: .
image: cabot:web
command: "false"
volumes:
- .:/code
env_file:
- conf/default.env
35 changes: 35 additions & 0 deletions docker-compose-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '2'
services:
base:
extends:
file: docker-compose-base.yml
service: base
env_file:
- conf/production.env

web:
extends: base
command: gunicorn cabot.wsgi:application --config gunicorn.conf
links:
- redis
- db

worker:
extends: base
command: python manage.py celery worker -A cabot --loglevel=DEBUG --concurrency=16 -Ofair
links:
- redis
- db

beat:
extends: base
command: python manage.py celery beat -A cabot --loglevel=DEBUG
links:
- redis
- db

redis:
image: redis

db:
image: postgres
9 changes: 9 additions & 0 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '2'
services:
test:
extends:
file: docker-compose-base.yml
service: base
command: python manage.py test -v2
env_file:
- conf/test.env
48 changes: 28 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
version: '2'
services:
web:
extends:
file: docker-compose-base.yml
service: base
env_file:
- conf/development.env
build: .
image: cabot:web
- conf/development.env
environment:
- CABOT_SUPERUSER_USERNAME=admin
- CABOT_SUPERUSER_PASSWORD=pass
command: python manage.py runserver 0.0.0.0:5001
ports:
- "5001:5001"
volumes:
- .:/code
- "5000:5000"
links:
- redis
- db
- redis
- db

worker:
extends:
file: docker-compose-base.yml
service: base
env_file:
- conf/development.env
image: cabot:web
- conf/development.env
command: python manage.py celery worker -A cabot --loglevel=DEBUG --concurrency=16 -Ofair
volumes:
- .:/code
environment:
- SKIP_INIT=1
- WAIT_FOR_MIGRATIONS=1
links:
- redis
- db
- redis
- db

beat:
extends:
file: docker-compose-base.yml
service: base
env_file:
- conf/development.env
image: cabot:web
- conf/development.env
command: python manage.py celery beat -A cabot --loglevel=DEBUG
volumes:
- .:/code
environment:
- SKIP_INIT=1
- WAIT_FOR_MIGRATIONS=1
links:
- redis
- db
- redis
- db

redis:
image: redis
Expand Down
14 changes: 13 additions & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash
set -e
set -o allexport

function wait_for_broker {(
set +e
Expand All @@ -20,6 +19,15 @@ function wait_for_database {(
done
)}

function wait_for_migrations {(
set +e
for try in {1..60} ; do
python manage.py migrate --list | grep "\[ \]" &> /dev/null || break
echo "Waiting for database migrations to be run..."
sleep 1
done
)}


wait_for_broker
wait_for_database
Expand All @@ -28,4 +36,8 @@ if [ -z "$SKIP_INIT" ]; then
/code/bin/build-app
fi

if [ -n "$WAIT_FOR_MIGRATIONS" ]; then
wait_for_migrations
fi

exec "$@"
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ django-mptt==0.6.0
django-polymorphic==0.7.2
django-smtp-ssl==1.0
djangorestframework==2.4.8
gunicorn==18.0
gunicorn==19.6.0
gevent==1.0.1
httplib2==0.7.7
icalendar==3.2
Expand All @@ -30,3 +30,4 @@ twilio==3.4.1
wsgiref==0.1.2
python-dateutil==2.1
django-auth-ldap==1.2.6
sqlalchemy==1.1.5

0 comments on commit ec5f682

Please sign in to comment.