From 3397e74cab994de25b4b5669c5904bd5898695d6 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 19 Mar 2015 12:35:17 +0100 Subject: [PATCH] add a wait script for better composition sequencing --- docker-compose-mysql.yml | 24 ++++++++++++------------ examples/deploy/celery_app.sh | 11 ++++------- examples/deploy/start_app.sh | 21 ++++++++------------- examples/deploy/wait.sh | 18 ++++++++++++++++++ 4 files changed, 42 insertions(+), 32 deletions(-) create mode 100644 examples/deploy/wait.sh diff --git a/docker-compose-mysql.yml b/docker-compose-mysql.yml index 9f11f79..b051292 100644 --- a/docker-compose-mysql.yml +++ b/docker-compose-mysql.yml @@ -47,7 +47,7 @@ lib: home: image: debian:wheezy volumes: - - ./examples/sandbox:/home/timeside + - ./examples/sandbox:/home/sandbox command: /bin/true db: @@ -57,7 +57,7 @@ db: - log environment: - MYSQL_ROOT_PASSWORD=mysecretpassword - - MYSQL_DATABASE=timeside + - 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/TimeSide/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/TimeSide/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 c09ad06..8be32e1 100644 --- a/examples/deploy/celery_app.sh +++ b/examples/deploy/celery_app.sh @@ -1,14 +1,11 @@ #!/bin/sh # paths -app_dir='/opt/TimeSide/' -sandbox_dir='/home/timeside/' -manage=$sandbox_dir'manage.py' +app='/opt/TimeSide/' +sandbox='/home/sandbox/' +manage=$sandbox'manage.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 cf84347..94ff7c1 100644 --- a/examples/deploy/start_app.sh +++ b/examples/deploy/start_app.sh @@ -1,18 +1,13 @@ #!/bin/sh # paths -app_dir='/opt/TimeSide/' -sandbox_dir='/home/timeside/' -manage=$sandbox_dir'manage.py' -wsgi=$sandbox_dir'wsgi.py' -app_static_dir=$app_dir'timeside/player/static/' +app='/opt/TimeSide/' +static=$app'timeside/static/' +sandbox='/home/sandbox/' +manage=$sandbox'manage.py' +wsgi=$sandbox'wsgi.py' -# Copy Sandbox in /home/timeside -#  this is not needed for TimeSide but for Timeside-diadems -# cp -uR /opt/TimeSide/examples/sandbox/* /home/timeside/ - -# install staging modules -pip install mysql +sh $app/examples/deploy/wait.sh # django init python $manage syncdb --noinput @@ -22,7 +17,7 @@ python $manage timeside-create-admin-user # static files auto update 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 0000000..a3341e0 --- /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 -- 2.39.5