2017-01-16 14:51:24 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
worker() {
|
|
|
|
WORKERS_COUNT=${WORKERS_COUNT:-2}
|
|
|
|
QUEUES=${QUEUES:-queries,scheduled_queries,celery}
|
|
|
|
|
|
|
|
echo "Starting $WORKERS_COUNT workers for queues: $QUEUES..."
|
2017-03-06 05:54:20 +00:00
|
|
|
exec /usr/local/bin/celery worker --app=redash.worker -c$WORKERS_COUNT -Q$QUEUES -linfo --maxtasksperchild=10 -Ofair
|
2017-01-16 14:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
scheduler() {
|
|
|
|
WORKERS_COUNT=${WORKERS_COUNT:-1}
|
|
|
|
QUEUES=${QUEUES:-celery}
|
|
|
|
|
|
|
|
echo "Starting scheduler and $WORKERS_COUNT workers for queues: $QUEUES..."
|
|
|
|
|
2017-03-06 05:54:20 +00:00
|
|
|
exec /usr/local/bin/celery worker --app=redash.worker --beat -c$WORKERS_COUNT -Q$QUEUES -linfo --maxtasksperchild=10 -Ofair
|
2017-01-16 14:51:24 +00:00
|
|
|
}
|
|
|
|
|
2017-01-18 13:20:46 +00:00
|
|
|
server() {
|
2017-07-06 17:45:47 +00:00
|
|
|
exec /usr/local/bin/gunicorn -b 0.0.0.0:5000 --name redash -w${REDASH_WEB_WORKERS:-4} redash.wsgi:app
|
2017-01-16 14:51:24 +00:00
|
|
|
}
|
|
|
|
|
2017-11-26 04:26:44 +00:00
|
|
|
create_db() {
|
|
|
|
while ! bash -c "echo > /dev/tcp/postgres/5432" &> /dev/null ; do
|
|
|
|
echo "Waiting for PostgreSQL container to become available."
|
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
exec /app/manage.py database create_tables
|
|
|
|
}
|
|
|
|
|
2017-01-16 14:51:24 +00:00
|
|
|
help() {
|
2017-01-18 13:20:46 +00:00
|
|
|
echo "Redash Docker."
|
|
|
|
echo ""
|
|
|
|
echo "Usage:"
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
echo "server -- start Redash server (with gunicorn)"
|
|
|
|
echo "worker -- start Celery worker"
|
|
|
|
echo "scheduler -- start Celery worker with a beat (scheduler) process"
|
|
|
|
echo ""
|
|
|
|
echo "shell -- open shell"
|
|
|
|
echo "dev_server -- start Flask development server with debugger and auto reload"
|
|
|
|
echo "create_db -- create database tables"
|
2017-03-08 13:35:58 +00:00
|
|
|
echo "manage -- CLI to manage redash"
|
2017-12-31 12:34:41 +00:00
|
|
|
echo "tests -- run tests"
|
2017-01-16 14:51:24 +00:00
|
|
|
}
|
|
|
|
|
2017-01-22 10:46:27 +00:00
|
|
|
tests() {
|
|
|
|
export REDASH_DATABASE_URL="postgresql://postgres@postgres/tests"
|
2018-01-02 11:30:06 +00:00
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
TEST_ARGS=tests/
|
|
|
|
else
|
|
|
|
TEST_ARGS=$@
|
|
|
|
fi
|
2017-12-31 12:34:41 +00:00
|
|
|
exec pytest $TEST_ARGS
|
2017-01-22 10:46:27 +00:00
|
|
|
}
|
|
|
|
|
2017-01-16 14:51:24 +00:00
|
|
|
case "$1" in
|
|
|
|
worker)
|
|
|
|
shift
|
|
|
|
worker
|
|
|
|
;;
|
2017-01-18 13:20:46 +00:00
|
|
|
server)
|
2017-01-16 14:51:24 +00:00
|
|
|
shift
|
2017-01-18 13:20:46 +00:00
|
|
|
server
|
2017-01-16 14:51:24 +00:00
|
|
|
;;
|
|
|
|
scheduler)
|
|
|
|
shift
|
|
|
|
scheduler
|
|
|
|
;;
|
|
|
|
dev_server)
|
2018-02-27 21:09:00 +00:00
|
|
|
export FLASK_DEBUG=1
|
2017-03-06 05:54:20 +00:00
|
|
|
exec /app/manage.py runserver --debugger --reload -h 0.0.0.0
|
2017-01-16 14:51:24 +00:00
|
|
|
;;
|
|
|
|
shell)
|
2017-03-06 05:54:20 +00:00
|
|
|
exec /app/manage.py shell
|
2017-01-18 13:20:46 +00:00
|
|
|
;;
|
|
|
|
create_db)
|
2017-11-26 04:26:44 +00:00
|
|
|
create_db
|
2017-01-16 14:51:24 +00:00
|
|
|
;;
|
2017-03-08 13:35:58 +00:00
|
|
|
manage)
|
|
|
|
shift
|
|
|
|
exec /app/manage.py $*
|
|
|
|
;;
|
2017-01-22 10:46:27 +00:00
|
|
|
tests)
|
2018-01-02 11:30:06 +00:00
|
|
|
shift
|
|
|
|
tests $@
|
2017-01-22 10:46:27 +00:00
|
|
|
;;
|
2017-10-25 18:41:50 +00:00
|
|
|
help)
|
2017-12-31 12:34:41 +00:00
|
|
|
shift
|
2017-01-16 14:51:24 +00:00
|
|
|
help
|
|
|
|
;;
|
2017-10-25 18:41:50 +00:00
|
|
|
*)
|
|
|
|
exec "$@"
|
|
|
|
;;
|
2017-01-16 14:51:24 +00:00
|
|
|
esac
|