From 8aec988fbf4de7afb72e32328fef22f0f6d6b03f Mon Sep 17 00:00:00 2001 From: Helge Rausch Date: Fri, 23 Oct 2015 08:05:46 +0200 Subject: [PATCH 01/11] Move configuration into environment --- .env.example | 14 +++++++++++ .gitignore | 1 + .travis.yml | 13 +++------- Gemfile | 2 ++ Gemfile.lock | 8 ++++++ README.md | 9 ++----- Rakefile | 3 ++- app/controllers/fitbit_profiles_controller.rb | 6 +++-- app/workers/fitbit_edit.rb | 3 ++- app/workers/fitbit_endsubscription.rb | 3 ++- app/workers/fitbit_init.rb | 3 ++- app/workers/fitbit_notification.rb | 3 ++- app/workers/plos_search.rb | 3 +-- config/app_config.yml.example | 25 ------------------- config/application.rb | 6 +---- config/initializers/0_load_app_config.rb | 2 -- config/initializers/airbrake.rb | 4 +-- config/initializers/mendeley.rb | 2 +- config/initializers/recaptcha.rb | 4 +-- config/initializers/secret_token.rb | 11 +++----- config/initializers/sidekiq.rb | 6 ++--- 21 files changed, 57 insertions(+), 74 deletions(-) create mode 100644 .env.example delete mode 100644 config/app_config.yml.example delete mode 100644 config/initializers/0_load_app_config.rb diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..b71f09b --- /dev/null +++ b/.env.example @@ -0,0 +1,14 @@ +export SECRET_KEY_BASE=foo +export SECRET_TOKEN=bar +export RAILS_ENV=development +export POSTGRES_URL="postgres://localhost/snpr_$RAILS_ENV" +#export REDIS_URL= +export FITBIT_CONSUMER_KEY=foo +export FITBIT_CONSUMER_SECRET=bar +export PLOS_API_KEY=foo +export RECAPTCHA_PRIVATE_KEY=foo +export RECAPTCHA_PUBLIC_KEY=bar +export SIDEKIQ_PASSWORD=foo +export MENDELEY_CONSUMER_KEY=foo +export ERRBIT_API_KEY=foo +export ERRBIT_HOST=localhost diff --git a/.gitignore b/.gitignore index c553a73..0cd3f4f 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ tmp/pids/server.pid vendor/bundle vendor/cache logfile +.env diff --git a/.travis.yml b/.travis.yml index 4339df2..13d846c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,11 @@ -language: ruby # Defaults to ruby, but travis-ci recommends making this explicit. +language: ruby sudo: false cache: bundler addons: apt: packages: - libhiredis-dev - postgresql: "9.2" + postgresql: '9.3' services: - redis-server rvm: @@ -14,11 +14,6 @@ env: DB=postgres CI=1 bundler_args: --without development debug before_script: - cp config/database.yml.ci config/database.yml - - cp config/app_config.yml.example config/app_config.yml - - echo "foo" > mail_username.txt - - echo "bar" > mail_password.txt - - echo "secret-token" > secret_token - - echo "secret-key-base" > secret_key_base - - psql -c 'create database snpr_test;' -U postgres + - cp .env.example .env - bundle exec rake db:setup -script: "bundle exec rake test" +script: bundle exec rake diff --git a/Gemfile b/Gemfile index 2eea1e3..67761a8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,7 @@ source 'http://rubygems.org' +gem 'dotenv-rails', groups: %i(development test) + gem 'rails', '~> 4.2.0' gem 'authlogic' # lots of user-related magic gem 'i18n', '>= 0.6.6' diff --git a/Gemfile.lock b/Gemfile.lock index ddbc1f8..075f94d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -106,6 +106,10 @@ GEM docile (1.1.5) domain_name (0.5.24) unf (>= 0.0.5, < 1.0.0) + dotenv (2.0.2) + dotenv-rails (2.0.2) + dotenv (= 2.0.2) + railties (~> 4.0) dynamic_form (1.1.4) erubis (2.7.0) execjs (2.6.0) @@ -375,6 +379,7 @@ DEPENDENCIES capybara composite_primary_keys (~> 8.0) database_cleaner + dotenv-rails dynamic_form execjs factory_girl_rails @@ -426,3 +431,6 @@ DEPENDENCIES whenever will_paginate yui-compressor + +BUNDLED WITH + 1.10.6 diff --git a/README.md b/README.md index e5585ce..50e1987 100644 --- a/README.md +++ b/README.md @@ -38,13 +38,7 @@ rake db:seed OR rake db:setup (which also sets up the entire db) # edit database.yml to point to your postgresql database cp config/database.yml.example config/database.yml -cp config/app_config.yml.example config/app_config.yml -``` - -## Generate Secret Token - -``` -bundle rake secret > secret_token +cp .env.example .env ``` ## Initialize Database @@ -58,6 +52,7 @@ bundle exec rake db:setup ``` bundle exec rake ``` +This runs RSpec tests as well as the **legacy** test/unit ones. # Usage diff --git a/Rakefile b/Rakefile index f32fb01..7aff7d5 100644 --- a/Rakefile +++ b/Rakefile @@ -6,4 +6,5 @@ require 'rake' Snpr::Application.load_tasks -task :test => :spec +task test: :spec +task default: :test diff --git a/app/controllers/fitbit_profiles_controller.rb b/app/controllers/fitbit_profiles_controller.rb index 772bf28..822516a 100644 --- a/app/controllers/fitbit_profiles_controller.rb +++ b/app/controllers/fitbit_profiles_controller.rb @@ -162,7 +162,8 @@ class FitbitProfilesController < ApplicationController print @user @fitbit_profile = @user.fitbit_profile print @fitbit_profile - client = Fitgem::Client.new({:consumer_key => APP_CONFIG[:fitbit_consumer_key], :consumer_secret => APP_CONFIG[:fitbit_consumer_secret]}) + client = Fitgem::Client.new(consumer_key: ENV.fetch('FITBIT_CONSUMER_KEY'), + consumer_secret: ENV.fetch('FITBIT_CONSUMER_SECRET')) request_token = client.request_token @fitbit_profile.request_token = request_token.token @fitbit_profile.request_secret = request_token.secret @@ -174,7 +175,8 @@ class FitbitProfilesController < ApplicationController @user = current_user @fitbit_profile = @user.fitbit_profile if params[:oauth_token] && params[:oauth_verifier] - @client = Fitgem::Client.new(:consumer_key => APP_CONFIG[:fitbit_consumer_key], :consumer_secret => APP_CONFIG[:fitbit_consumer_secret]) + @client = Fitgem::Client.new(consumer_key: ENV.fetch('FITBIT_CONSUMER_KEY'), + consumer_secret: ENV.fetch('FITBIT_CONSUMER_SECRET')) token = params[:oauth_token] secret = @fitbit_profile.request_secret verifier = params[:oauth_verifier] diff --git a/app/workers/fitbit_edit.rb b/app/workers/fitbit_edit.rb index fd746c2..15e1bcd 100644 --- a/app/workers/fitbit_edit.rb +++ b/app/workers/fitbit_edit.rb @@ -6,7 +6,8 @@ class FitbitEdit def perform(fitbit_profile_id) @fitbit_profile = FitbitProfile.find_by_id(fitbit_profile_id) - @client = Fitgem::Client.new(:consumer_key => APP_CONFIG[:fitbit_consumer_key], :consumer_secret => APP_CONFIG[:fitbit_consumer_secret]) + @client = Fitgem::Client.new(consumer_key: ENV.fetch('FITBIT_CONSUMER_KEY'), + consumer_secret: ENV.fetch('FITBIT_CONSUMER_SECRET')) @client.reconnect(@fitbit_profile.access_token, @fitbit_profile.access_secret) @return_value = @client.create_subscription({:type => :all, :subscription_id => @fitbit_profile.id}) puts "subscription returned: "+ @return_value[0] diff --git a/app/workers/fitbit_endsubscription.rb b/app/workers/fitbit_endsubscription.rb index 1b06991..18e0046 100644 --- a/app/workers/fitbit_endsubscription.rb +++ b/app/workers/fitbit_endsubscription.rb @@ -6,7 +6,8 @@ class FitbitEndSubscription def perform(fitbit_profile_id) @fitbit_profile = FitbitProfile.find_by_id(fitbit_profile_id) - @client = Fitgem::Client.new(:consumer_key => APP_CONFIG[:fitbit_consumer_key], :consumer_secret => APP_CONFIG[:fitbit_consumer_secret]) + @client = Fitgem::Client.new(consumer_key: ENV.fetch('FITBIT_CONSUMER_KEY'), + consumer_secret: ENV.fetch('FITBIT_CONSUMER_SECRET')) @client.reconnect(@fitbit_profile.access_token, @fitbit_profile.access_secret) @client.remove_subscription({:type => :all, :subscriber_id => "general", :subscription_id => @fitbit_profile.id}) @fitbit_profile.destroy() diff --git a/app/workers/fitbit_init.rb b/app/workers/fitbit_init.rb index 8c06ad1..d1f36c4 100644 --- a/app/workers/fitbit_init.rb +++ b/app/workers/fitbit_init.rb @@ -5,7 +5,8 @@ class FitbitInit sidekiq_options :queue => :fitbit, :retry => 5, :unique => true def perform(fitbit_profile_id) - @client = Fitgem::Client.new(:consumer_key => APP_CONFIG[:fitbit_consumer_key], :consumer_secret => APP_CONFIG[:fitbit_consumer_secret]) + @client = Fitgem::Client.new(consumer_key: ENV.fetch('FITBIT_CONSUMER_KEY'), + consumer_secret: ENV.fetch('FITBIT_CONSUMER_SECRET')) fitbit_profile = FitbitProfile.find_by_id(fitbit_profile_id) @client.reconnect(fitbit_profile.access_token, fitbit_profile.access_secret) fitbit_id = @client.user_info["user"]["encodedId"] diff --git a/app/workers/fitbit_notification.rb b/app/workers/fitbit_notification.rb index 71a813c..4d2fe81 100644 --- a/app/workers/fitbit_notification.rb +++ b/app/workers/fitbit_notification.rb @@ -9,7 +9,8 @@ class FitbitNotification notification.each do |n| @fitbit_profile = FitbitProfile.find_by_id(n["subscriptionId"]) if @fitbit_profile != nil - @client = Fitgem::Client.new(:consumer_key => APP_CONFIG[:fitbit_consumer_key], :consumer_secret => APP_CONFIG[:fitbit_consumer_secret]) + @client = Fitgem::Client.new(consumer_key: ENV.fetch('FITBIT_CONSUMER_KEY'), + consumer_secret: ENV.fetch('FITBIT_CONSUMER_SECRET')) @client.reconnect(@fitbit_profile.access_token, @fitbit_profile.access_secret) puts n puts n["collectionType"] diff --git a/app/workers/plos_search.rb b/app/workers/plos_search.rb index bb51aeb..01136b8 100644 --- a/app/workers/plos_search.rb +++ b/app/workers/plos_search.rb @@ -84,7 +84,6 @@ class PlosSearch end def self.api_key - # TODO: put in APP_CONFIG - File.read(Rails.root.join("key_plos.txt")).strip + ENV.fetch('PLOS_API_KEY') end end diff --git a/config/app_config.yml.example b/config/app_config.yml.example deleted file mode 100644 index d9e1536..0000000 --- a/config/app_config.yml.example +++ /dev/null @@ -1,25 +0,0 @@ -default: &default - fitbit_consumer_key: - fitbit_consumer_secret: - mendeley: - consumer_key: - recaptcha: - public_key: foo - private_key: bar - sidekiq: - user: admin - password: password - devise: password - errbit: - api_key: gobbledigook - host: url - -production: - <<: *default - -development: - <<: *default - -test: - <<: *default - diff --git a/config/application.rb b/config/application.rb index 2419059..48e1f03 100644 --- a/config/application.rb +++ b/config/application.rb @@ -2,11 +2,7 @@ require File.expand_path('../boot', __FILE__) require 'rails/all' -if defined?(Bundler) - # Require the gems listed in Gemfile, including any gems - # you've limited to :test, :development, or :production. - Bundler.require(*Rails.groups) -end +Bundler.require(*Rails.groups) module Snpr class Application < Rails::Application diff --git a/config/initializers/0_load_app_config.rb b/config/initializers/0_load_app_config.rb deleted file mode 100644 index 4e5bbdd..0000000 --- a/config/initializers/0_load_app_config.rb +++ /dev/null @@ -1,2 +0,0 @@ -raw_config = File.read("#{Rails.root}/config/app_config.yml") -APP_CONFIG = YAML.load(raw_config)[Rails.env].symbolize_keys diff --git a/config/initializers/airbrake.rb b/config/initializers/airbrake.rb index 8f6f488..c644ca1 100644 --- a/config/initializers/airbrake.rb +++ b/config/initializers/airbrake.rb @@ -1,7 +1,7 @@ # This is the config to talk to opensnperr.herokuapp.com Airbrake.configure do |config| - config.api_key = APP_CONFIG[:errbit]['api_key'] - config.host = APP_CONFIG[:errbit]['host'] + config.api_key = ENV.fetch('ERRBIT_API_KEY') + config.host = ENV.fetch('ERRBIT_HOST') config.port = 80 config.secure = config.port == 443 config.environment_name = Rails.env.production? ? `hostname` : Rails.env diff --git a/config/initializers/mendeley.rb b/config/initializers/mendeley.rb index 86a5cff..7fe405b 100644 --- a/config/initializers/mendeley.rb +++ b/config/initializers/mendeley.rb @@ -1 +1 @@ -Mendeley.consumer_key = APP_CONFIG[:mendeley]['consumer_key'] +Mendeley.consumer_key = ENV.fetch('MENDELEY_CONSUMER_KEY') diff --git a/config/initializers/recaptcha.rb b/config/initializers/recaptcha.rb index 301b881..489ec65 100644 --- a/config/initializers/recaptcha.rb +++ b/config/initializers/recaptcha.rb @@ -1,4 +1,4 @@ Recaptcha.configure do |config| - config.public_key = APP_CONFIG[:recaptcha]['public_key'] - config.private_key = APP_CONFIG[:recaptcha]['private_key'] + config.public_key = ENV.fetch('RECAPTCHA_PUBLIC_KEY') + config.private_key = ENV.fetch('RECAPTCHA_PRIVATE_KEY') end diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index 188ec87..4927177 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -1,9 +1,4 @@ -# TODO: Move to environment variables -begin - Snpr::Application.configure do - config.secret_token = File.read(Rails.root.join('secret_token')) - config.secret_key_base = File.read(Rails.root.join('secret_key_base')) - end -rescue LoadError, Errno::ENOENT => e - raise "Secret token couldn't be loaded! Error: #{e}" +Snpr::Application.configure do + config.secret_token = ENV.fetch('SECRET_TOKEN') + config.secret_key_base = ENV.fetch('SECRET_KEY_BASE') end diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 3f61644..a6b8553 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -3,8 +3,6 @@ require 'sidekiq/web' require 'sidekiq/limit_fetch' -Sidekiq::Web.use(Rack::Auth::Basic) do |user, password| - u = (APP_CONFIG[:sidekiq].try(:[], "user") || "admin") - p = (APP_CONFIG[:sidekiq].try(:[], "password") || "password") - [user, password] == [u, p] +Sidekiq::Web.use(Rack::Auth::Basic) do |_user, password| + password == ENV.fetch('SIDEKIQ_PASSWORD') end From e5428701ce3d491c03fd4b2ead32d3a368740734 Mon Sep 17 00:00:00 2001 From: Helge Rausch Date: Fri, 23 Oct 2015 21:19:52 +0200 Subject: [PATCH 02/11] Add script for extracting env vars for nginx --- bin/extract_env_var_names_for_nginx | 7 +++++++ {script => bin}/munin/parse_queue_length | 0 {script => bin}/munin/requests.sh | 0 {script => bin}/munin/response_time.sh | 0 {script => bin}/munin/sidekiq_workers.sh | 0 script/rails | 6 ------ 6 files changed, 7 insertions(+), 6 deletions(-) create mode 100755 bin/extract_env_var_names_for_nginx rename {script => bin}/munin/parse_queue_length (100%) rename {script => bin}/munin/requests.sh (100%) rename {script => bin}/munin/response_time.sh (100%) rename {script => bin}/munin/sidekiq_workers.sh (100%) delete mode 100644 script/rails diff --git a/bin/extract_env_var_names_for_nginx b/bin/extract_env_var_names_for_nginx new file mode 100755 index 0000000..f66bc29 --- /dev/null +++ b/bin/extract_env_var_names_for_nginx @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby + +env_file_name = ARGV[0] || '.env.example' +puts File.read(env_file_name) + .split(/ |=/) + .grep(/\A[_A-Z0-9]+\z/) + .map { |var| "env #{var};" } diff --git a/script/munin/parse_queue_length b/bin/munin/parse_queue_length similarity index 100% rename from script/munin/parse_queue_length rename to bin/munin/parse_queue_length diff --git a/script/munin/requests.sh b/bin/munin/requests.sh similarity index 100% rename from script/munin/requests.sh rename to bin/munin/requests.sh diff --git a/script/munin/response_time.sh b/bin/munin/response_time.sh similarity index 100% rename from script/munin/response_time.sh rename to bin/munin/response_time.sh diff --git a/script/munin/sidekiq_workers.sh b/bin/munin/sidekiq_workers.sh similarity index 100% rename from script/munin/sidekiq_workers.sh rename to bin/munin/sidekiq_workers.sh diff --git a/script/rails b/script/rails deleted file mode 100644 index f8da2cf..0000000 --- a/script/rails +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby -# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. - -APP_PATH = File.expand_path('../../config/application', __FILE__) -require File.expand_path('../../config/boot', __FILE__) -require 'rails/commands' From 08583082109408e40cd7fecbcaa936f66ec7bb93 Mon Sep 17 00:00:00 2001 From: Helge Rausch Date: Fri, 23 Oct 2015 21:43:25 +0200 Subject: [PATCH 03/11] Use sass-rails for CSS compression --- Gemfile | 17 ++++++++--------- Gemfile.lock | 12 ++++++++---- config/environments/production.rb | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Gemfile b/Gemfile index 67761a8..d010335 100644 --- a/Gemfile +++ b/Gemfile @@ -6,10 +6,10 @@ gem 'rails', '~> 4.2.0' gem 'authlogic' # lots of user-related magic gem 'i18n', '>= 0.6.6' gem 'rails3-generators' -gem "jquery-rails" -gem 'bcrypt-ruby', :require => "bcrypt" +gem 'jquery-rails' +gem 'bcrypt-ruby', :require => 'bcrypt' gem 'sanitize' -gem "recaptcha", :require => "recaptcha/rails" +gem 'recaptcha', :require => 'recaptcha/rails' gem 'dynamic_form' gem 'lograge' gem 'slop' @@ -34,13 +34,13 @@ gem 'pg_search' # so we can create zip-files for genotypes gem 'rubyzip' -gem "will_paginate" +gem 'will_paginate' gem 'nested_form', github: 'ryanb/nested_form' gem 'json' gem 'mediawiki-gateway' gem 'paperclip', '~> 4.0 ' gem 'friendly_id' -gem 'recommendify', github: 'paulasmuth/recommendify', :ref => "34308c4" +gem 'recommendify', github: 'paulasmuth/recommendify', :ref => '34308c4' # background jobs gem 'sidekiq' @@ -55,10 +55,9 @@ gem 'whenever', require: false gem 'therubyracer' gem 'execjs' gem 'uglifier' -gem 'yui-compressor' -gem "twitter-bootstrap-rails" -gem "jquery-ui-rails" -gem "sass" +gem 'twitter-bootstrap-rails' +gem 'jquery-ui-rails' +gem 'sass-rails' #group :production do # gem 'rpm_contrib' diff --git a/Gemfile.lock b/Gemfile.lock index 075f94d..0877b70 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -293,7 +293,13 @@ GEM crass (~> 1.0.2) nokogiri (>= 1.4.4) nokogumbo (= 1.4.1) - sass (3.4.13) + sass (3.4.19) + sass-rails (5.0.4) + railties (>= 4.0.0, < 5.0) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) scrypt (1.2.1) ffi-compiler (>= 0.0.2) rake @@ -365,7 +371,6 @@ GEM xpath (2.0.0) nokogiri (~> 1.3) yajl-ruby (1.2.1) - yui-compressor (0.12.0) PLATFORMS ruby @@ -410,7 +415,7 @@ DEPENDENCIES rubyzip rvm-capistrano (= 1.4.4) sanitize - sass + sass-rails shoulda-context sidekiq sidekiq-limit_fetch @@ -430,7 +435,6 @@ DEPENDENCIES webmock whenever will_paginate - yui-compressor BUNDLED WITH 1.10.6 diff --git a/config/environments/production.rb b/config/environments/production.rb index 0f261e0..7ff7b3a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -52,7 +52,7 @@ Snpr::Application.configure do # Compress JavaScript and CSS config.assets.compress = true config.assets.js_compressor = :uglifier - config.assets.css_compressor = :yui + #config.assets.css_compressor = :yui # Don't fallback to assets pipeline config.assets.compile = false From eeaf3bd847ec993bc535b358343f25618a98cf27 Mon Sep 17 00:00:00 2001 From: Helge Rausch Date: Sat, 24 Oct 2015 12:05:05 +0200 Subject: [PATCH 04/11] Add comment to .env.example --- .env.example | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.env.example b/.env.example index b71f09b..572ec16 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,9 @@ +# This file serves as a template for configuration through environment +# variables. It should always be sufficient for use in development and +# testing. It should also be always complete in a sense that all +# variables that can be set are included. It is used to extract a list +# of permitted variables for production during deployment, commented out +# or not. export SECRET_KEY_BASE=foo export SECRET_TOKEN=bar export RAILS_ENV=development From e4c268f5c83043df8eed1959a1219a61af0b0017 Mon Sep 17 00:00:00 2001 From: Helge Rausch Date: Fri, 23 Oct 2015 21:28:48 +0200 Subject: [PATCH 05/11] Trigger docker build when tests pass --- .travis.yml | 5 +++++ bin/deploy | 5 +++++ 2 files changed, 10 insertions(+) create mode 100755 bin/deploy diff --git a/.travis.yml b/.travis.yml index 13d846c..5b85cb6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,3 +17,8 @@ before_script: - cp .env.example .env - bundle exec rake db:setup script: bundle exec rake +deploy: + provider: script + script: bin/deploy + on: + branch: dockerize diff --git a/bin/deploy b/bin/deploy new file mode 100755 index 0000000..e5012a5 --- /dev/null +++ b/bin/deploy @@ -0,0 +1,5 @@ +#!/usr/bin/env sh + +curl -X POST \ + -d "build=true&source_type=Branch&source_name=dockerize" \ + https://registry.hub.docker.com/u/opensnp/rails/trigger/$DOCKERHUB_TRIGGER_TOKEN/ From eb4fbc5a1b2489aa983923181fa6ab6826935848 Mon Sep 17 00:00:00 2001 From: Helge Rausch Date: Fri, 23 Oct 2015 21:28:48 +0200 Subject: [PATCH 06/11] Update gems --- Gemfile.lock | 214 +++++++++++++++++++++++++++------------------------ 1 file changed, 115 insertions(+), 99 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 0877b70..50639ac 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -24,87 +24,102 @@ GIT GEM remote: http://rubygems.org/ specs: - actionmailer (4.2.2) - actionpack (= 4.2.2) - actionview (= 4.2.2) - activejob (= 4.2.2) + actionmailer (4.2.4) + actionpack (= 4.2.4) + actionview (= 4.2.4) + activejob (= 4.2.4) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.2) - actionview (= 4.2.2) - activesupport (= 4.2.2) + actionpack (4.2.4) + actionview (= 4.2.4) + activesupport (= 4.2.4) rack (~> 1.6) rack-test (~> 0.6.2) rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.1) - actionview (4.2.2) - activesupport (= 4.2.2) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (4.2.4) + activesupport (= 4.2.4) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.1) - activejob (4.2.2) - activesupport (= 4.2.2) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (4.2.4) + activesupport (= 4.2.4) globalid (>= 0.3.0) - activemodel (4.2.2) - activesupport (= 4.2.2) + activemodel (4.2.4) + activesupport (= 4.2.4) builder (~> 3.1) - activerecord (4.2.2) - activemodel (= 4.2.2) - activesupport (= 4.2.2) + activerecord (4.2.4) + activemodel (= 4.2.4) + activesupport (= 4.2.4) arel (~> 6.0) - activerecord-import (0.7.0) + activerecord-import (0.10.0) activerecord (>= 3.0) - activesupport (4.2.2) + activesupport (4.2.4) i18n (~> 0.7) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) addressable (2.3.8) - airbrake (4.1.0) + airbrake (4.3.3) builder multi_json - arel (6.0.0) - authlogic (3.4.5) + arel (6.0.3) + authlogic (3.4.6) activerecord (>= 3.2) activesupport (>= 3.2) request_store (~> 1.0) - scrypt (~> 1.2) + scrypt (>= 1.2, < 3.0) bcrypt (3.1.10) bcrypt-ruby (3.1.5) bcrypt (>= 3.1.3) builder (3.2.2) - capistrano (2.15.5) + capistrano (2.15.6) highline net-scp (>= 1.0.0) net-sftp (>= 2.0.0) net-ssh (>= 2.0.14) net-ssh-gateway (>= 1.1.0) - capybara (2.4.4) + capybara (2.5.0) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - celluloid (0.16.0) - timers (~> 4.0.0) + celluloid (0.17.2) + celluloid-essentials + celluloid-extras + celluloid-fsm + celluloid-pool + celluloid-supervision + timers (>= 4.1.1) + celluloid-essentials (0.20.5) + timers (>= 4.1.1) + celluloid-extras (0.20.5) + timers (>= 4.1.1) + celluloid-fsm (0.20.5) + timers (>= 4.1.1) + celluloid-pool (0.20.5) + timers (>= 4.1.1) + celluloid-supervision (0.20.5) + timers (>= 4.1.1) chronic (0.10.2) climate_control (0.0.3) activesupport (>= 3.0) cocaine (0.5.7) climate_control (>= 0.0.3, < 1.0) coderay (1.1.0) - composite_primary_keys (8.1.0) + composite_primary_keys (8.1.1) activerecord (~> 4.2.0) connection_pool (2.2.0) crack (0.4.2) safe_yaml (~> 1.0.0) crass (1.0.2) - database_cleaner (1.4.1) + database_cleaner (1.5.1) diff-lcs (1.2.5) docile (1.1.5) - domain_name (0.5.24) + domain_name (0.5.25) unf (>= 0.0.5, < 1.0.0) dotenv (2.0.2) dotenv-rails (2.0.2) @@ -118,20 +133,20 @@ GEM factory_girl_rails (4.5.0) factory_girl (~> 4.5.0) railties (>= 3.0.0) - ffi (1.9.8) + ffi (1.9.10) ffi-compiler (0.1.3) ffi (>= 1.0.0) rake - fitgem (0.10.0) + fitgem (0.12.1) oauth formatador (0.2.5) friendly_id (5.1.0) activerecord (>= 4.0.0) - globalid (0.3.5) + globalid (0.3.6) activesupport (>= 4.1.0) - guard (2.12.5) + guard (2.13.0) formatador (>= 0.2.4) - listen (~> 2.7) + listen (>= 2.7, <= 4.0) lumberjack (~> 1.0) nenv (~> 0.1) notiffany (~> 0.0) @@ -139,32 +154,32 @@ GEM shellany (~> 0.0) thor (>= 0.18.1) guard-compat (1.2.1) - guard-rspec (4.5.0) + guard-rspec (4.6.4) guard (~> 2.1) guard-compat (~> 1.1) rspec (>= 2.99.0, < 4.0) - highline (1.7.2) + hashdiff (0.2.2) + highline (1.7.8) hitimes (1.2.3) http-cookie (1.0.2) domain_name (~> 0.5) i18n (0.7.0) - jquery-rails (4.0.4) + jquery-rails (4.0.5) rails-dom-testing (~> 1.0) railties (>= 4.2.0) thor (>= 0.14, < 2.0) jquery-ui-rails (5.0.5) railties (>= 3.2.16) json (1.8.3) - libv8 (3.16.14.7) - listen (2.10.0) - celluloid (~> 0.16.0) + libv8 (3.16.14.13) + listen (3.0.3) rb-fsevent (>= 0.9.3) rb-inotify (>= 0.9) - lograge (0.3.2) + lograge (0.3.4) actionpack (>= 3) activesupport (>= 3) railties (>= 3) - loofah (2.0.2) + loofah (2.0.3) nokogiri (>= 1.5.9) lumberjack (1.0.9) mail (2.6.3) @@ -173,71 +188,71 @@ GEM rest-client (~> 1.7) metaclass (0.0.4) method_source (0.8.2) - mime-types (2.6.1) + mime-types (2.6.2) mimemagic (0.3.0) mini_portile (0.6.2) - minitest (5.7.0) + minitest (5.8.1) mocha (1.1.0) metaclass (~> 0.0.1) - multi_json (1.11.0) + multi_json (1.11.2) nenv (0.2.0) net-scp (1.2.1) net-ssh (>= 2.6.5) net-sftp (2.1.2) net-ssh (>= 2.6.5) - net-ssh (2.9.2) + net-ssh (3.0.1) net-ssh-gateway (1.2.0) net-ssh (>= 2.6.5) netrc (0.10.3) - newrelic_rpm (3.12.0.288) + newrelic_rpm (3.14.0.305) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) nokogumbo (1.4.1) nokogiri - notiffany (0.0.6) + notiffany (0.0.8) nenv (~> 0.1) shellany (~> 0.0) oauth (0.4.7) - paperclip (4.3.0) + paperclip (4.3.1) activemodel (>= 3.2.0) activesupport (>= 3.2.0) cocaine (~> 0.5.5) mime-types mimemagic (= 0.3.0) - pg (0.18.2) - pg_search (1.0.3) + pg (0.18.3) + pg_search (1.0.5) activerecord (>= 3.1) activesupport (>= 3.1) arel plos (0.0.7) nokogiri rest-client - power_assert (0.2.3) - pry (0.10.1) + power_assert (0.2.4) + pry (0.10.3) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) pry-rails (0.3.4) pry (>= 0.9.10) - rack (1.6.2) + rack (1.6.4) rack-protection (1.5.3) rack rack-test (0.6.3) rack (>= 1.0) - rails (4.2.2) - actionmailer (= 4.2.2) - actionpack (= 4.2.2) - actionview (= 4.2.2) - activejob (= 4.2.2) - activemodel (= 4.2.2) - activerecord (= 4.2.2) - activesupport (= 4.2.2) + rails (4.2.4) + actionmailer (= 4.2.4) + actionpack (= 4.2.4) + actionview (= 4.2.4) + activejob (= 4.2.4) + activemodel (= 4.2.4) + activerecord (= 4.2.4) + activesupport (= 4.2.4) bundler (>= 1.3.0, < 2.0) - railties (= 4.2.2) + railties (= 4.2.4) sprockets-rails rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.6) + rails-dom-testing (1.0.7) activesupport (>= 4.2.0.beta, < 5.0) nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) @@ -245,46 +260,46 @@ GEM loofah (~> 2.0) rails3-generators (1.0.0) railties (>= 3.0.0) - railties (4.2.2) - actionpack (= 4.2.2) - activesupport (= 4.2.2) + railties (4.2.4) + actionpack (= 4.2.4) + activesupport (= 4.2.4) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.4.2) - rb-fsevent (0.9.4) + rb-fsevent (0.9.6) rb-inotify (0.9.5) ffi (>= 0.5.0) recaptcha (0.4.0) redis (3.2.1) redis-namespace (1.5.2) redis (~> 3.0, >= 3.0.4) - ref (1.0.5) - request_store (1.1.0) + ref (2.0.0) + request_store (1.2.0) rest-client (1.8.0) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 3.0) netrc (~> 0.7) - rspec (3.2.0) - rspec-core (~> 3.2.0) - rspec-expectations (~> 3.2.0) - rspec-mocks (~> 3.2.0) - rspec-core (3.2.3) - rspec-support (~> 3.2.0) - rspec-expectations (3.2.1) + rspec (3.3.0) + rspec-core (~> 3.3.0) + rspec-expectations (~> 3.3.0) + rspec-mocks (~> 3.3.0) + rspec-core (3.3.2) + rspec-support (~> 3.3.0) + rspec-expectations (3.3.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.2.0) - rspec-mocks (3.2.1) + rspec-support (~> 3.3.0) + rspec-mocks (3.3.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.2.0) - rspec-rails (3.2.1) + rspec-support (~> 3.3.0) + rspec-rails (3.3.3) actionpack (>= 3.0, < 4.3) activesupport (>= 3.0, < 4.3) railties (>= 3.0, < 4.3) - rspec-core (~> 3.2.0) - rspec-expectations (~> 3.2.0) - rspec-mocks (~> 3.2.0) - rspec-support (~> 3.2.0) - rspec-support (3.2.2) + rspec-core (~> 3.3.0) + rspec-expectations (~> 3.3.0) + rspec-mocks (~> 3.3.0) + rspec-support (~> 3.3.0) + rspec-support (3.3.0) rubyzip (1.1.7) rvm-capistrano (1.4.4) capistrano (>= 2.15.4) @@ -300,13 +315,13 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - scrypt (1.2.1) + scrypt (2.0.2) ffi-compiler (>= 0.0.2) rake shellany (0.0.1) shoulda-context (1.2.1) - sidekiq (3.4.2) - celluloid (~> 0.16.0) + sidekiq (3.5.1) + celluloid (~> 0.17.2) connection_pool (~> 2.2, >= 2.2.0) json (~> 1.0) redis (~> 3.2, >= 3.2.1) @@ -326,17 +341,17 @@ GEM temple (~> 0.6.3) tilt (~> 1.3, >= 1.3.3) slop (3.6.0) - spring (1.3.6) + spring (1.4.0) spring-commands-rspec (1.0.4) spring (>= 0.9.1) - sprockets (3.2.0) - rack (~> 1.0) - sprockets-rails (2.3.1) + sprockets (3.4.0) + rack (> 1, < 3) + sprockets-rails (2.3.3) actionpack (>= 3.0) activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) temple (0.6.10) - test-unit (3.0.9) + test-unit (3.1.5) power_assert therubyracer (0.12.2) libv8 (~> 3.16.14.0) @@ -344,8 +359,8 @@ GEM thor (0.19.1) thread_safe (0.3.5) tilt (1.4.1) - timecop (0.7.3) - timers (4.0.4) + timecop (0.8.0) + timers (4.1.1) hitimes twitter-bootstrap-rails (3.2.0) actionpack (~> 4.1) @@ -362,9 +377,10 @@ GEM unf_ext (0.0.7.1) uuidtools (2.1.5) vcr (2.9.3) - webmock (1.21.0) + webmock (1.22.1) addressable (>= 2.3.6) crack (>= 0.3.2) + hashdiff whenever (0.9.4) chronic (>= 0.6.3) will_paginate (3.0.7) From 9e609fa24c40e686d5e0ffc51b37c95a0052cabe Mon Sep 17 00:00:00 2001 From: Helge Rausch Date: Fri, 23 Oct 2015 21:28:48 +0200 Subject: [PATCH 07/11] Load dotenv in production --- .env.example | 2 +- Gemfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 572ec16..6ab7e29 100644 --- a/.env.example +++ b/.env.example @@ -8,7 +8,7 @@ export SECRET_KEY_BASE=foo export SECRET_TOKEN=bar export RAILS_ENV=development export POSTGRES_URL="postgres://localhost/snpr_$RAILS_ENV" -#export REDIS_URL= +export REDIS_URL=redis://localhost export FITBIT_CONSUMER_KEY=foo export FITBIT_CONSUMER_SECRET=bar export PLOS_API_KEY=foo diff --git a/Gemfile b/Gemfile index d010335..4e176da 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'http://rubygems.org' -gem 'dotenv-rails', groups: %i(development test) +gem 'dotenv-rails' gem 'rails', '~> 4.2.0' gem 'authlogic' # lots of user-related magic From f53593fe71dfd204f5a10470b3ad91a6db2bf72e Mon Sep 17 00:00:00 2001 From: Helge Rausch Date: Fri, 23 Oct 2015 21:28:48 +0200 Subject: [PATCH 08/11] Log to stdout by default in production --- config/environments/production.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 7ff7b3a..02ac95b 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -23,7 +23,7 @@ Snpr::Application.configure do config.log_level = :info # Use a different logger for distributed setups - # config.logger = SyslogLogger.new + config.logger = Logger.new($stdout) # Use a different cache store in production # config.cache_store = :mem_cache_store From bb2d6d5ea476de88005424780d8a670b6456adec Mon Sep 17 00:00:00 2001 From: Helge Rausch Date: Thu, 29 Oct 2015 08:31:17 +0100 Subject: [PATCH 09/11] Deploy master branch --- .travis.yml | 2 +- bin/deploy | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5b85cb6..ac4f84b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,4 +21,4 @@ deploy: provider: script script: bin/deploy on: - branch: dockerize + branch: master diff --git a/bin/deploy b/bin/deploy index e5012a5..f397599 100755 --- a/bin/deploy +++ b/bin/deploy @@ -1,5 +1,5 @@ #!/usr/bin/env sh curl -X POST \ - -d "build=true&source_type=Branch&source_name=dockerize" \ + -d "build=true&source_type=Branch&source_name=master" \ https://registry.hub.docker.com/u/opensnp/rails/trigger/$DOCKERHUB_TRIGGER_TOKEN/ From 0d95a9632db34f02de863603254829fd29900735 Mon Sep 17 00:00:00 2001 From: Helge Rausch Date: Thu, 29 Oct 2015 08:51:11 +0100 Subject: [PATCH 10/11] Use new hash syntax --- Gemfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 4e176da..46d9921 100644 --- a/Gemfile +++ b/Gemfile @@ -7,9 +7,9 @@ gem 'authlogic' # lots of user-related magic gem 'i18n', '>= 0.6.6' gem 'rails3-generators' gem 'jquery-rails' -gem 'bcrypt-ruby', :require => 'bcrypt' +gem 'bcrypt-ruby', require: 'bcrypt' gem 'sanitize' -gem 'recaptcha', :require => 'recaptcha/rails' +gem 'recaptcha', require: 'recaptcha/rails' gem 'dynamic_form' gem 'lograge' gem 'slop' @@ -40,7 +40,7 @@ gem 'json' gem 'mediawiki-gateway' gem 'paperclip', '~> 4.0 ' gem 'friendly_id' -gem 'recommendify', github: 'paulasmuth/recommendify', :ref => '34308c4' +gem 'recommendify', github: 'paulasmuth/recommendify', ref: '34308c4' # background jobs gem 'sidekiq' From bde8095716455f497ff312d313c3df064a46d1c7 Mon Sep 17 00:00:00 2001 From: Helge Rausch Date: Sat, 31 Oct 2015 12:02:41 +0100 Subject: [PATCH 11/11] Add more text about how to set up the environment --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 50e1987..4e90939 100644 --- a/README.md +++ b/README.md @@ -34,12 +34,14 @@ rake db:seed OR rake db:setup (which also sets up the entire db) ## Setup Config -``` -# edit database.yml to point to your postgresql database -cp config/database.yml.example config/database.yml +All configuration is done via environment variables. A file with a +working environment for development can be found at `.env.example`. +Simply copy it to `.env` to use it as is. The +[dotenv](https://github.com/bkeepers/dotenv) gem will pick it up +and set the environment variables. -cp .env.example .env -``` +Copy `config/database.yml.example` to `config/database.yml` and adapt to +your database setup. ## Initialize Database