From 4a2e61c0008d6702817e7926780884d683a257fa Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Sat, 14 Mar 2015 02:35:01 +0100 Subject: [PATCH] Add a rabbitmq broker and a celery worker (now builing with "docker-compose up") --- docker-compose.yml | 58 ++++++++++++++++++++++++---------- examples/deploy/celery_app.sh | 17 ++++++++++ examples/deploy/start_app.sh | 5 +-- examples/sandbox/celery_app.py | 6 ++-- examples/sandbox/settings.py | 14 ++++---- 5 files changed, 71 insertions(+), 29 deletions(-) create mode 100644 examples/deploy/celery_app.sh diff --git a/docker-compose.yml b/docker-compose.yml index 5067dfe..73d1bb1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,29 +18,26 @@ log: - /var/log/uwsgi command: /bin/true -# datadb: -# image: debian:wheezy -# volumes: -# - /var/lib/postgresql -# command: /bin/true +lib: + image: debian:wheezy + volumes: + - /var/lib/rabbitmq + - /var/lib/postgres + - /var/lib/mysql + command: /bin/true + # db: # image: postgres # volumes_from: # - datadb -nginx: - image: nginx +rabbitmq: + image: rabbitmq:3-management ports: - - "8000:80" - volumes: - - ./examples/deploy/nginx-app.conf:/etc/nginx/conf.d/default.conf - volumes_from: - - static - - home - - log - links: - - app + - "15672:15672" + expose: + - "5672" app: build: . @@ -54,4 +51,31 @@ app: ports: - "9000:9000" expose: - - "80" #default runserver wsgi port \ No newline at end of file + - "8000" #default runserver wsgi port + links: + - rabbitmq + +worker: + image: parisson/timeside + volumes: + - .:/opt/TimeSide + volumes_from: + - home + command: /bin/sh /opt/TimeSide/examples/deploy/celery_app.sh + links: + - rabbitmq + - app + +nginx: + image: nginx + ports: + - "8000:80" + volumes: + - ./examples/deploy/nginx-app.conf:/etc/nginx/conf.d/default.conf + volumes_from: + - static + - home + - log + links: + - app + diff --git a/examples/deploy/celery_app.sh b/examples/deploy/celery_app.sh new file mode 100644 index 0000000..f92c6df --- /dev/null +++ b/examples/deploy/celery_app.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +# paths +app_dir='/opt/TimeSide/' +sandbox_dir='/home/timeside/' +manage=$sandbox_dir'manage.py' + +# cp -uR /opt/TimeSide/examples/sandbox/* /home/timeside/ + +echo "YYYYYYYYYYYYYY" + +pip install django-celery + +python $manage migrate --noinput + +# run Celery worker for our project myproject with Celery configuration stored in Celeryconf +su -c "$manage celery worker -A celery_app" diff --git a/examples/deploy/start_app.sh b/examples/deploy/start_app.sh index 79c34f8..0a01c21 100644 --- a/examples/deploy/start_app.sh +++ b/examples/deploy/start_app.sh @@ -11,6 +11,9 @@ app_static_dir=$app_dir'timeside/player/static/' #  this is not needed for TimeSide but for Timeside-diadems cp -uR /opt/TimeSide/examples/sandbox/* /home/timeside/ +# add some staging modules +pip install watchdog django-celery + # django init python $manage syncdb --noinput python $manage migrate --noinput @@ -18,8 +21,6 @@ python $manage collectstatic --noinput python $manage timeside-create-admin-user # static files auto update -pip install watchdog - watchmedo shell-command --patterns="*.js;*.css" --recursive \ --command='python '$manage' collectstatic --noinput' $app_static_dir & diff --git a/examples/sandbox/celery_app.py b/examples/sandbox/celery_app.py index f558ac7..7e9d7f8 100644 --- a/examples/sandbox/celery_app.py +++ b/examples/sandbox/celery_app.py @@ -15,9 +15,9 @@ app = Celery('sandbox') # pickle the object when using Windows. app.config_from_object('django.conf:settings') app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) -app.conf.update( - CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend', -) +# app.conf.update( +# CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend', +# ) @app.task(bind=True) def debug_task(self): diff --git a/examples/sandbox/settings.py b/examples/sandbox/settings.py index 66c666f..7254d78 100644 --- a/examples/sandbox/settings.py +++ b/examples/sandbox/settings.py @@ -27,7 +27,7 @@ DATABASES = { # Hosts/domain names that are valid for this site; required if DEBUG is False # See https://docs.djangoproject.com/en/1.4/ref/settings/#allowed-hosts -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['*'] # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'ghv8us2587n97dq&w$c((o5rj_$-9#d-8j#57y_a9og8wux1h7' @@ -174,10 +174,10 @@ REST_FRAMEWORK = { # One or more gearman servers # GEARMAN_SERVERS = ['127.0.0.1'] -BROKER_URL = 'amqp://guest:guest@localhost//' +BROKER_URL = 'amqp://guest:guest@rabbitmq//' +CELERY_IMPORTS = ("timeside.server.tasks",) +CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend' +CELERY_TASK_SERIALIZER = "json" +CELERY_ACCEPT_CONTENT = ['application/json'] - -# This will make sure the app is always imported when -# Django starts so that shared_task will use this app. -CELERY_IMPORTS = ("timeside.server.tasks", ) -from celery_app import app +from celery_app import app \ No newline at end of file -- 2.39.5