Skip to content

Commit

Permalink
Merge pull request wooey#233 from wooey/add-docker
Browse files Browse the repository at this point in the history
Docker setup with some test fixes
  • Loading branch information
Chris7 authored Apr 8, 2018
2 parents d55a92b + 9f06acc commit b2e27f8
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ target/

# IDE
.idea

# Template files
docker/docker-compose.override.yml
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ testenv:
pip install sphinx mock

test:
-rm -r test_project
wooify -p test_project
nosetests --with-coverage --cover-erase --cover-package=wooey tests
nosetests --with-coverage --cover-erase --cover-branches --cover-package=wooey tests/*
coverage run --append --branch --source=wooey `which django-admin.py` test --settings=wooey.test_settings wooey.tests
coverage report
coverage report --omit='*migrations*','*wooey_scripts*','*tests/scripts*','*conf/*'

.PHONY: docs
docs:
Expand Down
35 changes: 35 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM python:2.7

ENV BUILD_DIR=/wooey_build

RUN pip install psycopg2

COPY setup.py requirements.txt MANIFEST.in Makefile README.md ${BUILD_DIR}/
COPY scripts ${BUILD_DIR}/scripts
COPY wooey ${BUILD_DIR}/wooey
COPY tests ${BUILD_DIR}/tests

WORKDIR ${BUILD_DIR}

RUN pip install -r requirements.txt
RUN pip install -e .

RUN chmod -R a+rwx ${BUILD_DIR}

WORKDIR /
ARG WOOEY_PROJECT=docker_wooey

RUN wooify -p ${WOOEY_PROJECT}

WORKDIR ${WOOEY_PROJECT}

COPY docker/scripts/run-server run-server

# Make volumes and make sure the wooey directory is r/w by all. By default,
# docker will create volumes as root so this is needed.
RUN mkdir ${WOOEY_PROJECT}/user_uploads && \
chmod -R a+rwx /${WOOEY_PROJECT}

EXPOSE 8080

CMD ["sh", "-c", "make -C ${BUILD_DIR} test"]
2 changes: 2 additions & 0 deletions docker/celery
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
./wooey-compose run --rm --service-ports celery "$@"
11 changes: 11 additions & 0 deletions docker/docker-compose.override.template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file should be renamed to docker-compose.overrides.yml with whatever
# overrides are specific to the particular setup
version: '2.1'

services:
wooey:
volumes:
- ../wooey:/docker_wooey/wooey
- ../../clinto/clinto:/usr/local/lib/python3.6/site-packages/clinto
ports:
- 8080:8080
46 changes: 46 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
version: '2.1'
volumes:
user_uploads:
wooey_db:

services:
common:
build:
context: ..
dockerfile: docker/Dockerfile
image: wooey:dev
volumes :
- ./user_settings.py:/docker_wooey/docker_wooey/settings/user_settings.py
- user_uploads:/docker_wooey/docker_wooey/user_uploads
environment:
AMQP_URL: amqp://rabbit:5672
DATABASE_NAME: wooey
DATABASE_USER: wooey
DATABASE_URL: db
DATABASE_PASSWORD: wooey
user: 1000:1000

wooey:
extends: common
ports:
- 8081:8080
depends_on:
- rabbit
- db
command: ./run-server

celery:
extends: common
command: celery worker -A docker_wooey -c 4 --beat -l info -s schedule

rabbit:
image: rabbitmq

db:
image: postgres
volumes:
- wooey_db:/var/lib/postgresql/data
environment:
POSTGRES_USER: wooey
POSTGRES_PASSWORD: wooey
POSTGRES_DB: wooey
2 changes: 2 additions & 0 deletions docker/manage
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
./wooey-compose run --rm wooey python manage.py "$@"
2 changes: 2 additions & 0 deletions docker/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
./wooey-compose run --rm wooey "$@"
2 changes: 2 additions & 0 deletions docker/run-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
./wooey-compose run --rm --service-ports wooey "$@"
4 changes: 4 additions & 0 deletions docker/scripts/run-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
python manage.py migrate
python manage.py collectstatic -c --noinput
python manage.py runserver 0.0.0.0:8080
Empty file added docker/test.sh
Empty file.
52 changes: 52 additions & 0 deletions docker/user_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os
from .wooey_settings import *

# Whether to allow anonymous job submissions, set False to disallow 'guest' job submissions
WOOEY_ALLOW_ANONYMOUS = True

## Celery related options
INSTALLED_APPS += (
'django_celery_results',
)

WOOEY_CELERY = True
CELERY_RESULT_BACKEND = 'django-db'
CELERY_BROKER_URL = 'amqp://guest@rabbit'
CELERY_TRACK_STARTED = True
CELERY_SEND_EVENTS = True
CELERY_IMPORTS = ('wooey.tasks')
CELERY_TASK_SERIALIZER = 'json'
CELERY_TASK_ACKS_LATE = True

# the directory for uploads (physical directory)
MEDIA_ROOT = os.path.join(BASE_DIR, 'user_uploads')
# the url mapping
MEDIA_URL = '/uploads/'

# the directory to store our webpage assets (images, javascript, etc.)
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# the url mapping
STATIC_URL = '/static/'
## Here is a setup example for production servers

## A postgres database -- for multiple users a sqlite based database is asking for trouble

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
# for production environments, these should be stored as environment variables
# I also recommend the django-heroku-postgresify package for a super simple setup
'NAME': os.environ.get('DATABASE_NAME', 'wooey'),
'USER': os.environ.get('DATABASE_USER', 'wooey'),
'PASSWORD': os.environ.get('DATABASE_PASSWORD', 'wooey'),
'HOST': os.environ.get('DATABASE_URL', 'localhost'),
'PORT': os.environ.get('DATABASE_PORT', '5432')
}
}

ALLOWED_HOSTS = (
'localhost',
'127.0.0.1',
)

AUTHENTICATION_BACKEND = 'django.contrib.auth.backends.ModelBackend'
2 changes: 2 additions & 0 deletions docker/wooey-compose
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker-compose -p wooey "$@"
11 changes: 6 additions & 5 deletions wooey/conf/project_template/settings/user_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
'kombu.transport.filesystem',
)

# This stores the results of tasks. For larger sites, a database may become slow and other solutions
# such as redis should be considered.
CELERY_RESULT_BACKEND = 'django-db'

# This should absolutely be changed to a non-filesystem based broker for production deployments!
Expand Down Expand Up @@ -86,15 +88,14 @@ def ensure_path(path):
# }
# }

## A better celery backend -- using RabbitMQ (these defaults are from two free rabbitmq Heroku providers)
# CELERY_RESULT_BACKEND = 'amqp'
# BROKER_URL = os.environ.get('AMQP_URL') or \
## A better celery broker -- using RabbitMQ (these defaults are from two free rabbitmq Heroku providers)
# CELERY_BROKER_URL = os.environ.get('AMQP_URL') or \
# os.environ.get('RABBITMQ_BIGWIG_TX_URL') or \
# os.environ.get('CLOUDAMQP_URL', 'amqp://guest:guest@localhost:5672/')
# BROKER_POOL_LIMIT = 1
# CELERY_BROKER_POOL_LIMIT = 1
# CELERYD_CONCURRENCY = 1
# CELERY_TASK_SERIALIZER = 'json'
# ACKS_LATE = True
# CELERY_TASK_ACKS_LATE = True
#

## for production environments, django-storages abstracts away much of the difficulty of various storage engines.
Expand Down

0 comments on commit b2e27f8

Please sign in to comment.