diff --git a/.gitignore b/.gitignore index a812f1ce3..f2e8c948b 100644 --- a/.gitignore +++ b/.gitignore @@ -27,8 +27,6 @@ /config/initializers/devise.rb /config/facebook.yml /.idea/ -/config/deploy.rb -/Capfile /config/newrelic.yml @@ -37,7 +35,6 @@ .ruby-version .ruby-env -/config/database.yml /config/puma.rb # Ignore 1337 secrets diff --git a/Capfile b/Capfile new file mode 100644 index 000000000..a204fd415 --- /dev/null +++ b/Capfile @@ -0,0 +1,26 @@ +# Load DSL and Setup Up Stages +require 'capistrano/setup' + +# Includes default deployment tasks +require 'capistrano/deploy' + +# Include bundler related tasks +require 'capistrano/bundler' + +# Includes tasks from other gems included in your Gemfile +# +# For documentation on these, see for example: +# +# https://github.com/capistrano/rvm +# https://github.com/capistrano/rbenv +# https://github.com/capistrano/chruby +# https://github.com/capistrano/bundler +# https://github.com/capistrano/rails +# +require 'capistrano/rvm' +require 'capistrano/rails/assets' +require 'capistrano/rails/migrations' +require 'capistrano/puma' + +# Loads custom tasks from `lib/capistrano/tasks' if you have any defined. +Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } diff --git a/Gemfile b/Gemfile index b36d983ee..1511234f6 100644 --- a/Gemfile +++ b/Gemfile @@ -110,8 +110,12 @@ gem 'rollbar' # Use unicorn as the app server # gem 'unicorn' -#Deploy with Capistrano +# Deploy with Capistrano gem 'capistrano' +gem 'capistrano-bundler' +gem 'capistrano-rvm' +gem 'capistrano-rails' +gem 'capistrano3-puma' # To use debugger # gem 'debugger' diff --git a/Gemfile.lock b/Gemfile.lock index 8c3069ee9..d28dbbec5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -64,9 +64,9 @@ GEM acts_as_paranoid (0.4.3) activerecord (~> 3.2) acts_as_votable (0.7.1) - addressable (2.3.6) + addressable (2.3.8) angular-ui-sortable-rails (0.0.2) - angularjs-rails (1.2.21) + angularjs-rails (1.3.15) arel (3.0.3) aws-sdk (1.28.0) json (~> 1.4) @@ -76,18 +76,19 @@ GEM htmlentities (~> 4.3.1) nokogiri (>= 1.4.1) rubyzip (= 0.9.9) - bcrypt (3.1.7) - bcrypt (3.1.7-x86-mingw32) + bcrypt (3.1.10) + bcrypt (3.1.10-x86-mingw32) bcrypt-ruby (3.1.5) bcrypt (>= 3.1.3) bcrypt-ruby (3.1.5-x86-mingw32) bcrypt (>= 3.1.3) - best_in_place (2.1.0) - jquery-rails - rails (~> 3.1) - better_errors (1.1.0) + best_in_place (3.0.3) + actionpack (>= 3.2) + railties (>= 3.2) + better_errors (2.1.1) coderay (>= 1.0.0) erubis (>= 2.6.6) + rack (>= 0.9.0) bootstrap-colorpicker-rails (0.3.1) railties (>= 3.0) bootstrap-datetimepicker-rails (0.0.11) @@ -95,27 +96,39 @@ GEM bootstrap-select-rails (1.6.3) builder (3.0.4) callsite (0.0.11) - cancancan (1.9.2) - capistrano (3.2.1) + cancancan (1.10.1) + capistrano (3.4.0) i18n rake (>= 10.0.0) sshkit (~> 1.3) - capybara (2.4.1) + capistrano-bundler (1.1.4) + capistrano (~> 3.1) + sshkit (~> 1.2) + capistrano-rails (1.1.3) + capistrano (~> 3.1) + capistrano-bundler (~> 1.1) + capistrano-rvm (0.1.2) + capistrano (~> 3.0) + sshkit (~> 1.2) + capistrano3-puma (0.9.0) + capistrano (~> 3.0) + puma (>= 2.6) + capybara (2.4.4) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - celluloid (0.15.2) - timers (~> 1.1.0) - childprocess (0.5.3) + celluloid (0.16.0) + timers (~> 4.0.0) + childprocess (0.5.6) ffi (~> 1.0, >= 1.0.11) climate_control (0.0.3) activesupport (>= 3.0) - clockwork (0.7.7) + clockwork (1.2.0) activesupport tzinfo - cocaine (0.5.4) + cocaine (0.5.7) climate_control (>= 0.0.3, < 1.0) cocoon (1.2.6) codemirror-rails (3.24) @@ -124,25 +137,25 @@ GEM coffee-rails (3.2.2) coffee-script (>= 2.2.0) railties (~> 3.2.0) - coffee-script (2.3.0) + coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.7.1) - colorize (0.7.3) - connection_pool (2.0.0) - coveralls (0.7.1) - multi_json (~> 1.3) - rest-client - simplecov (>= 0.7) - term-ansicolor - thor - crass (0.2.1) - daemons (1.1.9) - dalli (2.7.2) - delayed_job (4.0.2) - activesupport (>= 3.0, < 4.2) - delayed_job_active_record (4.0.1) - activerecord (>= 3.0, < 4.2) + coffee-script-source (1.9.1.1) + colorize (0.7.7) + connection_pool (2.2.0) + coveralls (0.8.1) + json (~> 1.8) + rest-client (>= 1.6.8, < 2) + simplecov (~> 0.10.0) + term-ansicolor (~> 1.3) + thor (~> 0.19.1) + crass (1.0.2) + daemons (1.2.2) + dalli (2.7.4) + delayed_job (4.0.6) + activesupport (>= 3.0, < 5.0) + delayed_job_active_record (4.0.3) + activerecord (>= 3.0, < 5.0) delayed_job (>= 3.0, < 4.1) devise (3.0.0) bcrypt-ruby (~> 3.0) @@ -151,22 +164,23 @@ GEM warden (~> 1.2.3) diff-lcs (1.2.5) docile (1.1.5) - dotenv (1.0.2) - dotenv-rails (1.0.2) - dotenv (= 1.0.2) + domain_name (0.5.24) + unf (>= 0.0.5, < 1.0.0) + dotenv (2.0.1) + dotenv-rails (2.0.1) + dotenv (= 2.0.1) erubis (2.7.0) - execjs (2.2.1) - factory_girl (4.4.0) + execjs (2.5.2) + factory_girl (4.5.0) activesupport (>= 3.0.0) - factory_girl_rails (4.4.1) - factory_girl (~> 4.4.0) + factory_girl_rails (4.5.0) + factory_girl (~> 4.5.0) railties (>= 3.0.0) - faker (1.4.2) + faker (1.4.3) i18n (~> 0.5) - faraday (0.9.0) + faraday (0.9.1) multipart-post (>= 1.2, < 3) - ffi (1.9.3) - ffi (1.9.3-x86-mingw32) + ffi (1.9.8-x86-mingw32) font-awesome-sass-rails (3.0.2.2) railties (>= 3.1.1) sass-rails (>= 3.1.1) @@ -174,61 +188,72 @@ GEM fuubar (2.0.0) rspec (~> 3.0) ruby-progressbar (~> 1.4) - gon (5.1.2) + gon (5.2.3) actionpack (>= 2.3.0) json multi_json request_store (>= 1.0.5) - google_visualr (2.3.0) - guard (2.6.1) + google_visualr (2.4.0) + guard (2.12.5) formatador (>= 0.2.4) listen (~> 2.7) lumberjack (~> 1.0) + nenv (~> 0.1) + notiffany (~> 0.0) pry (>= 0.9.12) + shellany (~> 0.0) thor (>= 0.18.1) - guard-rspec (4.3.1) + guard-compat (1.2.1) + guard-rspec (4.5.0) guard (~> 2.1) - rspec (>= 2.14, < 4.0) - guard-spork (1.5.1) + guard-compat (~> 1.1) + rspec (>= 2.99.0, < 4.0) + guard-spork (2.1.0) childprocess (>= 0.2.3) - guard (>= 1.1) + guard (~> 2.0) + guard-compat (~> 1.0) spork (>= 0.8.4) - haml (4.0.5) + haml (4.0.6) tilt - hashie (3.2.0) + hashie (3.4.1) hike (1.2.3) - htmlentities (4.3.2) - i18n (0.6.11) + hitimes (1.2.2) + hitimes (1.2.2-x86-mingw32) + htmlentities (4.3.3) + http-cookie (1.0.2) + domain_name (~> 0.5) + i18n (0.7.0) imagesLoaded_rails (3.1.8) railties (>= 3.1) journey (1.0.4) jqtree-rails (0.1.8.1) railties (>= 3.2.0, < 5.0) thor (~> 0.14) - jquery-fileupload-rails (0.4.1) + jquery-fileupload-rails (0.4.5) actionpack (>= 3.1) railties (>= 3.1) + sass (>= 3.2) jquery-rails (2.1.3) railties (>= 3.1.0, < 5.0) thor (~> 0.14) jquery-tmpl-rails (1.1.0) rails (>= 3.1.0) - jquery-validation-rails (1.12.0) + jquery-validation-rails (1.13.1) railties (>= 3.2, < 5.0) thor (~> 0.14) - json (1.8.1) - jwt (1.0.0) - kaminari (0.16.1) + json (1.8.2) + jwt (1.4.1) + kaminari (0.16.3) actionpack (>= 3.0.0) activesupport (>= 3.0.0) - koala (1.10.0) + koala (2.0.0) addressable faraday multi_json - launchy (2.4.2) + launchy (2.4.3) addressable (~> 2.3) - listen (2.7.9) - celluloid (>= 0.15.2) + listen (2.10.0) + celluloid (~> 0.16.0) rb-fsevent (>= 0.9.3) rb-inotify (>= 0.9) lumberjack (1.0.9) @@ -243,25 +268,30 @@ GEM railties (>= 3.0.0, < 5.0.0) method_source (0.8.2) mime-types (1.25.1) - mini_portile (0.6.0) - momentjs-rails (2.8.1) + mini_portile (0.6.2) + momentjs-rails (2.10.2) railties (>= 3.1) - multi_json (1.10.1) + multi_json (1.11.0) multi_xml (0.5.5) multipart-post (2.0.0) - mysql2 (0.3.16) + mysql2 (0.3.18) + mysql2 (0.3.18-x86-mingw32) natcmp (1.4.1) + nenv (0.2.0) net-scp (1.2.1) net-ssh (>= 2.6.5) - net-ssh (2.9.1) - netrc (0.8.0) - newrelic_rpm (3.9.1.236) - nokogiri (1.6.3.1) - mini_portile (= 0.6.0) - nokogiri (1.6.3.1-x86-mingw32) - mini_portile (= 0.6.0) - nokogumbo (1.1.9) + net-ssh (2.9.2) + netrc (0.10.3) + newrelic_rpm (3.11.2.286) + nokogiri (1.6.6.2) + mini_portile (~> 0.6.0) + nokogiri (1.6.6.2-x86-mingw32) + mini_portile (~> 0.6.0) + nokogumbo (1.4.1) nokogiri + notiffany (0.0.6) + nenv (~> 0.1) + shellany (~> 0.0) oauth2 (1.0.0) faraday (>= 0.8, < 0.10) jwt (~> 1.0) @@ -271,11 +301,9 @@ GEM omniauth (1.2.2) hashie (>= 1.2, < 4) rack (~> 1.0) - omniauth-facebook (2.0.0) + omniauth-facebook (2.0.1) omniauth-oauth2 (~> 1.2) - omniauth-oauth2 (1.2.0) - faraday (>= 0.8, < 0.10) - multi_json (~> 1.3) + omniauth-oauth2 (1.3.0) oauth2 (~> 1.0) omniauth (~> 1.2) orm_adapter (0.5.0) @@ -285,27 +313,27 @@ GEM cocaine (~> 0.5.3) mime-types polyglot (0.3.5) - pry (0.10.0) + pry (0.10.1) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) - pry (0.10.0-x86-mingw32) + pry (0.10.1-x86-mingw32) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) win32console (~> 1.3) - pry-rails (0.3.2) + pry-rails (0.3.4) pry (>= 0.9.10) puma (2.6.0) rack (>= 1.1, < 2.0) rack (1.4.5) rack-cache (1.2) rack (>= 0.4) - rack-contrib (1.1.0) + rack-contrib (1.2.0) rack (>= 0.9.1) rack-ssl (1.3.4) rack - rack-test (0.6.2) + rack-test (0.6.3) rack (>= 1.0) rails (3.2.14) actionmailer (= 3.2.14) @@ -315,7 +343,7 @@ GEM activesupport (= 3.2.14) bundler (~> 1.0) railties (= 3.2.14) - rails-assets-fabric (1.4.13) + rails-assets-fabric (1.5.0) railties (3.2.14) actionpack (= 3.2.14) activesupport (= 3.2.14) @@ -323,60 +351,64 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) - rake (10.3.2) + rake (10.4.2) rb-fsevent (0.9.4) rb-inotify (0.9.5) ffi (>= 0.5.0) rdoc (3.12.2) json (~> 1.4) - request_store (1.0.8) - rest-client (1.7.2) + request_store (1.1.0) + rest-client (1.8.0) + http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 3.0) netrc (~> 0.7) - rest-client (1.7.2-x86-mingw32) + rest-client (1.8.0-x86-mingw32) ffi (~> 1.9) + http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 3.0) netrc (~> 0.7) - rollbar (1.3.1) + rollbar (1.5.1) multi_json (~> 1.3) - rspec (3.0.0) - rspec-core (~> 3.0.0) - rspec-expectations (~> 3.0.0) - rspec-mocks (~> 3.0.0) - rspec-core (3.0.3) - rspec-support (~> 3.0.0) - rspec-expectations (3.0.3) + 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) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.0.0) - rspec-mocks (3.0.3) - rspec-support (~> 3.0.0) - rspec-rails (3.0.2) - actionpack (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 3.0.0) - rspec-expectations (~> 3.0.0) - rspec-mocks (~> 3.0.0) - rspec-support (~> 3.0.0) - rspec-support (3.0.3) - ruby-progressbar (1.7.0) + rspec-support (~> 3.2.0) + rspec-mocks (3.2.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.2.0) + rspec-rails (3.2.1) + 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) + ruby-progressbar (1.7.5) rubyzip (0.9.9) - sanitize (3.0.0) - crass (~> 0.2.0) + sanitize (4.0.0) + crass (~> 1.0.2) nokogiri (>= 1.4.4) - nokogumbo (= 1.1.9) - sass (3.3.14) + nokogumbo (= 1.4.1) + sass (3.4.13) sass-rails (3.2.6) railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) scrollToFixed_rails (1.0.5) railties (>= 3.1) - simplecov (0.9.1) + shellany (0.0.1) + simplecov (0.10.0) docile (~> 1.1.0) - multi_json (~> 1.0) - simplecov-html (~> 0.8.0) - simplecov-html (0.8.0) + json (~> 1.8) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.0) slop (3.6.0) slugged (2.0.0) activerecord (>= 3.0) @@ -388,31 +420,36 @@ GEM spork-rails (4.0.0) rails (>= 3.0.0, < 5) spork (>= 1.0rc0) - spring (1.1.3) - sprockets (2.2.2) + spring (1.3.4) + sprockets (2.2.3) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - sshkit (1.5.1) - colorize + sshkit (1.7.1) + colorize (>= 0.7.0) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) - systemu (2.6.4) + systemu (2.6.5) term-ansicolor (1.3.0) tins (~> 1.0) thor (0.19.1) tilt (1.4.1) - timers (1.1.0) - tins (1.3.3) + timers (4.0.1) + hitimes + tins (1.5.1) treetop (1.4.15) polyglot polyglot (>= 0.3.1) - truncate_html (0.9.2) - tzinfo (0.3.41) - uglifier (2.5.3) + truncate_html (0.9.3) + tzinfo (0.3.44) + uglifier (2.7.1) execjs (>= 0.3.0) json (>= 1.8.0) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.1) + unf_ext (0.0.7.1-x86-mingw32) uuid (2.3.7) macaddr (~> 1.0) uuidtools (2.1.5) @@ -420,13 +457,15 @@ GEM rack (>= 1.0) wicked_pdf (0.11.0) rails - win32-process (0.7.4) + win32-process (0.7.5) ffi (>= 1.0.0) win32console (1.3.2-x86-mingw32) wkhtmltopdf_binary_provider (0.12.0) xpath (2.0.0) nokogiri (~> 1.3) - yaml_db (0.2.3) + yaml_db (0.3.0) + rails (>= 3.0, < 4.3) + rake (>= 0.8.7) PLATFORMS ruby @@ -450,6 +489,10 @@ DEPENDENCIES bootstrap-wysihtml5-rails! cancancan (~> 1.8) capistrano + capistrano-bundler + capistrano-rails + capistrano-rvm + capistrano3-puma capybara clockwork cocoon diff --git a/config/deploy.rb b/config/deploy.rb new file mode 100644 index 000000000..8ba9b7195 --- /dev/null +++ b/config/deploy.rb @@ -0,0 +1,13 @@ +lock '3.2.1' + +set :application, 'coursemology' + +set :repo_url, 'git@github.com:coursemology/coursemology.org.git' +set :branch, 'development' +set :deploy_via, :remote_cache + +set :linked_dirs, ['log', 'tmp/cache', 'tmp/sockets', 'tmp/pids'] + +namespace :deploy do + after :finished, 'puma:restart' +end diff --git a/config/deploy/production.rb b/config/deploy/production.rb new file mode 100644 index 000000000..9784ea412 --- /dev/null +++ b/config/deploy/production.rb @@ -0,0 +1,6 @@ +user = 'raymoond' +hostname = 'coursemology.org' + +server hostname, user: user, roles: %w{web app db}, primary: true + +set :rails_env, 'production' diff --git a/prox.config b/prox.config deleted file mode 100644 index 26fd93d56..000000000 --- a/prox.config +++ /dev/null @@ -1,38 +0,0 @@ -upstream nodes { - ip_hash; - server 192.241.237.84:80; -} - -server { - listen 80; - server_name coursemology.com www.coursemology.com; - root /var/www/coursemology/public; - - location / { - client_max_body_size 50M; - proxy_set_header Host $http_host; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - if (-f $request_filename) { - break; - } - - if (-f $request_filename/index.html) { - rewrite (.*) $1/index.html break; - } - - if (-f $request_filename.html) { - rewrite (.*) $1.html break; - } - - if (!-f $request_filename) { - proxy_pass http://nodes; - break; - } - } - location ~* .(jpg|png|gif|jpeg|css|mp3|wav|swf|mov|doc|pdf|xls|ppt|docx|pptx|xlsx)$ { - proxy_cache_valid 200 120m; - expires 604800; - proxy_pass http://apachesyslogtv; - proxy_cache cache; - } -} \ No newline at end of file diff --git a/puma.sh b/puma.sh deleted file mode 100755 index e1c226110..000000000 --- a/puma.sh +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env bash -# Simple move this file into your Rails `script` folder. Also make sure you `chmod +x puma.sh`. -# Please modify the CONSTANT variables to fit your configurations. - -PUMA_CONFIG_FILE=config/puma.rb -PUMA_PID_FILE=tmp/pids/puma.pid -PUMA_SOCKET=tmp/sockets/puma.sock - -. ~/.bash_profile - -puma_is_running() { - if [ -e $PUMA_PID_FILE ] ; then - FILENAME=$PUMA_PID_FILE - PID=0 - while read LINE - do - PID=$LINE - done < $FILENAME - - if ps -p $PID > /dev/null - then - return 0 - else - return 1 - fi - else - return 1 - fi -} - -puma_high_memo() { - echo "check memory usage" - FILENAME=$PUMA_PID_FILE - PID=0 - while read LINE - do - PID=$LINE - done < $FILENAME - - t=$(ps -p $PID -o %mem) - p=0 - for word in $t - do - p=$word - done - echo "mem $p%" - - if [ $(echo "$p > 40" | bc) -ne 0 ] ; then - return 0 - else - return 1 - fi -} - -rvm use ruby-2.1.2 - -if [ $# -gt 0 ]; then - #clean memory - if puma_is_running ; then - if puma_high_memo ; then - echo "we need to clean memo" - pumactl -P $PUMA_PID_FILE restart - else - echo "memory usage normal" - fi - exit 0 - fi -else - #restart - echo "we want to restart puma" - - if puma_is_running ; then - echo "Hot-restarting puma..." - pumactl -P $PUMA_PID_FILE restart - - echo "Doublechecking the process restart..." - sleep 5 - if puma_is_running ; then - echo "done" - exit 0 - else - echo "Puma restart failed :/" - fi - fi -fi - -puma --config $PUMA_CONFIG_FILE - - diff --git a/remove_duplicate.sql b/remove_duplicate.sql deleted file mode 100644 index e7479b65d..000000000 --- a/remove_duplicate.sql +++ /dev/null @@ -1,11 +0,0 @@ -delete from seen_by_users where id not in - (select * from - (select distinct(del.id) from ( - select id, obj_id, obj_type, user_course_id, MAX(created_at) as created_at - from seen_by_users - group by obj_id, obj_type, user_course_id) - as del INNER JOIN seen_by_users AS hs ON - hs.obj_type=del.obj_type - AND hs.obj_id = del.obj_id - AND hs.user_course_id=del.user_course_id - AND hs.created_at = del.created_at) as we) \ No newline at end of file