From 9a97cc94e1aa5aec734b45d4f2058ac764dac444 Mon Sep 17 00:00:00 2001 From: Tom Naessens Date: Tue, 25 Nov 2014 10:00:55 +0100 Subject: [PATCH 1/5] Added capistrano --- Capfile | 11 ++++++++ Gemfile | 8 ++++++ Gemfile.lock | 26 ++++++++++++++++++ config/deploy.rb | 51 +++++++++++++++++++++++++++++++++++ config/deploy/production.rb | 8 ++++++ lib/capistrano/tasks/logs.cap | 8 ++++++ 6 files changed, 112 insertions(+) create mode 100644 Capfile create mode 100644 config/deploy.rb create mode 100644 config/deploy/production.rb create mode 100644 lib/capistrano/tasks/logs.cap diff --git a/Capfile b/Capfile new file mode 100644 index 0000000..a0b2bee --- /dev/null +++ b/Capfile @@ -0,0 +1,11 @@ +# Load DSL and Setup Up Stages +require 'capistrano/setup' + +# Includes default deployment tasks +require 'capistrano/deploy' + +require 'capistrano/rails' +require 'capistrano/rvm' + +# Loads custom tasks from `lib/capistrano/tasks' if you have any defined. +Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r } diff --git a/Gemfile b/Gemfile index c0e89c5..b79cfbb 100644 --- a/Gemfile +++ b/Gemfile @@ -35,6 +35,14 @@ gem 'spring', group: :development # Use Capistrano for deployment # gem 'capistrano-rails', group: :development +# Deployment +gem 'capistrano', '~> 3.1' +gem 'capistrano-rails', '~> 1.1' +gem 'capistrano-rvm' + +group :production do + gem 'mysql2' # Database +end # Use debugger # gem 'debugger', group: [:development, :test] diff --git a/Gemfile.lock b/Gemfile.lock index 12a9ee6..df01c83 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,6 +38,19 @@ GEM columnize (~> 0.8) debugger-linecache (~> 1.2) slop (~> 3.6) + capistrano (3.2.1) + i18n + rake (>= 10.0.0) + sshkit (~> 1.3) + capistrano-bundler (1.1.3) + capistrano (~> 3.1) + sshkit (~> 1.2) + capistrano-rails (1.1.2) + capistrano (~> 3.1) + capistrano-bundler (~> 1.1) + capistrano-rvm (0.1.2) + capistrano (~> 3.0) + sshkit (~> 1.2) coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -45,6 +58,7 @@ GEM coffee-script-source execjs coffee-script-source (1.8.0) + colorize (0.7.3) columnize (0.8.9) debugger-linecache (1.2.0) erubis (2.7.0) @@ -63,6 +77,10 @@ GEM mime-types (2.4.3) minitest (5.4.3) multi_json (1.10.1) + mysql2 (0.3.17) + net-scp (1.2.1) + net-ssh (>= 2.6.5) + net-ssh (2.9.1) rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) @@ -105,6 +123,10 @@ GEM activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) sqlite3 (1.3.10) + sshkit (1.5.1) + colorize + net-scp (>= 1.1.2) + net-ssh (>= 2.8.0) thor (0.19.1) thread_safe (0.3.4) tilt (1.4.1) @@ -125,9 +147,13 @@ DEPENDENCIES bootstrap-sass (= 3.2.0.0) bootstrap-will_paginate (= 0.0.10) byebug + capistrano (~> 3.1) + capistrano-rails (~> 1.1) + capistrano-rvm coffee-rails (~> 4.0.0) jbuilder (~> 2.0) jquery-rails + mysql2 rails (= 4.1.7) sass-rails (~> 4.0.3) sdoc (~> 0.4.0) diff --git a/config/deploy.rb b/config/deploy.rb new file mode 100644 index 0000000..e9929cf --- /dev/null +++ b/config/deploy.rb @@ -0,0 +1,51 @@ +# config valid only for Capistrano 3.1 +# lock '3.1.0' + +set :application, 'Tab' +set :repo_url, 'git@github.com:ZeusWPI/Tab.git' + +set :branch, 'master' +set :deploy_to, '/home/tab/production' + +# Default branch is :master +# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp } + +# Default deploy_to directory is /var/www/my_app +# set :deploy_to, '/var/www/my_app' + +# Default value for :scm is :git +# set :scm, :git + +# Default value for :format is :pretty +# set :format, :pretty + +# Default value for :log_level is :debug + set :log_level, :debug + +# Default value for :pty is false +# set :pty, true + +# Default value for :linked_files is [] +# set :linked_files, %w{config/database.yml} + +# Default value for linked_dirs is [] +set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} + +# Default value for default_env is {} +# set :default_env, { path: "/opt/ruby/bin:$PATH" } + +# Default value for keep_releases is 5 +# set :keep_releases, 5 + +namespace :passenger do + desc "Restart Application" + task :restart do + on roles(:app) do + with rails_env: fetch(:rails_env) do + execute "touch #{current_path}/tmp/restart.txt" + end + end + end +end + +after :deploy, "passenger:restart" diff --git a/config/deploy/production.rb b/config/deploy/production.rb new file mode 100644 index 0000000..1fded02 --- /dev/null +++ b/config/deploy/production.rb @@ -0,0 +1,8 @@ +server 'zeus.ugent.be', user: 'tab', roles: %w{web app db}, + ssh_options: { + forward_agent: true, + auth_methods: ['publickey'], + port: 2222 +} + +set :rails_env, 'production' diff --git a/lib/capistrano/tasks/logs.cap b/lib/capistrano/tasks/logs.cap new file mode 100644 index 0000000..4855a5d --- /dev/null +++ b/lib/capistrano/tasks/logs.cap @@ -0,0 +1,8 @@ +namespace :logs do + desc "tail rails logs" + task :tail do + on roles(:app) do + execute "tail -f #{shared_path}/log/#{fetch(:rails_env)}.log" + end + end +end From 96fbe2c4b8904fe5d8776736722befa59ec6d2ad Mon Sep 17 00:00:00 2001 From: Tom Naessens Date: Tue, 25 Nov 2014 10:05:00 +0100 Subject: [PATCH 2/5] Random dots? --- app/assets/stylesheets/application.css | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 149333d..a06a4ce 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -27,9 +27,9 @@ $gray-medium-light: #eaeaea; -webkit-box-sizing: border-box; box-sizing: border-box; } -. -. -. + + + /* miscellaneous */ .debug_dump { From 52eea26c8a8c17248d478276dc6f3145c9060abe Mon Sep 17 00:00:00 2001 From: Tom Naessens Date: Tue, 25 Nov 2014 10:10:47 +0100 Subject: [PATCH 3/5] Add linked files --- config/deploy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/deploy.rb b/config/deploy.rb index e9929cf..e9fb683 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -26,7 +26,7 @@ set :deploy_to, '/home/tab/production' # set :pty, true # Default value for :linked_files is [] -# set :linked_files, %w{config/database.yml} +set :linked_files, %w{config/database.yml config/secrets.yml} # Default value for linked_dirs is [] set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} From b6cba92124529374bdd5e8fcef7c03827ce3cbdc Mon Sep 17 00:00:00 2001 From: Tom Naessens Date: Tue, 25 Nov 2014 10:16:07 +0100 Subject: [PATCH 4/5] Don't specify ruby version in gemfile --- Gemfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Gemfile b/Gemfile index b79cfbb..d561ce6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,4 @@ source 'https://rubygems.org' -ruby '2.1.5' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' From b423a9d0e811323dfd08dec25a571cfce5f11d00 Mon Sep 17 00:00:00 2001 From: Benjamin Cousaert Date: Tue, 25 Nov 2014 11:30:55 +0100 Subject: [PATCH 5/5] Add some validations to User and errors to form --- app/models/user.rb | 10 +++++----- app/views/application/_errors.html.erb | 5 +++++ app/views/users/new.html.erb | 2 ++ ...0141125102501_add_default_value_balance_to_users.rb | 5 +++++ db/schema.rb | 4 ++-- 5 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 app/views/application/_errors.html.erb create mode 100644 db/migrate/20141125102501_add_default_value_balance_to_users.rb diff --git a/app/models/user.rb b/app/models/user.rb index 3c791bb..34ad658 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,13 +1,13 @@ class User < ActiveRecord::Base has_many :orders - before_save :init + validates :name, presence: true + validates :last_name, presence: true + validates :nickname, presence: true, uniqueness: true - - def init - self.balance ||= 0 + def full_name + "#{name} #{last_name}" end - has_secure_password end diff --git a/app/views/application/_errors.html.erb b/app/views/application/_errors.html.erb new file mode 100644 index 0000000..d7c0fb2 --- /dev/null +++ b/app/views/application/_errors.html.erb @@ -0,0 +1,5 @@ +
    + <% model.errors.full_messages.each do |e| %> + <%= content_tag(:li, e) %> + <% end %> +
diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 6fa72e3..dfe2528 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -3,6 +3,8 @@
<%= form_for(@user) do |f| %> + <%= render partial: 'errors', locals: { model: @user } %> + <%= f.label :nickname %> <%= f.text_field :nickname %> diff --git a/db/migrate/20141125102501_add_default_value_balance_to_users.rb b/db/migrate/20141125102501_add_default_value_balance_to_users.rb new file mode 100644 index 0000000..d0e7afd --- /dev/null +++ b/db/migrate/20141125102501_add_default_value_balance_to_users.rb @@ -0,0 +1,5 @@ +class AddDefaultValueBalanceToUsers < ActiveRecord::Migration + def change + change_column :users, :balance, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 9484f1a..d2a68be 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20141124091707) do +ActiveRecord::Schema.define(version: 20141125102501) do create_table "orders", force: true do |t| t.integer "user_id" @@ -36,7 +36,7 @@ ActiveRecord::Schema.define(version: 20141124091707) do create_table "users", force: true do |t| t.string "name" t.string "last_name" - t.integer "balance" + t.integer "balance", default: 0 t.string "nickname" t.string "password_digest" t.datetime "created_at"