From c75054b320f544ea0bf4dc236f79b35c84d3f6bc Mon Sep 17 00:00:00 2001 From: Adam Griffiths Date: Fri, 3 Jun 2016 10:50:44 +1000 Subject: [PATCH 1/2] Add Heroku support Move .bowerrc, bower.json, gulpfile.js, package.json down to root level. Update paths in .bowerrc, gulpfile.js, Makefile Add a heroku-postbuild step to package.json which installs devDependencies and runs the build. Add step in bin/pre_compile which adds the requirements_all_ds.txt to requirements.txt to ensure that cffi is installed. Also removes pymssql as this is not supported on Heroku. Add content from rd_ui/.gitignore to .gitignore and remove rd_ui/.gitignore. Add section in setup.rst about Heroku deployments. --- .bowerrc | 3 +++ .gitignore | 5 ++++ Makefile | 10 ++++---- Procfile.heroku | 2 ++ bin/pre_compile | 17 +++++++++++++ rd_ui/bower.json => bower.json | 0 docs/setup.rst | 38 ++++++++++++++++++++++++++++++ rd_ui/gulpfile.js => gulpfile.js | 4 ++-- rd_ui/package.json => package.json | 3 ++- rd_ui/.bowerrc | 3 --- rd_ui/.gitignore | 4 ---- 11 files changed, 74 insertions(+), 15 deletions(-) create mode 100644 .bowerrc create mode 100644 Procfile.heroku create mode 100644 bin/pre_compile rename rd_ui/bower.json => bower.json (100%) rename rd_ui/gulpfile.js => gulpfile.js (98%) rename rd_ui/package.json => package.json (87%) delete mode 100644 rd_ui/.bowerrc delete mode 100644 rd_ui/.gitignore diff --git a/.bowerrc b/.bowerrc new file mode 100644 index 0000000000..7a15de5f4c --- /dev/null +++ b/.bowerrc @@ -0,0 +1,3 @@ +{ + "directory": "rd_ui/app/bower_components" +} diff --git a/.gitignore b/.gitignore index 57951982b3..d35a8f7433 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,8 @@ dump.rdb # Docker related docker-compose.yml + +node_modules +.tmp +.sass-cache +rd_ui/app/bower_components diff --git a/Makefile b/Makefile index a15f0931ae..f4e15a9b66 100644 --- a/Makefile +++ b/Makefile @@ -6,17 +6,17 @@ BASE_VERSION=$(shell python ./manage.py version | cut -d + -f 1) FILENAME=$(CIRCLE_ARTIFACTS)/$(NAME).$(VERSION).tar.gz deps: - if [ -d "./rd_ui/app" ]; then cd rd_ui && npm install; fi - if [ -d "./rd_ui/app" ]; then cd rd_ui && npm run bower install; fi - if [ -d "./rd_ui/app" ]; then cd rd_ui && npm run build; fi + if [ -d "./rd_ui/app" ]; then npm install; fi + if [ -d "./rd_ui/app" ]; then npm run bower install; fi + if [ -d "./rd_ui/app" ]; then npm run build; fi pack: sed -ri "s/^__version__ = '([0-9.]*)'/__version__ = '$(FULL_VERSION)'/" redash/__init__.py - tar -zcv -f $(FILENAME) --exclude="optipng*" --exclude=".git*" --exclude="*.pyc" --exclude="*.pyo" --exclude="venv" --exclude="rd_ui/node_modules" --exclude="rd_ui/dist/bower_components" --exclude="rd_ui/app" * + tar -zcv -f $(FILENAME) --exclude="optipng*" --exclude=".git*" --exclude="*.pyc" --exclude="*.pyo" --exclude="venv" --exclude="node_modules" --exclude="rd_ui/dist/bower_components" --exclude="rd_ui/app" * upload: python bin/release_manager.py $(CIRCLE_SHA1) $(BASE_VERSION) $(FILENAME) test: nosetests --with-coverage --cover-package=redash tests/ - #cd rd_ui && grunt test + #grunt test diff --git a/Procfile.heroku b/Procfile.heroku new file mode 100644 index 0000000000..89cb91bd3a --- /dev/null +++ b/Procfile.heroku @@ -0,0 +1,2 @@ +web: ./manage.py runserver -p $PORT --host 0.0.0.0 +worker: ./bin/run celery worker --app=redash.worker --beat -Q queries,celery,scheduled_queries diff --git a/bin/pre_compile b/bin/pre_compile new file mode 100644 index 0000000000..c5777bffc2 --- /dev/null +++ b/bin/pre_compile @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# heroku post_compile script + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +pushd $DIR/.. + +# heroku requires cffi to be in requirements.txt in order for libffi to be installed. +# https://github.com/heroku/heroku-buildpack-python/blob/master/bin/steps/cryptography +# to avoid making it a requirement for other build systems, we'll inject it now +# into the requirements.txt file +# remove pymssql, it doesn't compile on heroku +grep -v '^pymssql' requirements_all_ds.txt >> requirements.txt + +# make the heroku Procfile the active one +cp Procfile.heroku Procfile + +popd diff --git a/rd_ui/bower.json b/bower.json similarity index 100% rename from rd_ui/bower.json rename to bower.json diff --git a/docs/setup.rst b/docs/setup.rst index 4b459ccedc..c769d1393c 100644 --- a/docs/setup.rst +++ b/docs/setup.rst @@ -79,6 +79,44 @@ Docker Compose Now proceed to `"Setup" <#setup>`__. +Heroku +------ + +1. Install `Heroku CLI `_. + +2. Create Heroku App:: + + $ heroku apps:create + +2. Set application buildpacks:: + + $ heroku buildpacks:set heroku/python + $ heroku buildpacks:add --index 1 heroku/nodejs + +3. Add Postgres addon:: + + $ heroku addons:create heroku-postgresql:hobby-dev + +4. Add Redis addon:: + + $ heroku addons:create heroku-redis:hobby-dev + +5. Set environment variables:: + + $ heroku config:set REDASH_DATABASE_URL=`heroku config:get DATABASE_URL` + $ heroku config:set REDASH_REDIS_URL=`heroku config:get REDIS_URL` + $ heroku config:set REDASH_COOKIE_SECRET='' + +6. Push the repository to Heroku:: + + $ git push heroku master + +7. Create database tables:: + + $ heroku run bash + $ python manage.py database create_tables + + Other ----- diff --git a/rd_ui/gulpfile.js b/gulpfile.js similarity index 98% rename from rd_ui/gulpfile.js rename to gulpfile.js index 4355297ebb..484f544959 100644 --- a/rd_ui/gulpfile.js +++ b/gulpfile.js @@ -9,8 +9,8 @@ var wiredep = require('wiredep').stream; var runSequence = require('run-sequence'); var yeoman = { - app: 'app', - dist: 'dist' + app: 'rd_ui/app', + dist: 'rd_ui/dist' }; var paths = { diff --git a/rd_ui/package.json b/package.json similarity index 87% rename from rd_ui/package.json rename to package.json index 8a199b7fcf..d707c5da82 100644 --- a/rd_ui/package.json +++ b/package.json @@ -34,7 +34,8 @@ "scripts": { "test": "echo 'No tests.'", "build": "gulp build", - "bower": "bower" + "bower": "bower", + "heroku-postbuild": "npm install --dev && npm run bower install && npm run build && npm prune --production" }, "dependencies": { } diff --git a/rd_ui/.bowerrc b/rd_ui/.bowerrc deleted file mode 100644 index ba0accc5a3..0000000000 --- a/rd_ui/.bowerrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "directory": "app/bower_components" -} diff --git a/rd_ui/.gitignore b/rd_ui/.gitignore deleted file mode 100644 index ff422877e5..0000000000 --- a/rd_ui/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -node_modules -.tmp -.sass-cache -app/bower_components From a0b97c1fc90eb665fb8103a0adca4e8ca2c17132 Mon Sep 17 00:00:00 2001 From: Adam Griffiths Date: Mon, 6 Jun 2016 11:39:10 +1000 Subject: [PATCH 2/2] Update Heroku support as per comments Fix comment in bin/pre_compile. Remove .gitattributes and .travis.yml in rd_ui/. Remove bin/run from Procfile.heroku. Update documentation: -Add a note about upgrading from version to version. -Remove commands for DATABASE_URL and REDIS_URL. -Add importance to the cookie secret variable. -Merge adding redis and postgres addons into 1 step. --- Procfile.heroku | 2 +- bin/pre_compile | 2 +- docs/setup.rst | 18 ++++++++---------- rd_ui/.gitattributes | 1 - rd_ui/.travis.yml | 6 ------ 5 files changed, 10 insertions(+), 19 deletions(-) delete mode 100644 rd_ui/.gitattributes delete mode 100644 rd_ui/.travis.yml diff --git a/Procfile.heroku b/Procfile.heroku index 89cb91bd3a..6b8aed452d 100644 --- a/Procfile.heroku +++ b/Procfile.heroku @@ -1,2 +1,2 @@ web: ./manage.py runserver -p $PORT --host 0.0.0.0 -worker: ./bin/run celery worker --app=redash.worker --beat -Q queries,celery,scheduled_queries +worker: celery worker --app=redash.worker --beat -Q queries,celery,scheduled_queries diff --git a/bin/pre_compile b/bin/pre_compile index c5777bffc2..fd07650446 100644 --- a/bin/pre_compile +++ b/bin/pre_compile @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# heroku post_compile script +# heroku pre_compile script DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" pushd $DIR/.. diff --git a/docs/setup.rst b/docs/setup.rst index c769d1393c..6414f54b38 100644 --- a/docs/setup.rst +++ b/docs/setup.rst @@ -82,7 +82,10 @@ Now proceed to `"Setup" <#setup>`__. Heroku ------ -1. Install `Heroku CLI `_. +Due to the nature of Heroku deployments, upgrading to a newer version of Redash +requires performing the steps outlined on the `"How to Upgrade"`__ page. + +1. Install `Heroku CLI`__. 2. Create Heroku App:: @@ -93,25 +96,20 @@ Heroku $ heroku buildpacks:set heroku/python $ heroku buildpacks:add --index 1 heroku/nodejs -3. Add Postgres addon:: +3. Add Postgres and Redis addons:: $ heroku addons:create heroku-postgresql:hobby-dev - -4. Add Redis addon:: - $ heroku addons:create heroku-redis:hobby-dev -5. Set environment variables:: +4. Update the cookie secret (**Important** otherwise anyone can sign new cookies and impersonate users. You may be able to run the command ``pwgen 32 -1`` to generate a random string):: - $ heroku config:set REDASH_DATABASE_URL=`heroku config:get DATABASE_URL` - $ heroku config:set REDASH_REDIS_URL=`heroku config:get REDIS_URL` $ heroku config:set REDASH_COOKIE_SECRET='' -6. Push the repository to Heroku:: +5. Push the repository to Heroku:: $ git push heroku master -7. Create database tables:: +6. Create database tables:: $ heroku run bash $ python manage.py database create_tables diff --git a/rd_ui/.gitattributes b/rd_ui/.gitattributes deleted file mode 100644 index 2125666142..0000000000 --- a/rd_ui/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -* text=auto \ No newline at end of file diff --git a/rd_ui/.travis.yml b/rd_ui/.travis.yml deleted file mode 100644 index a80b6e0388..0000000000 --- a/rd_ui/.travis.yml +++ /dev/null @@ -1,6 +0,0 @@ -language: node_js -node_js: - - '0.10' -before_script: - - 'npm install -g bower grunt-cli' - - 'bower install'