From a854e2916048c5012a4331c200c3943f6d54265b Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 19 Mar 2015 11:57:51 +0100 Subject: [PATCH] add a script for waiting available linked container ports, fix worker start --- docker-compose.yml | 24 ++++---- examples/deploy/celery_app.sh | 12 ++-- examples/deploy/start_app.sh | 16 ++--- examples/deploy/wait.sh | 18 ++++++ examples/sandbox/settings.py | 2 +- .../commands/telemeta-timeside-boilerplate.py | 61 +++++++++++++++++++ 6 files changed, 106 insertions(+), 27 deletions(-) create mode 100644 examples/deploy/wait.sh create mode 100644 telemeta/management/commands/telemeta-timeside-boilerplate.py diff --git a/docker-compose.yml b/docker-compose.yml index 6cb690e1..32c86058 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -47,7 +47,7 @@ lib: home: image: debian:wheezy volumes: - - ./examples/sandbox:/home/telemeta + - ./examples/sandbox:/home/sandbox command: /bin/true db: @@ -57,7 +57,7 @@ db: - log environment: - MYSQL_ROOT_PASSWORD=mysecretpassword - - MYSQL_DATABASE=telemeta + - MYSQL_DATABASE=sandbox - MYSQL_USER=root - MYSQL_PASSWORD=mysecretpassword @@ -68,15 +68,6 @@ rabbitmq: expose: - "5672" -worker: - build: . - volumes_from: - - home - command: /bin/sh /opt/Telemeta/examples/deploy/celery_app.sh - links: - - rabbitmq - - db - app: build: . volumes: @@ -93,7 +84,16 @@ app: links: - rabbitmq - db - - worker + +worker: + build: . + volumes_from: + - app + command: /bin/sh /opt/Telemeta/examples/deploy/celery_app.sh + links: + - rabbitmq + - db + - app nginx: image: nginx diff --git a/examples/deploy/celery_app.sh b/examples/deploy/celery_app.sh index a5752d42..ac1b1c76 100644 --- a/examples/deploy/celery_app.sh +++ b/examples/deploy/celery_app.sh @@ -1,14 +1,12 @@ #!/bin/sh # paths -app_dir='/opt/Telemeta/' -sandbox_dir='/home/telemeta/' -manage=$sandbox_dir'manage.py' +app='/opt/Telemeta/' +sandbox='/home/sandbox/' +manage=$sandbox'manage.py' +wsgi=$sandbox'wsgi.py' -python $manage syncdb --noinput -python $manage migrate --noinput -python $manage collectstatic --noinput -python $manage timeside-create-admin-user +sh $app/examples/deploy/wait.sh # Starting celery worker with the --autoreload option will enable the worker to watch for file system changes # This is an experimental feature intended for use in development only diff --git a/examples/deploy/start_app.sh b/examples/deploy/start_app.sh index 2b5deb56..a342403f 100644 --- a/examples/deploy/start_app.sh +++ b/examples/deploy/start_app.sh @@ -1,11 +1,13 @@ #!/bin/sh # paths -app_dir='/opt/Telemeta/' -sandbox_dir='/home/telemeta/' -manage=$sandbox_dir'manage.py' -wsgi=$sandbox_dir'wsgi.py' -app_static_dir=$app_dir'telemeta/static/' +app='/opt/Telemeta/' +static=$app'telemeta/static/' +sandbox='/home/sandbox/' +manage=$sandbox'manage.py' +wsgi=$sandbox'wsgi.py' + +sh $app/examples/deploy/wait.sh # django init python $manage syncdb --noinput @@ -17,7 +19,7 @@ python $manage telemeta-create-admin-user pip install watchdog watchmedo shell-command --patterns="*.js;*.css" --recursive \ - --command='python '$manage' collectstatic --noinput' $app_static_dir & + --command='python '$manage' collectstatic --noinput' $static & # app start -uwsgi --socket :8000 --wsgi-file $wsgi --chdir $sandbox_dir --master --processes 4 --threads 2 --py-autoreload 3 +uwsgi --socket :8000 --wsgi-file $wsgi --chdir $sandbox --master --processes 4 --threads 2 --py-autoreload 3 diff --git a/examples/deploy/wait.sh b/examples/deploy/wait.sh new file mode 100644 index 00000000..a3341e05 --- /dev/null +++ b/examples/deploy/wait.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +apt-get install -y --force-yes netcat + +set -e + +host=$(env | grep _TCP_ADDR | cut -d = -f 2) +port=$(env | grep _TCP_PORT | cut -d = -f 2) + +echo -n "waiting for TCP connection to $host:$port..." + +while ! nc -w 1 $host $port 2>/dev/null +do + echo -n . + sleep 1 +done + +echo 'ok' \ No newline at end of file diff --git a/examples/sandbox/settings.py b/examples/sandbox/settings.py index 97cf812d..f2a35830 100644 --- a/examples/sandbox/settings.py +++ b/examples/sandbox/settings.py @@ -33,7 +33,7 @@ DATABASES = { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'USER': 'root', # Not used with sqlite3. 'PASSWORD': 'mysecretpassword', # Not used with sqlite3. - 'NAME': 'telemeta', + 'NAME': 'sandbox', 'HOST': 'db', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '3306', # Set to empty string for default. Not used with sqlite3. } diff --git a/telemeta/management/commands/telemeta-timeside-boilerplate.py b/telemeta/management/commands/telemeta-timeside-boilerplate.py new file mode 100644 index 00000000..fbb4f2a6 --- /dev/null +++ b/telemeta/management/commands/telemeta-timeside-boilerplate.py @@ -0,0 +1,61 @@ +from optparse import make_option +from django.conf import settings +from django.core.management.base import BaseCommand, CommandError +from django.contrib.auth.models import User +from django.template.defaultfilters import slugify + +import os +import timeside.core +from timeside.server.models import * +from timeside.core.tools.test_samples import generateSamples + + +class Command(BaseCommand): + help = "Setup and run a boilerplate for testing" + cleanup = True + + def processor_cleanup(self): + for processor in Processor.objects.all(): + processor.delete() + + def result_cleanup(self): + for result in Result.objects.all(): + result.delete() + + def handle(self, *args, **options): + presets = [] + blacklist =['decoder', 'live', 'gain'] + processors = timeside.core.processor.processors(timeside.core.api.IProcessor) + for proc in processors: + trig = True + for black in blacklist: + if black in proc.id(): + trig = False + if trig: + processor, c = Processor.objects.get_or_create(pid=proc.id()) + preset, c = Preset.objects.get_or_create(processor=processor, parameters='{}') + presets.append(preset) + + media_dir = 'items' + os.sep + 'tests' + samples_dir = settings.MEDIA_ROOT + media_dir + samples = generateSamples(samples_dir=samples_dir) + selection, c = Selection.objects.get_or_create(title='Tests') + + for sample in samples.iteritems(): + filename, path = sample + title = os.path.splitext(filename)[0] + path = media_dir + os.sep + filename + item, c = Item.objects.get_or_create(title=title, file=path) + if not item in selection.items.all(): + selection.items.add(item) + if self.cleanup: + for result in item.results.all(): + result.delete() + + experience, c = Experience.objects.get_or_create(title='All') + for preset in presets: + if not preset in experience.presets.all(): + experience.presets.add(preset) + + task = Task(experience=experience, selection=selection) + task.status_setter(2) -- 2.39.5