From e4679c66565d0ccae54ffc58a23083841e5585e7 Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 31 Mar 2015 10:52:07 -0700 Subject: fix travis: use couchdb.admin.yml and pin travis ruby version to one that is installed on travis-ci.org --- .travis.yml | 13 ++++++++----- DEPLOY.md | 28 ++++++++++++++++++---------- README.md | 12 ++++++++++-- lib/tasks/leap_web_core_tasks.rake | 31 +++++++++++++++++++------------ test/config/couchdb.admin.yml | 6 ++++++ test/config/couchdb.yml | 5 +++++ test/config/couchdb.yml.admin | 6 ------ test/config/couchdb.yml.user | 5 ----- test/setup_couch.sh | 17 ----------------- test/travis/ruby-version | 1 + test/travis/setup_couch.sh | 17 +++++++++++++++++ 11 files changed, 84 insertions(+), 57 deletions(-) create mode 100644 test/config/couchdb.admin.yml create mode 100644 test/config/couchdb.yml delete mode 100644 test/config/couchdb.yml.admin delete mode 100644 test/config/couchdb.yml.user delete mode 100755 test/setup_couch.sh create mode 100644 test/travis/ruby-version create mode 100755 test/travis/setup_couch.sh diff --git a/.travis.yml b/.travis.yml index 90822f3..189a4c3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,10 +3,13 @@ services: notifications: email: false before_script: - - "test/setup_couch.sh" - - "mv test/config/couchdb.yml.admin config/couchdb.yml" - - "bundle exec rake RAILS_ENV=test couchrest:migrate_with_proxies" - - "mv test/config/couchdb.yml.user config/couchdb.yml" + - "rm .ruby-version" + - "mv test/travis/ruby-version .ruby-version" + - "test/travis/setup_couch.sh" + - "mv test/config/couchdb.admin.yml config/couchdb.admin.yml" + - "mv test/config/couchdb.yml config/couchdb.yml" + - "bundle exec rake RAILS_ENV=test db:rotate" + - "bundle exec rake RAILS_ENV=test db:migrate" after_script: - "cat tmp/*.test*.log" # printing logs from the failed integration tests -bundler_args: --without development debug \ No newline at end of file +bundler_args: --without development debug diff --git a/DEPLOY.md b/DEPLOY.md index 05d97cb..33d5598 100644 --- a/DEPLOY.md +++ b/DEPLOY.md @@ -1,6 +1,7 @@ # Deployment # -These instructions are targeting a Debian GNU/Linux system. You might need to change the commands to match your own needs. +These instructions are targeting a Debian GNU/Linux system. You might need to +change the commands to match your own needs. ## Server Preperation ## @@ -15,7 +16,9 @@ The following packages need to be installed: ### Setup Capistrano ### -We use puppet to deploy. But we also ship an example deploy.rb in config/deploy.rb.example. Edit it to match your needs if you want to use capistrano. +We use puppet to deploy. But we also ship an example deploy.rb in +config/deploy.rb.example. Edit it to match your needs if you want to use +capistrano. run `cap deploy:setup` to create the directory structure. @@ -31,12 +34,15 @@ Please make sure your deploy includes the following files: ## Couch Security ## -We recommend against using an admin user for running the webapp. To avoid this couch design documents need to be created ahead of time and the auto update mechanism needs to be disabled. -Take a look at test/setup_couch.sh for an example of securing the couch. +We recommend against using an admin user for running the webapp. To avoid this +couch design documents need to be created ahead of time and the auto update +mechanism needs to be disabled. Take a look at `test/travis/setup_couch.sh` +for an example of securing the couch. ### DESIGN DOCUMENTS ### -After securing the couch design documents need to be deployed with admin permissions. There are two ways of doing this: +After securing the couch design documents need to be deployed with admin +permissions. There are two ways of doing this: * rake couchrest:migrate_with_proxies * dump the documents as files with `rake couchrest:dump` and deploy them to the couch by hand or with puppet. @@ -46,10 +52,10 @@ After securing the couch design documents need to be deployed with admin permiss The before_script block in .travis.yml illustrates how to do this: ```bash -mv test/config/couchdb.yml.admin config/couchdb.yml # use admin privileges -bundle exec rake couchrest:migrate_with_proxies # run the migrations -bundle exec rake couchrest:migrate_with_proxies # looks like this needs to run twice -mv test/config/couchdb.yml.user config/couchdb.yml # drop admin privileges +mv test/config/couchdb.yml config/couchdb.yml +mv test/config/couchdb.admin.yml config/couchdb.admin.yml +bundle exec rake db:rotate # create dbs +bundle exec rake couchrest:migrate # run migrations ``` #### Deploy design docs from CouchRest::Dump #### @@ -61,4 +67,6 @@ First of all we get the design docs as files: bundle exec rake couchrest:dump ``` -Then we add them to files/design in the site_couchdb module in leap_platform so they get deployed with the couch. You could also upload them using curl or sth. similar. +Then we add them to files/design in the site_couchdb module in leap_platform +so they get deployed with the couch. You could also upload them using curl or +sth. similar. diff --git a/README.md b/README.md index e399ee2..f2d69ca 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,8 @@ Running To run leap_web: cd leap_web - bin/rake couchrest:migrate + bin/rake db:rotate + bin/rake db:migrate bin/rails server Then open http://localhost:3000 in your web browser. @@ -124,12 +125,19 @@ powers by creating an account with username 'staff', 'blue', or 'red' To peruse the database, visit http://localhost:5984/_utils/ +The task `db:rotate` must come before `db:migrate`, in order to assure that +the special rotating databases get created. + +Do not run the normal CouchRest task 'couchrest:migrate'. Instead, use +'db:rotate' since the latter will correctly use the couchdb.admin.yml file. + Testing -------------------------------- To run all tests - bin/rake couchrest:migrate # if not already run + bin/rake RAILS_ENV=test db:rotate # if not already run + bin/rake RAILS_ENV=test db:migrate # if not already run bin/rake test To run an individual test: diff --git a/lib/tasks/leap_web_core_tasks.rake b/lib/tasks/leap_web_core_tasks.rake index e446f93..6f5ea4e 100644 --- a/lib/tasks/leap_web_core_tasks.rake +++ b/lib/tasks/leap_web_core_tasks.rake @@ -22,7 +22,21 @@ namespace :cleanup do end end +def use_admin_conf(couchrest_model_class) + couchrest_model_class.configure do |conf| + conf.environment = Rails.env + conf.connection_config_file = File.join(Rails.root, 'config', 'couchdb.admin.yml') + end +end + namespace :db do + desc "Migrate all design documents (using couchdb.admin.yml)" + task :migrate => :environment do + use_admin_conf(CouchRest::Model::Base) + CouchRest::Model::Utils::Migrate.load_all_models + CouchRest::Model::Utils::Migrate.all_models + end + desc "Rotate the databases, as needed." task :rotate => :environment do # @@ -31,26 +45,19 @@ namespace :db do # override the default config twice. # - CouchRest::Model::Base.configure do |conf| - conf.environment = Rails.env - conf.connection_config_file = File.join(Rails.root, 'config', 'couchdb.admin.yml') - end + use_admin_conf(CouchRest::Model::Base) Token.rotate_database_now(:window => 1.day) + User.create_tmp_database! + User.design_doc.sync!(User.tmp_database) - CouchRest::Session::Document.configure do |conf| - conf.environment = Rails.env - conf.connection_config_file = File.join(Rails.root, 'config', 'couchdb.admin.yml') - end + use_admin_conf(CouchRest::Session::Document) CouchRest::Session::Document.rotate_database_now(:window => 1.day) end desc "Delete and recreate temporary databases." task :deletetmp => :environment do # db deletion and creation must be performed by admin - CouchRest::Model::Base.configure do |conf| - conf.environment = Rails.env - conf.connection_config_file = File.join(Rails.root, 'config', 'couchdb.admin.yml') - end + use_admin_conf(CouchRest::Model::Base) User.tmp_database.recreate! User.design_doc.sync!(User.tmp_database) end diff --git a/test/config/couchdb.admin.yml b/test/config/couchdb.admin.yml new file mode 100644 index 0000000..0988bc1 --- /dev/null +++ b/test/config/couchdb.admin.yml @@ -0,0 +1,6 @@ +test: + auto_update_design_doc: false + username: "anna" + password: "secret" + prefix: "" + diff --git a/test/config/couchdb.yml b/test/config/couchdb.yml new file mode 100644 index 0000000..9c8b67b --- /dev/null +++ b/test/config/couchdb.yml @@ -0,0 +1,5 @@ +test: + auto_update_design_doc: false + username: "me" + password: "pwd" + prefix: "" diff --git a/test/config/couchdb.yml.admin b/test/config/couchdb.yml.admin deleted file mode 100644 index 0988bc1..0000000 --- a/test/config/couchdb.yml.admin +++ /dev/null @@ -1,6 +0,0 @@ -test: - auto_update_design_doc: false - username: "anna" - password: "secret" - prefix: "" - diff --git a/test/config/couchdb.yml.user b/test/config/couchdb.yml.user deleted file mode 100644 index 9c8b67b..0000000 --- a/test/config/couchdb.yml.user +++ /dev/null @@ -1,5 +0,0 @@ -test: - auto_update_design_doc: false - username: "me" - password: "pwd" - prefix: "" diff --git a/test/setup_couch.sh b/test/setup_couch.sh deleted file mode 100755 index 0502c12..0000000 --- a/test/setup_couch.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -HOST="http://localhost:5984" -echo "couch version :" -curl -X GET $HOST -echo "creating user :" -curl -HContent-Type:application/json -XPUT $HOST/_users/org.couchdb.user:me --data-binary '{"_id": "org.couchdb.user:me","name": "me","roles": [],"type": "user","password": "pwd"}' -echo "creating databases :" -curl -X PUT $HOST/sessions -curl -X PUT $HOST/users -curl -X PUT $HOST/tickets -echo "restricting database access :" -curl -X PUT $HOST/sessions/_security -Hcontent-type:application/json --data-binary '{"admins":{"names":[],"roles":[]},"members":{"names":["me"],"roles":[]}}' -curl -X PUT $HOST/users/_security -Hcontent-type:application/json --data-binary '{"admins":{"names":[],"roles":[]},"members":{"names":["me"],"roles":[]}}' -curl -X PUT $HOST/tickets/_security -Hcontent-type:application/json --data-binary '{"admins":{"names":[],"roles":[]},"members":{"names":["me"],"roles":[]}}' -echo "adding admin :" -curl -X PUT $HOST/_config/admins/anna -d '"secret"' diff --git a/test/travis/ruby-version b/test/travis/ruby-version new file mode 100644 index 0000000..68b3a4c --- /dev/null +++ b/test/travis/ruby-version @@ -0,0 +1 @@ +1.9.3-p551 diff --git a/test/travis/setup_couch.sh b/test/travis/setup_couch.sh new file mode 100755 index 0000000..0502c12 --- /dev/null +++ b/test/travis/setup_couch.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +HOST="http://localhost:5984" +echo "couch version :" +curl -X GET $HOST +echo "creating user :" +curl -HContent-Type:application/json -XPUT $HOST/_users/org.couchdb.user:me --data-binary '{"_id": "org.couchdb.user:me","name": "me","roles": [],"type": "user","password": "pwd"}' +echo "creating databases :" +curl -X PUT $HOST/sessions +curl -X PUT $HOST/users +curl -X PUT $HOST/tickets +echo "restricting database access :" +curl -X PUT $HOST/sessions/_security -Hcontent-type:application/json --data-binary '{"admins":{"names":[],"roles":[]},"members":{"names":["me"],"roles":[]}}' +curl -X PUT $HOST/users/_security -Hcontent-type:application/json --data-binary '{"admins":{"names":[],"roles":[]},"members":{"names":["me"],"roles":[]}}' +curl -X PUT $HOST/tickets/_security -Hcontent-type:application/json --data-binary '{"admins":{"names":[],"roles":[]},"members":{"names":["me"],"roles":[]}}' +echo "adding admin :" +curl -X PUT $HOST/_config/admins/anna -d '"secret"' -- cgit v1.2.3