From 62814ba7772877e7fbcabf88298e6fa58965c4a9 Mon Sep 17 00:00:00 2001 From: Everaldo Gomes Date: Fri, 29 Aug 2014 15:01:43 +0000 Subject: [PATCH 01/16] updated readme - install instructions - imagemagick installation --- README.markdown | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.markdown b/README.markdown index 8f25a4f..1b0072c 100644 --- a/README.markdown +++ b/README.markdown @@ -10,6 +10,22 @@ O projeto usa o controle de versão [GIT-SCM](http://git-scm.com) e se caso voc - Planeje a sua feature e implemente em um feature branch, o seu feature branch deve conter ser branch com o nome da sua fuature e deve implementar os devidos testes. - Feita a sua implementação de feature com todos os teste passando (todos testes verdinhos) envie um `Pull Request` para o projeto principal no tecnobest e aguarde o *Code Review*. +## Setup do Projeto + +- Instale o Ruby, versão 2.1.2 + +### Dependências + +- Image Magic + +``` +sudo apt-get update +sudo apt-get install imagemagick libmagickcore-dev +sudo apt-get install libmagickwand-dev +``` + + + ### Como fazer o *code review* e workflow de aprovação para *Pull Requests* A metodologia de não aceitar os commits diretamente no repositório TecnoBest/teno_freela é exatamente melhorar a qualidade através do Code Review do código onde o avaliador pode observar o emprego de boas práticas e convenções ou ainda sugerir melhorias em algoritmos compatíveis com o uso comum do dia-a-dia. Para aprovação de um *Pull Request* o avaliador deve: From 6acf94aaa21dd611229d35d4657cb789f047e0a7 Mon Sep 17 00:00:00 2001 From: Everaldo Gomes Date: Fri, 29 Aug 2014 15:10:39 +0000 Subject: [PATCH 02/16] Updated Ruby to 2.1.2 It was necessary to uninstall pry-debugger in favor of pry-byebug, because the debugger gem doesn't offer full support to Rails 2 References: http://stackoverflow.com/questions/20826568/debugger-gem-not-supported-in-ruby-2-1-0-2-1-1-2-1-2 https://github.com/cldwalker/debugger/issues/125#issuecomment-43353446 --- Gemfile | 4 ++-- Gemfile.lock | 18 ++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index 84f4ce5..457ee85 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby '2.0.0' +ruby '2.1.2' gem 'rails', '4.0.2' gem 'cancan' gem 'devise' @@ -27,7 +27,7 @@ gem 'rails_layout' group :development do - gem 'pry-debugger' + gem 'pry-byebug' gem 'pry-rails' gem 'better_errors' gem 'binding_of_caller', platforms: [:mri_19, :mri_20, :rbx] diff --git a/Gemfile.lock b/Gemfile.lock index 0de3d48..c888f4a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -50,6 +50,9 @@ GEM railties (>= 3.0) bson (2.1.2) builder (3.1.4) + byebug (2.7.0) + columnize (~> 0.3) + debugger-linecache (~> 1.2) cancan (1.6.10) capybara (2.1.0) mime-types (>= 1.16) @@ -76,16 +79,11 @@ GEM coffee-script-source execjs coffee-script-source (1.6.3) - columnize (0.3.6) + columnize (0.8.9) connection_pool (1.2.0) database_cleaner (1.0.1) debug_inspector (0.0.2) - debugger (1.6.5) - columnize (>= 0.3.1) - debugger-linecache (~> 1.2.0) - debugger-ruby_core_source (~> 1.3.1) debugger-linecache (1.2.0) - debugger-ruby_core_source (1.3.1) devise (3.2.2) bcrypt-ruby (~> 3.0) orm_adapter (~> 0.1) @@ -171,9 +169,9 @@ GEM coderay (~> 1.0) method_source (~> 0.8) slop (~> 3.4) - pry-debugger (0.2.2) - debugger (~> 1.3) - pry (~> 0.9.10) + pry-byebug (1.3.2) + byebug (~> 2.7) + pry (~> 0.9.12) pry-rails (0.3.2) pry (>= 0.9.10) quiet_assets (1.0.2) @@ -300,7 +298,7 @@ DEPENDENCIES jquery-rails mongoid! mongoid_taggable - pry-debugger + pry-byebug pry-rails quiet_assets rails (= 4.0.2) From 36679f8b7f4c7c90924b67789652a24812b90b30 Mon Sep 17 00:00:00 2001 From: Everaldo Gomes Date: Fri, 29 Aug 2014 15:21:20 +0000 Subject: [PATCH 03/16] updated rails and sass-rails versions --- Gemfile | 4 +- Gemfile.lock | 280 ++++++++++++++++++++++++++++----------------------- 2 files changed, 154 insertions(+), 130 deletions(-) diff --git a/Gemfile b/Gemfile index 457ee85..e1a45a7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' ruby '2.1.2' -gem 'rails', '4.0.2' +gem 'rails', '4.2.0.beta1' gem 'cancan' gem 'devise' gem 'figaro' @@ -13,7 +13,7 @@ gem 'simple_form' gem 'rmagick' gem 'geocoder' gem 'mongoid_taggable' -gem 'sass-rails', '~> 4.0.0' +gem 'sass-rails', '~> 5.0.0.beta1' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.0.0' gem 'therubyracer', platforms: :ruby diff --git a/Gemfile.lock b/Gemfile.lock index c888f4a..543546d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,55 +1,64 @@ GIT remote: git://github.com/mongoid/mongoid.git - revision: c6b832990cb9a09141c3eb381355117e9f9e2c62 + revision: 4e3b39e9bbcf1b36d0472c6b09f8f394c55065f4 specs: - mongoid (4.0.0.alpha2) - activemodel (>= 4.0.0) - moped (~> 2.0.beta5) + mongoid (4.0.0) + activemodel (~> 4.0) + moped (~> 2.0.0) origin (~> 2.1) tzinfo (>= 0.3.37) GEM remote: https://rubygems.org/ specs: - actionmailer (4.0.2) - actionpack (= 4.0.2) - mail (~> 2.5.4) - actionpack (4.0.2) - activesupport (= 4.0.2) - builder (~> 3.1.0) - erubis (~> 2.7.0) - rack (~> 1.5.2) + actionmailer (4.2.0.beta1) + actionpack (= 4.2.0.beta1) + actionview (= 4.2.0.beta1) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 1.0, >= 1.0.2) + actionpack (4.2.0.beta1) + actionview (= 4.2.0.beta1) + activesupport (= 4.2.0.beta1) + rack (~> 1.6.0.beta) rack-test (~> 0.6.2) - activemodel (4.0.2) - activesupport (= 4.0.2) - builder (~> 3.1.0) - activerecord (4.0.2) - activemodel (= 4.0.2) - activerecord-deprecated_finders (~> 1.0.2) - activesupport (= 4.0.2) - arel (~> 4.0.0) - activerecord-deprecated_finders (1.0.3) - activesupport (4.0.2) - i18n (~> 0.6, >= 0.6.4) - minitest (~> 4.2) - multi_json (~> 1.3) + rails-deprecated_sanitizer (~> 1.0, >= 1.0.2) + rails-dom-testing (~> 1.0, >= 1.0.2) + actionview (4.2.0.beta1) + activesupport (= 4.2.0.beta1) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-deprecated_sanitizer (~> 1.0, >= 1.0.2) + rails-dom-testing (~> 1.0, >= 1.0.2) + activejob (4.2.0.beta1) + globalid (>= 0.2.3) + activemodel (4.2.0.beta1) + activesupport (= 4.2.0.beta1) + builder (~> 3.1) + activerecord (4.2.0.beta1) + activemodel (= 4.2.0.beta1) + activesupport (= 4.2.0.beta1) + arel (>= 6.0.0.beta1, < 6.1) + activesupport (4.2.0.beta1) + i18n (>= 0.7.0.beta1, < 0.8) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) thread_safe (~> 0.1) - tzinfo (~> 0.3.37) + tzinfo (~> 1.1) addressable (2.3.6) - arel (4.0.1) - atomic (1.1.14) - bcrypt-ruby (3.1.2) - better_errors (1.1.0) + arel (6.0.0.beta1) + bcrypt (3.1.7) + better_errors (2.0.0) coderay (>= 1.0.0) erubis (>= 2.6.6) + rack (>= 0.9.0) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) - bootstrap-sass (3.0.3.0) + bootstrap-sass (3.2.0.1) sass (~> 3.2) - bootstrap-wysihtml5-rails (0.3.1.23) + bootstrap-wysihtml5-rails (0.3.2.100) railties (>= 3.0) - bson (2.1.2) - builder (3.1.4) + bson (2.3.0) + builder (3.2.2) byebug (2.7.0) columnize (~> 0.3) debugger-linecache (~> 1.2) @@ -60,13 +69,15 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - carrierwave (0.9.0) + carrierwave (0.10.0) activemodel (>= 3.2.0) activesupport (>= 3.2.0) json (>= 1.7) - carrierwave-mongoid (0.1.0) - carrierwave - mongoid + mime-types (>= 1.16) + carrierwave-mongoid (0.7.1) + carrierwave (>= 0.8.0, < 0.11.0) + mongoid (>= 3.0, < 5.0) + mongoid-grid_fs (>= 1.3, < 3.0) celluloid (0.15.2) timers (~> 1.1.0) childprocess (0.5.3) @@ -75,17 +86,17 @@ GEM coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) - coffee-script (2.2.0) + coffee-script (2.3.0) coffee-script-source execjs - coffee-script-source (1.6.3) + coffee-script-source (1.8.0) columnize (0.8.9) - connection_pool (1.2.0) + connection_pool (2.0.0) database_cleaner (1.0.1) debug_inspector (0.0.2) debugger-linecache (1.2.0) - devise (3.2.2) - bcrypt-ruby (~> 3.0) + devise (3.3.0) + bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 3.2.6, < 5) thread_safe (~> 0.1) @@ -95,7 +106,7 @@ GEM launchy (~> 2.1) mail (~> 2.2) erubis (2.7.0) - execjs (2.0.2) + execjs (2.2.1) factory_girl (4.2.0) activesupport (>= 3.0.0) factory_girl_rails (4.2.1) @@ -105,18 +116,20 @@ GEM figaro (0.7.0) bundler (~> 1.0) rails (>= 3, < 5) - formatador (0.2.4) - geocoder (1.1.9) - guard (2.3.0) + formatador (0.2.5) + geocoder (1.2.4) + globalid (0.2.3) + activesupport (>= 4.1.0) + guard (2.6.1) formatador (>= 0.2.4) - listen (~> 2.1) + listen (~> 2.7) lumberjack (~> 1.0) pry (>= 0.9.12) thor (>= 0.18.1) - guard-rspec (4.2.4) + guard-rspec (4.3.1) guard (~> 2.1) rspec (>= 2.14, < 4.0) - haml (4.0.5) + haml (4.1.0.beta.1) tilt haml-rails (0.5.3) actionpack (>= 4.0.1) @@ -130,142 +143,153 @@ GEM haml (>= 4.0.0.rc.1) hpricot (~> 0.8.6) ruby_parser (~> 3.1.1) - i18n (0.6.9) - jquery-rails (3.0.4) + i18n (0.7.0.beta1) + jquery-rails (3.1.1) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) json (1.8.1) - kgio (2.8.1) + kgio (2.9.2) launchy (2.4.2) addressable (~> 2.3) libv8 (3.16.14.3) - listen (2.4.0) + listen (2.7.9) celluloid (>= 0.15.2) rb-fsevent (>= 0.9.3) rb-inotify (>= 0.9) - lumberjack (1.0.4) - mail (2.5.4) - mime-types (~> 1.16) - treetop (~> 1.4.8) + lumberjack (1.0.9) + mail (2.6.1) + mime-types (>= 1.16, < 3) method_source (0.8.2) - mime-types (1.25.1) + mime-types (2.3) mini_portile (0.6.0) - minitest (4.7.5) + minitest (5.4.1) + mongoid-grid_fs (2.1.0) + mime-types (>= 1.0, < 3.0) + mongoid (>= 3.0, < 5.0) mongoid_taggable (1.1.1) mongoid (>= 3) rake - moped (2.0.0.beta5) - bson (~> 2.1) - connection_pool (~> 1.2) + moped (2.0.0) + bson (~> 2.2) + connection_pool (~> 2.0) optionable (~> 0.2.0) - multi_json (1.8.4) - nokogiri (1.6.2.1) + multi_json (1.10.1) + nokogiri (1.6.3.1) mini_portile (= 0.6.0) optionable (0.2.0) - origin (2.1.0) + origin (2.1.1) orm_adapter (0.5.0) - polyglot (0.3.3) - pry (0.9.12.4) - coderay (~> 1.0) - method_source (~> 0.8) + pry (0.10.1) + coderay (~> 1.1.0) + method_source (~> 0.8.1) slop (~> 3.4) - pry-byebug (1.3.2) + pry-byebug (1.3.3) byebug (~> 2.7) - pry (~> 0.9.12) + pry (~> 0.10) pry-rails (0.3.2) pry (>= 0.9.10) - quiet_assets (1.0.2) + quiet_assets (1.0.3) railties (>= 3.1, < 5.0) - rack (1.5.2) + rack (1.6.0.beta) rack-test (0.6.2) rack (>= 1.0) - rails (4.0.2) - actionmailer (= 4.0.2) - actionpack (= 4.0.2) - activerecord (= 4.0.2) - activesupport (= 4.0.2) + rails (4.2.0.beta1) + actionmailer (= 4.2.0.beta1) + actionpack (= 4.2.0.beta1) + actionview (= 4.2.0.beta1) + activejob (= 4.2.0.beta1) + activemodel (= 4.2.0.beta1) + activerecord (= 4.2.0.beta1) + activesupport (= 4.2.0.beta1) bundler (>= 1.3.0, < 2.0) - railties (= 4.0.2) - sprockets-rails (~> 2.0.0) - rails_layout (1.0.5) - railties (4.0.2) - actionpack (= 4.0.2) - activesupport (= 4.0.2) + railties (= 4.2.0.beta1) + sprockets-rails (~> 3.0.0.beta1) + rails-deprecated_sanitizer (1.0.2) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.2) + activesupport + nokogiri (~> 1.6.0) + rails-deprecated_sanitizer (>= 1.0.1) + rails_layout (1.0.21) + railties (4.2.0.beta1) + actionpack (= 4.2.0.beta1) + activesupport (= 4.2.0.beta1) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - raindrops (0.12.0) - rake (10.1.1) + raindrops (0.13.0) + rake (10.3.2) rb-fsevent (0.9.4) - rb-inotify (0.9.3) + rb-inotify (0.9.5) ffi (>= 0.5.0) ref (1.0.5) - rmagick (2.13.2) - rolify (3.2.0) - rspec (2.14.1) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) - rspec-core (2.14.7) - rspec-expectations (2.14.4) + rmagick (2.13.3) + rolify (3.4.0) + rspec (2.99.0) + rspec-core (~> 2.99.0) + rspec-expectations (~> 2.99.0) + rspec-mocks (~> 2.99.0) + rspec-collection_matchers (1.0.0) + rspec-expectations (>= 2.99.0.beta1) + rspec-core (2.99.2) + rspec-expectations (2.99.2) diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.14.4) - rspec-rails (2.14.1) + rspec-mocks (2.99.2) + rspec-rails (2.99.0) actionpack (>= 3.0) activemodel (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) + rspec-collection_matchers + rspec-core (~> 2.99.0) + rspec-expectations (~> 2.99.0) + rspec-mocks (~> 2.99.0) ruby_parser (3.1.3) sexp_processor (~> 4.1) rubyzip (0.9.9) - sass (3.2.13) - sass-rails (4.0.1) + sass (3.4.2) + sass-rails (5.0.0.beta1) railties (>= 4.0.0, < 5.0) - sass (>= 3.1.10) - sprockets-rails (~> 2.0.0) + sass (~> 3.2) + sprockets (~> 2.12) + sprockets-rails (>= 2.0, < 4.0) selenium-webdriver (2.35.1) childprocess (>= 0.2.5) multi_json (~> 1.0) rubyzip (< 1.0.0) websocket (~> 1.0.4) - sexp_processor (4.4.1) - simple_form (3.0.1) - actionpack (>= 4.0.0, < 4.1) - activemodel (>= 4.0.0, < 4.1) - slop (3.4.7) - sprockets (2.10.1) + sexp_processor (4.4.4) + simple_form (3.0.2) + actionpack (~> 4.0) + activemodel (~> 4.0) + slop (3.6.0) + sprockets (2.12.1) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.0.1) - actionpack (>= 3.0) - activesupport (>= 3.0) + sprockets-rails (3.0.0.beta1) + actionpack (>= 4.0) + activesupport (>= 4.0) sprockets (~> 2.8) - therubyracer (0.12.0) + therubyracer (0.12.1) libv8 (~> 3.16.14.0) ref - thor (0.18.1) - thread_safe (0.1.3) - atomic + thor (0.19.1) + thread_safe (0.3.4) tilt (1.4.1) timers (1.1.0) - treetop (1.4.15) - polyglot - polyglot (>= 0.3.1) - turbolinks (2.2.0) + turbolinks (2.3.0) coffee-rails - tzinfo (0.3.38) - uglifier (2.4.0) + tzinfo (1.2.2) + thread_safe (~> 0.1) + uglifier (2.5.3) execjs (>= 0.3.0) json (>= 1.8.0) - unicorn (4.8.0) + unicorn (4.8.3) kgio (~> 2.6) rack raindrops (~> 0.7) - unicorn-rails (1.1.0) + unicorn-rails (2.1.1) rack unicorn warden (1.2.3) @@ -301,12 +325,12 @@ DEPENDENCIES pry-byebug pry-rails quiet_assets - rails (= 4.0.2) + rails (= 4.2.0.beta1) rails_layout rmagick rolify rspec-rails (~> 2.14) - sass-rails (~> 4.0.0) + sass-rails (~> 5.0.0.beta1) selenium-webdriver (~> 2.35.1) simple_form therubyracer From a50df048e187ccc72d9e72638c8d8da8b9dc1746 Mon Sep 17 00:00:00 2001 From: Everaldo Gomes Date: Fri, 29 Aug 2014 15:38:39 +0000 Subject: [PATCH 04/16] runned rake rails:update and updated settings - overwritings some files and customizing others --- bin/setup | 29 +++++++++++++++++++++++ config/application.rb | 2 +- config/boot.rb | 3 +-- config/environment.rb | 2 +- config/environments/development.rb | 14 ++++++++++- config/environments/production.rb | 11 ++------- config/environments/test.rb | 7 ++++-- config/initializers/assets.rb | 11 +++++++++ config/initializers/cookies_serializer.rb | 3 +++ config/initializers/mime_types.rb | 1 - config/initializers/session_store.rb | 2 +- config/initializers/wrap_parameters.rb | 5 ++++ config/routes.rb | 2 +- 13 files changed, 73 insertions(+), 19 deletions(-) create mode 100755 bin/setup create mode 100644 config/initializers/assets.rb create mode 100644 config/initializers/cookies_serializer.rb diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..acdb2c1 --- /dev/null +++ b/bin/setup @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +Dir.chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file: + + puts "== Installing dependencies ==" + system "gem install bundler --conservative" + system "bundle check || bundle install" + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # system "cp config/database.yml.sample config/database.yml" + # end + + puts "\n== Preparing database ==" + system "bin/rake db:setup" + + puts "\n== Removing old logs and tempfiles ==" + system "rm -f log/*" + system "rm -rf tmp/cache" + + puts "\n== Restarting application server ==" + system "touch tmp/restart.txt" +end diff --git a/config/application.rb b/config/application.rb index 2b6707b..b211a10 100644 --- a/config/application.rb +++ b/config/application.rb @@ -10,7 +10,7 @@ # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. -Bundler.require(:default, Rails.env) +Bundler.require(*Rails.groups) module TecnoFreela class Application < Rails::Application diff --git a/config/boot.rb b/config/boot.rb index 3596736..6b750f0 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,4 +1,3 @@ -# Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/environment.rb b/config/environment.rb index 3be5ca7..ee8d90d 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -2,4 +2,4 @@ require File.expand_path('../application', __FILE__) # Initialize the Rails application. -TecnoFreela::Application.initialize! +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index a5e0b5f..bb1474b 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,4 +1,4 @@ -TecnoFreela::Application.configure do +Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on @@ -24,4 +24,16 @@ # This option may cause significant delays in view rendering with a large # number of complex assets. config.assets.debug = true + + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + config.assets.digest = true + + # Adds additional error checking when serving assets at runtime. + # Checks for improperly declared sprockets dependencies. + # Raises helpful error messages. + config.assets.raise_runtime_errors = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true end diff --git a/config/environments/production.rb b/config/environments/production.rb index e58916a..381b7bc 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,4 +1,4 @@ -TecnoFreela::Application.configure do +Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. @@ -32,8 +32,7 @@ # Generate digests for assets URLs. config.assets.digest = true - # Version of your assets, change this if you want to expire all your assets. - config.assets.version = '1.0' + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache @@ -57,9 +56,6 @@ # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = "http://assets.example.com" - # Precompile additional assets. - # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. - # config.assets.precompile += %w( search.js ) # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. @@ -72,9 +68,6 @@ # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify - # Disable automatic flushing of the log to improve performance. - # config.autoflush_log = false - # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new end diff --git a/config/environments/test.rb b/config/environments/test.rb index fa1ea20..053f5b6 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,4 +1,4 @@ -TecnoFreela::Application.configure do +Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's @@ -14,7 +14,7 @@ # Configure static asset server for tests with Cache-Control for performance. config.serve_static_assets = true - config.static_cache_control = "public, max-age=3600" + config.static_cache_control = 'public, max-age=3600' # Show full error reports and disable caching. config.consider_all_requests_local = true @@ -33,4 +33,7 @@ # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 0000000..01ef3e6 --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,11 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# Rails.application.config.assets.precompile += %w( search.js ) diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000..ac5f8b6 --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.action_dispatch.cookies_serializer = :marshal diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index 72aca7e..dc18996 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -2,4 +2,3 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf -# Mime::Type.register_alias "text/html", :iphone diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index bb9e4f0..631a4b3 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,3 +1,3 @@ # Be sure to restart your server when you modify this file. -TecnoFreela::Application.config.session_store :cookie_store, key: '_tecno_freela_session' +Rails.application.config.session_store :cookie_store, key: '_tecno_freela_session' diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index b81ea74..33725e9 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -7,3 +7,8 @@ ActiveSupport.on_load(:action_controller) do wrap_parameters format: [:json] if respond_to?(:wrap_parameters) end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/config/routes.rb b/config/routes.rb index b4a4441..f03c53d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,4 @@ -TecnoFreela::Application.routes.draw do +Rails.application.routes.draw do resources :jobs, except: [:edit, :update, :destroy] root "home#index" From fed3f9201115b33a3192d170ab3cc9bde96f2e61 Mon Sep 17 00:00:00 2001 From: Everaldo Gomes Date: Fri, 29 Aug 2014 15:54:16 +0000 Subject: [PATCH 05/16] using devise from github for solving a bug on rails 4.2.beta1 --- Gemfile | 4 +++- Gemfile.lock | 23 ++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index e1a45a7..d182799 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,9 @@ source 'https://rubygems.org' ruby '2.1.2' gem 'rails', '4.2.0.beta1' gem 'cancan' -gem 'devise' +#gem 'devise' +# https://github.com/plataformatec/devise/pull/3153 +gem 'devise', git: 'https://github.com/plataformatec/devise.git', :branch => 'lm-rails-4-2' gem 'figaro' gem 'haml-rails' gem 'mongoid', github: 'mongoid/mongoid' diff --git a/Gemfile.lock b/Gemfile.lock index 543546d..8cfe156 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,6 +8,19 @@ GIT origin (~> 2.1) tzinfo (>= 0.3.37) +GIT + remote: https://github.com/plataformatec/devise.git + revision: 2f4fab00d9f44958957e6699d8ee02a063565c19 + branch: lm-rails-4-2 + specs: + devise (3.3.0) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 3.2.6, < 5) + responders + thread_safe (~> 0.1) + warden (~> 1.2.3) + GEM remote: https://rubygems.org/ specs: @@ -95,12 +108,6 @@ GEM database_cleaner (1.0.1) debug_inspector (0.0.2) debugger-linecache (1.2.0) - devise (3.3.0) - bcrypt (~> 3.0) - orm_adapter (~> 0.1) - railties (>= 3.2.6, < 5) - thread_safe (~> 0.1) - warden (~> 1.2.3) diff-lcs (1.2.5) email_spec (1.5.0) launchy (~> 2.1) @@ -222,6 +229,8 @@ GEM rb-inotify (0.9.5) ffi (>= 0.5.0) ref (1.0.5) + responders (2.0.0) + railties (>= 4.2.0.alpha, < 5) rmagick (2.13.3) rolify (3.4.0) rspec (2.99.0) @@ -311,7 +320,7 @@ DEPENDENCIES carrierwave-mongoid coffee-rails (~> 4.0.0) database_cleaner (~> 1.0.1) - devise + devise! email_spec (~> 1.5.0) factory_girl_rails (~> 4.2.1) figaro From dbcb4671a74f909205e53559796413474eeeffcf Mon Sep 17 00:00:00 2001 From: Everaldo Gomes Date: Fri, 29 Aug 2014 16:40:22 +0000 Subject: [PATCH 06/16] added thin. If the app isnt open on your browser when running with vagrant, just use: rails s -b 0.0.0.0 to avoid binding only to localhost --- Gemfile | 1 + Gemfile.lock | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/Gemfile b/Gemfile index d182799..62a0895 100644 --- a/Gemfile +++ b/Gemfile @@ -29,6 +29,7 @@ gem 'rails_layout' group :development do + gem 'thin' gem 'pry-byebug' gem 'pry-rails' gem 'better_errors' diff --git a/Gemfile.lock b/Gemfile.lock index 8cfe156..1b56633 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -105,6 +105,7 @@ GEM coffee-script-source (1.8.0) columnize (0.8.9) connection_pool (2.0.0) + daemons (1.1.9) database_cleaner (1.0.1) debug_inspector (0.0.2) debugger-linecache (1.2.0) @@ -113,6 +114,7 @@ GEM launchy (~> 2.1) mail (~> 2.2) erubis (2.7.0) + eventmachine (1.0.3) execjs (2.2.1) factory_girl (4.2.0) activesupport (>= 3.0.0) @@ -283,6 +285,10 @@ GEM therubyracer (0.12.1) libv8 (~> 3.16.14.0) ref + thin (1.6.2) + daemons (>= 1.0.9) + eventmachine (>= 1.0.0) + rack (>= 1.0.0) thor (0.19.1) thread_safe (0.3.4) tilt (1.4.1) @@ -343,6 +349,7 @@ DEPENDENCIES selenium-webdriver (~> 2.35.1) simple_form therubyracer + thin turbolinks uglifier (>= 1.3.0) unicorn From 1c363f663f7ec853b953ab6d0879df4ea88a0f43 Mon Sep 17 00:00:00 2001 From: Everaldo Gomes Date: Fri, 29 Aug 2014 16:40:58 +0000 Subject: [PATCH 07/16] updating bootstrap-sass and bootstrap-wysihtml5 require statement --- Gemfile | 2 +- Gemfile.lock | 2 +- app/assets/javascripts/application.js | 2 +- app/assets/stylesheets/application.css.scss | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 62a0895..b6d4864 100644 --- a/Gemfile +++ b/Gemfile @@ -22,7 +22,7 @@ gem 'therubyracer', platforms: :ruby gem 'jquery-rails' gem 'turbolinks' gem 'bootstrap-wysihtml5-rails' -gem 'bootstrap-sass', '>= 3.0.0.0' +gem 'bootstrap-sass', '>= 3.2.0.1' gem 'html2haml' gem 'quiet_assets' gem 'rails_layout' diff --git a/Gemfile.lock b/Gemfile.lock index 1b56633..08eb743 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -319,7 +319,7 @@ PLATFORMS DEPENDENCIES better_errors binding_of_caller - bootstrap-sass (>= 3.0.0.0) + bootstrap-sass (>= 3.2.0.1) bootstrap-wysihtml5-rails cancan capybara (= 2.1.0) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 4bc9b3b..799ffb8 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -14,6 +14,6 @@ //= require jquery_ujs //= require turbolinks //= require bootstrap -//= require bootstrap-wysihtml5/b3 +//= require bootstrap-wysihtml5 // //= require_tree . diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index d6896e9..7a6f026 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -10,5 +10,5 @@ * *= require_self *= require_tree . - *= require bootstrap-wysihtml5/b3 + *= require bootstrap-wysihtml5 */ From c688f8c3bc58c24081fc86119cdf76003e654ce6 Mon Sep 17 00:00:00 2001 From: Everaldo Gomes Date: Fri, 29 Aug 2014 17:05:17 +0000 Subject: [PATCH 08/16] updating minor differences between rails 4.0 and rails 4.2 - added webconsole, html-sanitizer etc. --- Gemfile | 18 +++++++++++- Gemfile.lock | 24 ++++++++++++++++ Rakefile | 2 +- config/initializers/cookies_serializer.rb | 2 +- config/initializers/secret_token.rb | 12 -------- public/404.html | 34 ++++++++++++---------- public/422.html | 35 +++++++++++++---------- public/500.html | 33 ++++++++++++--------- public/robots.txt | 2 +- 9 files changed, 102 insertions(+), 60 deletions(-) delete mode 100644 config/initializers/secret_token.rb diff --git a/Gemfile b/Gemfile index b6d4864..fc6ff28 100644 --- a/Gemfile +++ b/Gemfile @@ -27,8 +27,24 @@ gem 'html2haml' gem 'quiet_assets' gem 'rails_layout' +gem 'jbuilder', '~> 2.0' +# bundle exec rake doc:rails generates the API under doc/api. +gem 'sdoc', '~> 0.4.0', group: :doc -group :development do +# Use ActiveModel has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use Rails Html Sanitizer for HTML sanitization +gem 'rails-html-sanitizer', '~> 1.0' + + +group :development, :test do + # Call 'debugger' anywhere in the code to stop execution and get a debugger console + gem 'byebug' + # Access an IRB console on exceptions page and /console in development + gem 'web-console', '~> 2.0.0.beta2' + # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'spring' gem 'thin' gem 'pry-byebug' gem 'pry-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 08eb743..d32fb8e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -153,6 +153,9 @@ GEM hpricot (~> 0.8.6) ruby_parser (~> 3.1.1) i18n (0.7.0.beta1) + jbuilder (2.1.3) + activesupport (>= 3.0.0, < 5) + multi_json (~> 1.2) jquery-rails (3.1.1) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) @@ -165,6 +168,8 @@ GEM celluloid (>= 0.15.2) rb-fsevent (>= 0.9.3) rb-inotify (>= 0.9) + loofah (2.0.1) + nokogiri (>= 1.5.9) lumberjack (1.0.9) mail (2.6.1) mime-types (>= 1.16, < 3) @@ -219,6 +224,8 @@ GEM activesupport nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.0) + loofah (~> 2.0) rails_layout (1.0.21) railties (4.2.0.beta1) actionpack (= 4.2.0.beta1) @@ -230,6 +237,8 @@ GEM rb-fsevent (0.9.4) rb-inotify (0.9.5) ffi (>= 0.5.0) + rdoc (4.1.1) + json (~> 1.4) ref (1.0.5) responders (2.0.0) railties (>= 4.2.0.alpha, < 5) @@ -263,6 +272,9 @@ GEM sass (~> 3.2) sprockets (~> 2.12) sprockets-rails (>= 2.0, < 4.0) + sdoc (0.4.1) + json (~> 1.7, >= 1.7.7) + rdoc (~> 4.0) selenium-webdriver (2.35.1) childprocess (>= 0.2.5) multi_json (~> 1.0) @@ -273,6 +285,7 @@ GEM actionpack (~> 4.0) activemodel (~> 4.0) slop (3.6.0) + spring (1.1.3) sprockets (2.12.1) hike (~> 1.2) multi_json (~> 1.0) @@ -309,6 +322,11 @@ GEM unicorn warden (1.2.3) rack (>= 1.0) + web-console (2.0.0.beta2) + activemodel (~> 4.0) + binding_of_caller + railties (~> 4.0) + sprockets-rails (>= 2.0, < 4.0) websocket (1.0.7) xpath (2.0.0) nokogiri (~> 1.3) @@ -321,6 +339,7 @@ DEPENDENCIES binding_of_caller bootstrap-sass (>= 3.2.0.1) bootstrap-wysihtml5-rails + byebug cancan capybara (= 2.1.0) carrierwave-mongoid @@ -334,6 +353,7 @@ DEPENDENCIES guard-rspec haml-rails html2haml + jbuilder (~> 2.0) jquery-rails mongoid! mongoid_taggable @@ -341,16 +361,20 @@ DEPENDENCIES pry-rails quiet_assets rails (= 4.2.0.beta1) + rails-html-sanitizer (~> 1.0) rails_layout rmagick rolify rspec-rails (~> 2.14) sass-rails (~> 5.0.0.beta1) + sdoc (~> 0.4.0) selenium-webdriver (~> 2.35.1) simple_form + spring therubyracer thin turbolinks uglifier (>= 1.3.0) unicorn unicorn-rails + web-console (~> 2.0.0.beta2) diff --git a/Rakefile b/Rakefile index eac2fa2..ba6b733 100644 --- a/Rakefile +++ b/Rakefile @@ -3,4 +3,4 @@ require File.expand_path('../config/application', __FILE__) -TecnoFreela::Application.load_tasks +Rails.application.load_tasks diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index ac5f8b6..7f70458 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -1,3 +1,3 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.action_dispatch.cookies_serializer = :marshal +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb deleted file mode 100644 index 82f5e3d..0000000 --- a/config/initializers/secret_token.rb +++ /dev/null @@ -1,12 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Your secret key is used for verifying the integrity of signed cookies. -# If you change this key, all old signed cookies will become invalid! - -# Make sure the secret is at least 30 characters and all random, -# no regular words or you'll be exposed to dictionary attacks. -# You can use `rake secret` to generate a secure secret key. - -# Make sure your secret_key_base is kept private -# if you're sharing your code publicly. -TecnoFreela::Application.config.secret_key_base = '78ff412eed609f8485f5f41580bfc24b30599691a406a640a1a3e9fa7c913ee7728518cede2aa7f12a1f0a28870237489d0c291894edf281fac0e5c770ec23cc' diff --git a/public/404.html b/public/404.html index a0daa0c..7c7e00e 100644 --- a/public/404.html +++ b/public/404.html @@ -2,6 +2,7 @@ The page you were looking for doesn't exist (404) + @@ -50,9 +52,11 @@
-

The page you were looking for doesn't exist.

-

You may have mistyped the address or the page may have moved.

+
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

-

If you are the application owner check the logs for more information.

diff --git a/public/422.html b/public/422.html index fbb4b84..9ff467a 100644 --- a/public/422.html +++ b/public/422.html @@ -2,47 +2,50 @@ The change you wanted was rejected (422) + @@ -50,9 +53,11 @@
-

The change you wanted was rejected.

-

Maybe you tried to change something you didn't have access to.

+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

-

If you are the application owner check the logs for more information.

diff --git a/public/500.html b/public/500.html index e9052d3..6436c55 100644 --- a/public/500.html +++ b/public/500.html @@ -2,47 +2,50 @@ We're sorry, but something went wrong (500) + @@ -50,8 +53,10 @@
-

We're sorry, but something went wrong.

+
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

-

If you are the application owner check the logs for more information.

diff --git a/public/robots.txt b/public/robots.txt index 1a3a5e4..ed773b5 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -1,4 +1,4 @@ -# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file +# See http://www.robotstxt.org/norobots.html for documentation on how to use the robots.txt file # # To ban all spiders from the entire site uncomment the next two lines: # User-agent: * From 06f3afac0721a3877d06c6519980db5b3da853ef Mon Sep 17 00:00:00 2001 From: Everaldo Gomes Date: Fri, 29 Aug 2014 18:12:35 +0000 Subject: [PATCH 09/16] installed and generated binstubs for mina --- Gemfile | 3 +++ Gemfile.lock | 7 +++++++ bin/mina | 16 ++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100755 bin/mina diff --git a/Gemfile b/Gemfile index fc6ff28..984f66f 100644 --- a/Gemfile +++ b/Gemfile @@ -26,6 +26,9 @@ gem 'bootstrap-sass', '>= 3.2.0.1' gem 'html2haml' gem 'quiet_assets' gem 'rails_layout' +gem 'mina' +gem 'mina-scp', require: false + gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. diff --git a/Gemfile.lock b/Gemfile.lock index d32fb8e..ff45e19 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -175,6 +175,10 @@ GEM mime-types (>= 1.16, < 3) method_source (0.8.2) mime-types (2.3) + mina (0.3.0) + open4 + rake + mina-scp (0.1.1) mini_portile (0.6.0) minitest (5.4.1) mongoid-grid_fs (2.1.0) @@ -190,6 +194,7 @@ GEM multi_json (1.10.1) nokogiri (1.6.3.1) mini_portile (= 0.6.0) + open4 (1.3.4) optionable (0.2.0) origin (2.1.1) orm_adapter (0.5.0) @@ -355,6 +360,8 @@ DEPENDENCIES html2haml jbuilder (~> 2.0) jquery-rails + mina + mina-scp mongoid! mongoid_taggable pry-byebug diff --git a/bin/mina b/bin/mina new file mode 100755 index 0000000..dc50f0b --- /dev/null +++ b/bin/mina @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# +# This file was generated by Bundler. +# +# The application 'mina' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('mina', 'mina') From ecbb420ad7a9f8805d7f20371892742330760be9 Mon Sep 17 00:00:00 2001 From: Everaldo Gomes Date: Fri, 29 Aug 2014 18:36:26 +0000 Subject: [PATCH 10/16] added staging environment --- config/environments/staging.rb | 73 ++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 config/environments/staging.rb diff --git a/config/environments/staging.rb b/config/environments/staging.rb new file mode 100644 index 0000000..7a4e784 --- /dev/null +++ b/config/environments/staging.rb @@ -0,0 +1,73 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both thread web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. + # config.action_dispatch.rack_cache = true + + # Disable Rails's static asset server (Apache or nginx will already do this). + config.serve_static_assets = false + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Generate digests for assets URLs. + config.assets.digest = true + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Set to :debug to see everything in the log. + config.log_level = :debug + + # Prepend all log lines with the following tags. + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups. + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = "http://assets.example.com" + + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation can not be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new +end From 7b2abeb7cb440fb3ba2e67cea73050f9d06b931a Mon Sep 17 00:00:00 2001 From: Everaldo Gomes Date: Fri, 29 Aug 2014 18:48:06 +0000 Subject: [PATCH 11/16] ignoring mongoid config --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1502c6d..f105047 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ db/*.sqlite3 # configuration file introduced in Rails 4.1 /config/secrets.yml +/config/mongoid.yml # various artifacts **.war From 86114ca9e31cbc5bd2ed823df77dbf96f47882ec Mon Sep 17 00:00:00 2001 From: Everaldo Gomes Date: Fri, 29 Aug 2014 19:31:43 +0000 Subject: [PATCH 12/16] added vendor/assets/fonts to prevent assets compile error --- vendor/assets/fonts/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 vendor/assets/fonts/.keep diff --git a/vendor/assets/fonts/.keep b/vendor/assets/fonts/.keep new file mode 100644 index 0000000..e69de29 From 5ebfa02922298e21626bb5658fe618f7d69a3e95 Mon Sep 17 00:00:00 2001 From: Everaldo Gomes Date: Fri, 29 Aug 2014 19:33:50 +0000 Subject: [PATCH 13/16] installed mina --- Gemfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Gemfile b/Gemfile index 984f66f..e8134a5 100644 --- a/Gemfile +++ b/Gemfile @@ -40,6 +40,9 @@ gem 'sdoc', '~> 0.4.0', group: :doc # Use Rails Html Sanitizer for HTML sanitization gem 'rails-html-sanitizer', '~> 1.0' +gem 'mina' +gem 'mina-scp', require: false + group :development, :test do # Call 'debugger' anywhere in the code to stop execution and get a debugger console From 08bba79d5e57fe4a2176c5ebd4f10125712ab2d8 Mon Sep 17 00:00:00 2001 From: Everaldo Gomes Date: Fri, 29 Aug 2014 19:39:22 +0000 Subject: [PATCH 14/16] workaround on bootstrap-sass for missing images folder --- Gemfile | 8 +++++--- Gemfile.lock | 11 ++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index e8134a5..19a9ff0 100644 --- a/Gemfile +++ b/Gemfile @@ -22,12 +22,14 @@ gem 'therubyracer', platforms: :ruby gem 'jquery-rails' gem 'turbolinks' gem 'bootstrap-wysihtml5-rails' -gem 'bootstrap-sass', '>= 3.2.0.1' +#gem 'bootstrap-sass', '>= 3.2.0.1' +# Temporary fix +gem 'bootstrap-sass', github: 'everaldo/bootstrap-sass' gem 'html2haml' gem 'quiet_assets' gem 'rails_layout' -gem 'mina' -gem 'mina-scp', require: false +gem 'mina' +gem 'mina-scp', require: false gem 'jbuilder', '~> 2.0' diff --git a/Gemfile.lock b/Gemfile.lock index ff45e19..e5e5bbe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,10 @@ +GIT + remote: git://github.com/everaldo/bootstrap-sass.git + revision: 21bff940bec205d641a818e08fce699810277d42 + specs: + bootstrap-sass (3.2.0.1) + sass (~> 3.2) + GIT remote: git://github.com/mongoid/mongoid.git revision: 4e3b39e9bbcf1b36d0472c6b09f8f394c55065f4 @@ -66,8 +73,6 @@ GEM rack (>= 0.9.0) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) - bootstrap-sass (3.2.0.1) - sass (~> 3.2) bootstrap-wysihtml5-rails (0.3.2.100) railties (>= 3.0) bson (2.3.0) @@ -342,7 +347,7 @@ PLATFORMS DEPENDENCIES better_errors binding_of_caller - bootstrap-sass (>= 3.2.0.1) + bootstrap-sass! bootstrap-wysihtml5-rails byebug cancan From fd33f795d12247a49ec58c67b8a667072e2fe505 Mon Sep 17 00:00:00 2001 From: Everaldo Gomes Date: Fri, 29 Aug 2014 20:03:09 +0000 Subject: [PATCH 15/16] ignoring mina servers deploy files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f105047..b8f341f 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ db/*.sqlite3 # configuration file introduced in Rails 4.1 /config/secrets.yml /config/mongoid.yml +/config/mina/servers/* # various artifacts **.war From 5dd50c2313084995f4d45cdb2a540730a9028fd6 Mon Sep 17 00:00:00 2001 From: Everaldo Gomes Date: Fri, 29 Aug 2014 20:04:16 +0000 Subject: [PATCH 16/16] mina deploy settings --- config/deploy.rb | 46 +++++++++++ config/mina/app.rb | 7 ++ config/mina/defaults.rb | 34 +++++++++ config/mina/extras.rb | 103 +++++++++++++++++++++++++ config/mina/imagemagick.rb | 12 +++ config/mina/mongoid.rb | 27 +++++++ config/mina/nginx.rb | 48 ++++++++++++ config/mina/secrets.rb | 24 ++++++ config/mina/templates/mongoid.yml | 58 ++++++++++++++ config/mina/templates/nginx.conf.erb | 109 +++++++++++++++++++++++++++ config/mina/templates/unicorn.rb.erb | 42 +++++++++++ config/mina/templates/unicorn.sh.erb | 82 ++++++++++++++++++++ config/mina/unicorn.rb | 79 +++++++++++++++++++ 13 files changed, 671 insertions(+) create mode 100644 config/deploy.rb create mode 100644 config/mina/app.rb create mode 100644 config/mina/defaults.rb create mode 100644 config/mina/extras.rb create mode 100644 config/mina/imagemagick.rb create mode 100644 config/mina/mongoid.rb create mode 100644 config/mina/nginx.rb create mode 100644 config/mina/secrets.rb create mode 100644 config/mina/templates/mongoid.yml create mode 100644 config/mina/templates/nginx.conf.erb create mode 100644 config/mina/templates/unicorn.rb.erb create mode 100755 config/mina/templates/unicorn.sh.erb create mode 100644 config/mina/unicorn.rb diff --git a/config/deploy.rb b/config/deploy.rb new file mode 100644 index 0000000..50ba372 --- /dev/null +++ b/config/deploy.rb @@ -0,0 +1,46 @@ +$:.unshift './config' + +require 'mina/bundler' +require 'mina/rails' +require 'mina/git' +require 'mina/defaults' +require 'mina/extras' +require 'mina/app' +require 'mina/mongoid' +require 'mina/imagemagick' +require 'mina/unicorn' +require 'mina/nginx' +require 'mina/secrets' + +Dir['config/mina/servers/*.rb'].each { |f| load f } + + +set :app, 'tecno_freela' +set :default_server, :staging +set :domain, 'staging' +set :deploy_to, '/home/tecnofreela/tecno_freela' +set :repository, 'git@github.com:everaldo/tecno_freela.git' # Needs to change to Tecnobest/tecno_freela after merging +set :branch, 'master' +set :keep_releases, 5 + + +# Optional settings: +set :user, 'tecnofreela' # Username in the server to SSH to. + +set :server, ENV['to'] || default_server +invoke :"env:#{server}" + +desc "Deploys the current version to the server." +task :deploy do + deploy do + invoke :'git:clone' + invoke :'deploy:link_shared_paths' + invoke :'bundle:install' + invoke :'rails:assets_precompile' # I don't really like assets pipeline + + to :launch do + invoke :'unicorn:restart' + end + end +end + diff --git a/config/mina/app.rb b/config/mina/app.rb new file mode 100644 index 0000000..3984cbb --- /dev/null +++ b/config/mina/app.rb @@ -0,0 +1,7 @@ +namespace :app do + desc "Application error logs" + task :logs do + queue 'echo "-----> App Logs"' + queue echo_cmd "tail -500 #{logs_path}/#{rails_env}.log" + end +end diff --git a/config/mina/defaults.rb b/config/mina/defaults.rb new file mode 100644 index 0000000..90ac961 --- /dev/null +++ b/config/mina/defaults.rb @@ -0,0 +1,34 @@ +########################################################################### +# Sensible defaults. You wouldn't want to change those in most of the cases +########################################################################### +task :defaults do + set_default :term_mode, :pretty + set_default :rails_env, 'staging' + set_default :shared_paths, ['config/secrets.yml', 'config/mongoid.yml', 'log', 'tmp'] + set_default :branch, 'master' + + set_default :sockets_path, "#{deploy_to}/#{shared_path}/tmp/sockets" + set_default :pids_path, "#{deploy_to}/#{shared_path}/tmp/pids" + set_default :logs_path, "#{deploy_to}/#{shared_path}/log" + set_default :config_templates_path, "config/mina/templates" + set_default :config_path, "#{deploy_to}/#{shared_path}/config" + + set_default :unicorn_socket, "#{sockets_path}/unicorn.sock" + set_default :unicorn_pid, "#{pids_path}/unicorn.pid" + set_default :unicorn_config, "#{config_path}/unicorn.rb" + set_default :unicorn_service_name, "unicorn-#{app!}" + set_default :unicorn_script, "#{services_path!}/#{unicorn_service_name}" + set_default :unicorn_workers, 1 + set_default :unicorn_bin, 'bundle exec unicorn' # you may prefer this over the line below + #set_default :unicorn_bin, "#{deploy_to}/#{current_path}/bin/unicorn_rails" + set_default :unicorn_user, user + set_default :unicorn_group, user + + set_default :nginx_config, "#{nginx_path}/sites-available/#{app!}.conf" + set_default :nginx_config_e, "#{nginx_path}/sites-enabled/#{app!}.conf" + set_default :nginx_log_path, "#{deploy_to}/#{shared_path}/log/nginx" + set_default :nginx_user, "www-data" + set_default :nginx_group, "www-data" + set_default :nginx_server_name, domain +end + diff --git a/config/mina/extras.rb b/config/mina/extras.rb new file mode 100644 index 0000000..90e1379 --- /dev/null +++ b/config/mina/extras.rb @@ -0,0 +1,103 @@ +task :setup do + invoke :create_extra_paths + invoke :'mongoid:upload' + invoke :'unicorn:upload' + invoke :'secrets:upload' + invoke :'nginx:upload' + + if sudoer? + queue %{echo "-----> (!!!) You now need to run 'mina sudo_setup' to run the parts that require sudoer user (!!!)"} + else + invoke :sudo_setup + end +end + +desc 'Invoke setup tasks, that requires sudo privileges' +task :sudo_setup do + invoke :sudo + invoke :'imagemagick:install' + invoke :'unicorn:link' + invoke :'nginx:setup' + invoke :'nginx:link' +end + +desc 'Create extra paths for shared configs, pids, sockets, etc.' +task :create_extra_paths do + queue 'echo "-----> Create configs path"' + queue echo_cmd "mkdir -p #{config_path}" + + queue 'echo "-----> Create shared paths"' + shared_dirs = shared_paths.map { |file| File.dirname("#{deploy_to}/#{shared_path}/#{file}") }.uniq + cmds = shared_dirs.map do |dir| + queue echo_cmd %{mkdir -p "#{dir}"} + end + + queue 'echo "-----> Create PID and Sockets paths"' + queue echo_cmd "mkdir -p #{pids_path} && chown #{user}:#{group} #{pids_path} && chmod +rw #{pids_path}" + queue echo_cmd "mkdir -p #{sockets_path} && chown #{user}:#{group} #{sockets_path} && chmod +rw #{sockets_path}" +end + +task :health do + queue 'ps aux | grep -v grep | grep -v bash | grep -e "unicorn" -e "mongod" -e "nginx" -e "redis" -e "STAT START TIME COMMAND" -e "bash"' +end + +task :sudo do + set :sudo, true + set :term_mode, :system # :pretty doesn't seem to work with sudo well +end + +def upload_template(desc, tpl, destination) + contents = parse_template(tpl) + queue %{echo "-----> Put #{desc} file to #{destination}"} + queue %{echo "#{contents}" > #{destination}} + queue check_exists(destination) +end + +def parse_template(file) + erb("#{config_templates_path}/#{file}.erb").gsub('"','\\"').gsub('`','\\\\`').gsub('$','\\\\$') +end + +def check_response + 'then echo "-----> SUCCESS"; else echo "-----> FAILED"; fi' +end + +def check_exists(destination) + %{if [[ -s "#{destination}" ]]; #{check_response}} +end + +def check_ownership(u, g, destination) + %{ + file_info=(`ls -l #{destination}`) + if [[ -s "#{destination}" ]] && [[ ${file_info[2]} == '#{u}' ]] && [[ ${file_info[3]} == '#{g}' ]]; #{check_response} + } +end + +def check_exec_and_ownership(u, g, destination) + %{ + file_info=(`ls -l #{destination}`) + if [[ -s "#{destination}" ]] && [[ -x "#{destination}" ]] && [[ ${file_info[2]} == '#{u}' ]] && [[ ${file_info[3]} == '#{g}' ]]; #{check_response} + } +end + +def check_symlink(destination) + %{if [[ -h "#{destination}" ]]; #{check_response}} +end + +# Allow to run some tasks as different (sudoer) user when sudo required +module Mina + module Helpers + def ssh_command + args = domain! + args = if sudo? && sudoer? + "#{sudoer}@#{args}" + elsif user? + "#{user}@#{args}" + end + args << " -i #{identity_file}" if identity_file? + args << " -p #{port}" if port? + args << " -t" + "ssh #{args}" + end + end +end + diff --git a/config/mina/imagemagick.rb b/config/mina/imagemagick.rb new file mode 100644 index 0000000..5a638c5 --- /dev/null +++ b/config/mina/imagemagick.rb @@ -0,0 +1,12 @@ +########################################################################### +# ImageMagick Tasks +########################################################################### + +namespace :imagemagick do + desc "Install ImageMagick" + task :install do + queue echo_cmd 'sudo apt-get update -y' + queue echo_cmd 'sudo apt-get install -y imagemagick libmagickcore-dev libmagickwand-dev' + end +end + diff --git a/config/mina/mongoid.rb b/config/mina/mongoid.rb new file mode 100644 index 0000000..ea0e912 --- /dev/null +++ b/config/mina/mongoid.rb @@ -0,0 +1,27 @@ + +########################################################################### +# Mongoid Tasks +########################################################################### + +require 'mina/scp' + +namespace :mongoid do + desc "Upload and update (link) Mongoid config" + task :upload do + template = "#{config_templates_path}/mongoid.yml" + destination = "#{config_path}/mongoid.yml" + scp_upload template, destination + queue check_exists(destination) + end + + namespace :parse do + desc "Parses Mongoid config file and shows it in output" + task :config do + puts "#"*80 + puts "# mongoid.yml" + puts "#"*80 + puts File.read("#{config_templates_path}/mongoid.yml") + end + end +end + diff --git a/config/mina/nginx.rb b/config/mina/nginx.rb new file mode 100644 index 0000000..ff175c0 --- /dev/null +++ b/config/mina/nginx.rb @@ -0,0 +1,48 @@ +########################################################################### +# nginx Tasks +########################################################################### + +namespace :nginx do + desc "Create configuration and other files" + task :setup do + invoke :sudo + queue echo_cmd "mkdir -p #{nginx_log_path}" + queue echo_cmd "sudo chown #{nginx_user}:#{nginx_group} #{nginx_log_path}" + end + + desc "Upload and update (link) all nginx config file" + task :update => [:upload, :link] + + desc "Symlink config file" + task :link do + invoke :sudo + queue %{echo "-----> Symlink nginx config file"} + queue echo_cmd %{sudo ln -fs "#{config_path}/nginx.conf" "#{nginx_config}"} + queue check_symlink nginx_config + queue echo_cmd %{sudo ln -fs "#{config_path}/nginx.conf" "#{nginx_config_e}"} + queue check_symlink nginx_config_e + end + + desc "Parses nginx config file and uploads it to server" + task :upload do + upload_template 'nginx config', 'nginx.conf', "#{config_path}/nginx.conf" + end + + desc "Parses config file and outputs it to STDOUT (local task)" + task :parse do + puts "#"*80 + puts "# nginx.conf" + puts "#"*80 + puts erb("#{config_templates_path}/nginx.conf.erb") + end + + %w(stop start restart reload status).each do |action| + desc "#{action.capitalize} Nginx" + task action.to_sym do + queue %{echo "-----> #{action.capitalize} Nginx"} + invoke :sudo + queue echo_cmd "sudo service nginx #{action}" + end + end +end + diff --git a/config/mina/secrets.rb b/config/mina/secrets.rb new file mode 100644 index 0000000..dbc4714 --- /dev/null +++ b/config/mina/secrets.rb @@ -0,0 +1,24 @@ +########################################################################### +# Secrets Tasks +########################################################################### + +require 'mina/scp' + +namespace :secrets do + desc "Upload and update (link) secrets.yml file" + task :upload do + template = "config/secrets.yml" + destination = "#{config_path}/secrets.yml" + scp_upload template, destination + queue check_exists(destination) + end + + desc "Parses secrets.yml file and shows it in output" + task :parse do + puts "#"*80 + puts "# secrets.yml" + puts "#"*80 + puts File.read("config/secrets.yml") + end +end + diff --git a/config/mina/templates/mongoid.yml b/config/mina/templates/mongoid.yml new file mode 100644 index 0000000..1d5c728 --- /dev/null +++ b/config/mina/templates/mongoid.yml @@ -0,0 +1,58 @@ +<%= ENV['RAILS_ENV'] %>: + # Configure available database sessions. (required) + sessions: + # Defines the default session. (required) + default: + # Defines the name of the default database that Mongoid can connect to. + # (required). + database: tecno_freela_<%= ENV['RAILS_ENV'] %> + # Provides the hosts the default session can connect to. Must be an array + # of host:port pairs. (required) + hosts: + - localhost:27017 + options: + # Change the default write concern. (default = { w: 1 }) + # write: + # w: 1 + + # Change the default consistency model to primary, secondary. + # 'secondary' will send reads to secondaries, 'primary' sends everything + # to master. (default: primary) + # read: secondary_preferred + + # How many times Moped should attempt to retry an operation after + # failure. (default: 30) + # max_retries: 30 + + # The time in seconds that Moped should wait before retrying an + # operation on failure. (default: 1) + # retry_interval: 1 + # Configure Mongoid specific options. (optional) + options: + # Includes the root model name in json serialization. (default: false) + # include_root_in_json: false + + # Include the _type field in serializaion. (default: false) + # include_type_for_serialization: false + + # Preload all models in development, needed when models use + # inheritance. (default: false) + # preload_models: false + + # Protect id and type from mass assignment. (default: true) + # protect_sensitive_fields: true + + # Raise an error when performing a #find and the document is not found. + # (default: true) + # raise_not_found_error: true + + # Raise an error when defining a scope with the same name as an + # existing method. (default: false) + # scope_overwrite_exception: false + + # Use Active Support's time zone in conversions. (default: true) + # use_activesupport_time_zone: true + + # Ensure all times are UTC in the app side. (default: false) + # use_utc: false + diff --git a/config/mina/templates/nginx.conf.erb b/config/mina/templates/nginx.conf.erb new file mode 100644 index 0000000..33b3ed3 --- /dev/null +++ b/config/mina/templates/nginx.conf.erb @@ -0,0 +1,109 @@ +<%# +# upstream unicorn { +# server unix:/tmp/unicorn.photoapp.sock fail_timeout=0; +# } +# +# server { +# # listen 80 default deferred; # for Linux +# # listen 80 default accept_filter=httpready; # for FreeBSD +# listen 80 default; +# +# # server_name example.com; +# +# root /vagrant/public; +# try_files $uri/index.html $uri @unicorn; +# location @unicorn { +# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; +# proxy_set_header Host $http_host; +# proxy_redirect off; +# proxy_pass http://unicorn; +# } +# +# error_page 500 502 503 504 /500.html; +# client_max_body_size 100M; +# keepalive_timeout 10; +# } +%> + +<% address_is_ip = !nginx_server_name.match(/\A\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/).nil? %> + +upstream <%= app %>_app_server { + server unix:<%= unicorn_socket %> fail_timeout=0; +} + +# <%= app %> Server +server { + listen 80<%= ' default' if address_is_ip %>; # default; # Tells nginx which site to load if host is not found. For example when using IP: http://192.168.1.54 + server_name .<%= nginx_server_name %>; + + root <%= deploy_to %>/<%= current_path %>/public; + + gzip on; + gzip_types text/plain text/xml application/xml application/xml+rss + text/css text/javascript application/javascript application/json; + +<% if deploy_server != 'production' %> + log_format <%= app %>_combined '$remote_addr - $remote_user [$time_local] ($request_time sec) ' + '"$request" $status $body_bytes_sent ' + '"$http_referer" "$http_user_agent"'; + access_log <%= nginx_log_path %>/access.log <%= app %>_combined; + error_log <%= nginx_log_path %>/error.log info; +<% end %> + + error_page 551 =503 @maintenance; + location @maintenance { + rewrite ^(.*)$ /system/maintenance.html break; + } + set $maintenance 0; + if (-f $document_root/system/maintenance.html) { + set $maintenance 1; + } + if ($request_uri = /favicon.ico) { + # Browsers will try to get favicon if it's not returned with 200ok status + set $maintenance 0; + } + if ($maintenance) { + # There can be several reasons for 503 error. We custom return 551 error + # to ensure maintenance.html is only shown when it's really maintenance + return 551; + } + + rewrite ^/(.*)/$ /$1 permanent; # Truncate trailing slashes + try_files $uri @rails; + + expires -1; +# TODO: enable cache for all non-static content +# maybe expires max; in server context, and expires -1; in @rails location? +# location ~ \.[\w]+$ { # Files with extension, .css, .png, etc. +# expires max; +# } + + location = /favicon.ico { + try_files $uri =204; + access_log off; + log_not_found off; + } + + # location /attachment_files { + # root <%= deploy_to %>/<%= current_path %>/public/system; + # internal; + # } + + location @rails { + proxy_pass http://<%= app %>_app_server; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_intercept_errors on; + expires -1; + } + + error_page 500 502 503 504 /500.html; + error_page 403 /403.html; + error_page 404 /404.html; + + client_max_body_size 50M; + keepalive_timeout 10; +} + diff --git a/config/mina/templates/unicorn.rb.erb b/config/mina/templates/unicorn.rb.erb new file mode 100644 index 0000000..389d122 --- /dev/null +++ b/config/mina/templates/unicorn.rb.erb @@ -0,0 +1,42 @@ +rails_root = "<%= "#{deploy_to!}/#{current_path!}" %>" +rails_env = "<%= rails_env %>" +pid_file = "<%= unicorn_pid %>" +socket_file= "<%= unicorn_socket %>" +log_file = "<%= "#{deploy_to!}/#{shared_path}" %>/log/unicorn.log" +err_log = "<%= "#{deploy_to!}/#{shared_path}" %>/log/unicorn.error.log" +old_pid = pid_file + '.oldbin' + +timeout 60 +worker_processes <%= unicorn_workers %> + +# Listen on a Unix data socket +listen socket_file, :backlog => 2048 +pid pid_file + +stderr_path err_log +stdout_path log_file + +preload_app true + +GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=) + +before_exec do |server| + ENV["BUNDLE_GEMFILE"] = "#{rails_root}/Gemfile" +end + +before_fork do |server, worker| + # Using this method we get 0 downtime deploys. + if File.exists?(old_pid) && server.pid != old_pid + begin + Process.kill("QUIT", File.read(old_pid).to_i) + rescue Errno::ENOENT, Errno::ESRCH + # someone else did our job for us + end + end +end + +after_fork do |server, worker| + child_pid = server.config[:pid].sub('.pid', ".#{worker.nr}.pid") + system("echo #{Process.pid} > #{child_pid}") +end + diff --git a/config/mina/templates/unicorn.sh.erb b/config/mina/templates/unicorn.sh.erb new file mode 100755 index 0000000..ba6f67b --- /dev/null +++ b/config/mina/templates/unicorn.sh.erb @@ -0,0 +1,82 @@ +#!/usr/bin/env bash +set -e + +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games + +AS_USER="<%= user %>" + +TIMEOUT=60 +APP_ROOT="<%= "#{deploy_to!}/#{current_path!}" %>" +PID="<%= unicorn_pid %>" +ENVIRONMENT="<%= rails_env %>" +CONFIG="<%= unicorn_config %>" +UARGS="-D -c $CONFIG -E $ENVIRONMENT" +CMD="cd $APP_ROOT && $APP_ROOT/bin/unicorn_rails $UARGS" +action="$1" +#set -u + + +cd $APP_ROOT || exit 1 + +old_pid="$PID.oldbin" + + +run () { + if [ "$(id -un)" = "$AS_USER" ]; then + eval $1 + else + su -c "$1" - $AS_USER + fi +} + + +sig () { + test -s "$PID" && kill -$1 `cat $PID` +} + +oldsig () { + test -s $old_pid && kill -$1 `cat $old_pid` +} + +workersig () { + workerpid="$APP_ROOT/tmp/pids/unicorn.$2.pid" + test -s "$workerpid" && kill -$1 `cat $workerpid` +} + +case $action in +start) + sig 0 && echo >&2 "Already running" && exit 0 + run "$CMD" && echo "start ok" && exit 0 + ;; +stop) + sig QUIT && echo "stop ok" && exit 0 + echo >&2 "Not running" + ;; +force-stop) + sig TERM && echo "force-stop ok" && exit 0 + echo >&2 "Not running" + ;; +restart|reload) + sig HUP && echo "reloaded OK" && exit 0 + echo >&2 "Couldn't reload, starting '$CMD' instead" + run "$CMD" + ;; +upgrade) + sig USR2 && echo Upgraded && exit 0 + echo >&2 "Couldn't upgrade, starting '$CMD' instead" + run "$CMD" + ;; +kill_worker) + workersig QUIT $2 && exit 0 + echo >&2 "Worker not running" + ;; + +reopen-logs) + sig USR1 + ;; +*) + echo >&2 "Usage: $0 " + exit 1 + ;; +esac + diff --git a/config/mina/unicorn.rb b/config/mina/unicorn.rb new file mode 100644 index 0000000..22ecd03 --- /dev/null +++ b/config/mina/unicorn.rb @@ -0,0 +1,79 @@ +########################################################################### +# Unicorn Tasks +########################################################################### + +namespace :unicorn do + desc "Upload and update (link) all Unicorn config files" + task :update => [:upload, :link] + + desc "Relocate unicorn script file" + task :link do + invoke :sudo + queue 'echo "-----> Relocate unicorn script file"' + queue echo_cmd %{sudo cp "#{config_path}/unicorn.sh" "#{unicorn_script}" && sudo chown #{unicorn_user}:#{unicorn_group} #{unicorn_script} && sudo chmod u+x #{unicorn_script}} + queue echo_cmd "sudo update-rc.d -f #{unicorn_service_name} remove" + queue echo_cmd "sudo update-rc.d -f #{unicorn_service_name} defaults" + queue check_ownership unicorn_user, unicorn_group, unicorn_script + end + + desc "Parses all Unicorn config files and uploads them to server" + task :upload => [:'upload:config', :'upload:script'] + + namespace :upload do + desc "Parses Unicorn config file and uploads it to server" + task :config do + upload_template 'Unicorn config', 'unicorn.rb', "#{config_path}/unicorn.rb" + end + + desc "Parses Unicorn control script file and uploads it to server" + task :script do + upload_template 'Unicorn control script', 'unicorn.sh', "#{config_path}/unicorn.sh" + end + end + + desc "Parses all Unicorn config files and shows them in output" + task :parse => [:'parse:config', :'parse:script'] + + namespace :parse do + desc "Parses Unicorn config file and shows it in output" + task :config do + puts "#"*80 + puts "# unicorn.rb" + puts "#"*80 + puts erb("#{config_templates_path}/unicorn.rb.erb") + end + + desc "Parses Unicorn control script file and shows it in output" + task :script do + puts "#"*80 + puts "# unicorn.sh" + puts "#"*80 + puts erb("#{config_templates_path}/unicorn.sh.erb") + end + end + + desc "Start unicorn" + task :start do + queue 'echo "-----> Start Unicorn"' + queue echo_cmd "#{unicorn_script} start" + end + + desc "Stop unicorn" + task :stop do + queue 'echo "-----> Stop Unicorn"' + queue echo_cmd "#{unicorn_script} stop" + end + + desc "Restart unicorn using 'upgrade'" + task :restart do + queue 'echo "-----> Restart Unicorn"' + queue echo_cmd "#{unicorn_script} upgrade" + end + + desc "Unicorn error logs" + task :logs do + queue 'echo "-----> Unicorn Logs"' + queue echo_cmd "tail -500 #{logs_path}/unicorn.error.log" + end +end +