Commit 867b0162 by Tran Hoang Viet

VietTH: Feature deploy with mina

parent a9b16269
......@@ -13,3 +13,4 @@
/tmp
/public/uploads/
/config/database.yml
/*.sh
......@@ -94,4 +94,9 @@ gem 'rubocop', '~> 0.32.1'
gem 'cartman', '~> 2.1.2'
gem 'font-awesome-rails', '~> 4.3.0.0'
\ No newline at end of file
gem 'font-awesome-rails', '~> 4.3.0.0'
gem 'rolify', '~> 4.0.0'
gem 'mina', '~> 0.3.4'
gem 'mina-unicorn', :require => false
\ No newline at end of file
......@@ -157,6 +157,10 @@ GEM
mime-types (>= 1.16, < 3)
method_source (0.8.2)
mime-types (2.6.1)
mina (0.3.7)
open4 (~> 1.3.4)
rake
mina-unicorn (0.3.0)
mini_magick (3.8.1)
subexec (~> 0.2.1)
mini_portile (0.6.2)
......@@ -169,6 +173,7 @@ GEM
net-ssh (2.9.2)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
open4 (1.3.4)
orm_adapter (0.5.0)
parser (2.2.2.6)
ast (>= 1.1, < 3.0)
......@@ -224,6 +229,7 @@ GEM
request_store (1.1.0)
responders (2.1.0)
railties (>= 4.2.0, < 5)
rolify (4.0.0)
rsolr (1.0.12)
builder (>= 2.1.2)
rspec-core (3.3.1)
......@@ -343,12 +349,15 @@ DEPENDENCIES
jquery-rails
kaminari (~> 0.16.3)
letter_opener (~> 1.4.1)
mina (~> 0.3.4)
mina-unicorn
mini_magick (~> 3.8.1)
mysql2
pry-rails (~> 0.3.4)
quiet_assets
rails (= 4.2.3)
rails_12factor (~> 0.0.3)
rolify (~> 4.0.0)
rsolr (~> 1.0.12)
rspec-rails (~> 3.3.2)
rubocop (~> 0.32.1)
......
......@@ -47,6 +47,12 @@ label.error{
position: relative;
&.disable{
opacity: 0.4;
img{
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
filter: gray;
filter: url("data:image/svg+xml;utf8,<svg version='1.1' xmlns='http://www.w3.org/2000/svg' height='0'><filter id='greyscale'><feColorMatrix type='matrix' values='0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0' /></filter></svg>#greyscale");
}
}
img{
height: 180px;
......
module UserRole extend ActiveSupport::Concern
included do
ROLES = %w(admin user)
before_save :default_role
rolify
def default_role
self.add_role(:user) if self.roles.blank?
end
ROLES.each do |role|
define_method "#{role}?" do
self.has_role?(role)
end
end
end
end
\ No newline at end of file
class Role < ActiveRecord::Base
has_and_belongs_to_many :users, join_table: :users_roles
belongs_to :resource, :polymorphic => true
validates :resource_type,
:inclusion => { :in => Rolify.resource_types },
:allow_nil => true
scopify
end
class User < ActiveRecord::Base
include UserRole
with_options dependent: :nullify do |assoc|
assoc.has_many :orders
assoc.has_many :products
......@@ -12,5 +14,4 @@ class User < ActiveRecord::Base
def cart
Cartman::Cart.new(self.id)
end
end
......@@ -12,11 +12,11 @@
%ul.nav.navbar-nav.navbar-right
- if user_signed_in?
%li
= link_to 'Logout', destroy_user_session_path, method: :delete
= link_to 'New product', new_product_path
%li
= link_to 'Change profile', edit_user_registration_path
%li
= link_to 'New product', new_product_path
= link_to 'Logout', destroy_user_session_path, method: :delete
- else
%li
......
# config valid only for current version of Capistrano
lock '3.4.0'
set :domain, '192.168.1.204'
set :deploy_to, '/web/training/vietth2/'
set :repository, 'git@gitlab.zigexn.vn:vietth/VietTH-VenShop.git'
set :branch, 'master'
set :user, 'ventura'
set :forward_agent, true
set :port, '22'
set :unicorn_pid, "#{deploy_to}/current/tmp/pids/unicorn.pid"
set :shared_paths, ['config/database.yml', 'log', 'config/secrets.yml', 'config/application.yml']
set :application, 'vietth'
set :pty, false
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/unicorn'
# # require 'mina/rbenv' # for rbenv support. (http://rbenv.org)
require 'mina/rvm' # for rvm support. (http://rvm.io)
# set :branch, 'master'
ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call
desc "Deploys the current version to the server."
task :deploy => :environment do
deploy do
# stop accepting new workers
# invoke :'sidekiq:quiet'
set :use_sudo, false
set :bundle_binstubs, nil
set :linked_files, fetch(:linked_files, []).push('config/database.yml')
set :linked_files, fetch(:linked_files, []).push('config/application.yml')
set :linked_dirs, fetch(:linked_dirs, []).push(
'log',
'tmp/pids',
'tmp/cache',
'tmp/sockets',
'vendor/bundle',
'public/system',
'public/uploads'
)
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'rails:db_migrate'
invoke :'rails:assets_precompile'
after 'deploy:publishing', 'deploy:restart'
namespace :deploy do
task :restart do
on roles(:app) do
within current_path do
if test("[ -f #{fetch(:unicorn_pid)} ]")
execute :kill, capture(:cat, fetch(:unicorn_pid))
end
with rails_env: fetch(:rails_env), wait: 3 do
execute :bundle, "exec rake seed:migrate"
config_file = "#{current_path}/config/unicorn/#{fetch(:rails_env)}.rb"
execute :bundle, "exec unicorn -c #{config_file} -D"
end
end
invoke('sidekiq:restart')
to :launch do
# invoke :'sidekiq:restart'
invoke :'unicorn:restart'
end
end
end
after 'deploy:publishing', 'deploy:restart'
# namespace :unicorn do
# desc "Start the application"
# task :start do
# queue 'echo "-----> Puma start"'
# config_file = "#{app_path}/config/unicorn/#{stage}.rb"
# queue "cd #{app_path} && RAILS_ENV=#{stage} bundle exec unicorn -c #{config_file} -D", :pty => false
# end
# desc "Stop the application"
# task :stop do
# queue 'echo "-----> Unicorn stop"'
# queue "cd #{app_path} && kill -9 `cat #{app_path}/tmp/pids/unicorn.pid`"
# end
# desc "Restart the application"
# task :restart do
# queue 'echo "-----> Restart unicorn"'
# invoke :'unicorn:stop'
# invoke :'unicorn:start'
# end
# end
\ No newline at end of file
set :port, 22
set :user, 'ventura'
set :deploy_via, :remote_cache
set :use_sudo, false
set :repo_url, 'git@gitlab.zigexn.vn:vietth/VietTH-VenShop.git'
server '192.168.1.204',
roles: [:web, :app, :db],
port: fetch(:port),
user: fetch(:user),
primary: true
set :deploy_to, "/web/training/#{fetch(:application)}"
set :ssh_options, {
forward_agent: true,
auth_methods: %w(publickey),
user: fetch(:user)
}
set :rails_env, :production
set :conditionally_migrate, true
\ No newline at end of file
set :port, 22
set :user, 'alicuche'
set :deploy_via, :remote_cache
set :use_sudo, false
server 'alicuche.koding.io',
roles: [:web, :app, :db],
port: fetch(:port),
user: fetch(:user),
primary: true
set :deploy_to, "/home/alicuche/Web/venshop"
set :ssh_options, {
forward_agent: true,
auth_methods: %w(publickey),
user: fetch(:user)
}
set :rails_env, :staging
set :conditionally_migrate, true
\ No newline at end of file
Rolify.configure do |config|
# By default ORM adapter is ActiveRecord. uncomment to use mongoid
# config.use_mongoid
# Dynamic shortcuts for User class (user.is_admin? like methods). Default is: false
# config.use_dynamic_shortcuts
end
\ No newline at end of file
class RolifyCreateRoles < ActiveRecord::Migration
def change
create_table(:roles) do |t|
t.string :name
t.references :resource, :polymorphic => true
t.timestamps
end
create_table(:users_roles, :id => false) do |t|
t.references :user
t.references :role
end
add_index(:roles, :name)
add_index(:roles, [ :name, :resource_type, :resource_id ])
add_index(:users_roles, [ :user_id, :role_id ])
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150713093724) do
ActiveRecord::Schema.define(version: 20150716012713) do
create_table "categories", force: :cascade do |t|
t.datetime "created_at", null: false
......@@ -62,6 +62,17 @@ ActiveRecord::Schema.define(version: 20150713093724) do
add_index "products", ["category_id"], name: "index_products_on_category_id", using: :btree
add_index "products", ["user_id"], name: "index_products_on_user_id", using: :btree
create_table "roles", force: :cascade do |t|
t.string "name", limit: 255
t.integer "resource_id", limit: 4
t.string "resource_type", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "roles", ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id", using: :btree
add_index "roles", ["name"], name: "index_roles_on_name", using: :btree
create_table "seed_migration_data_migrations", force: :cascade do |t|
t.string "version", limit: 255
t.integer "runtime", limit: 4
......@@ -86,4 +97,11 @@ ActiveRecord::Schema.define(version: 20150713093724) do
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
create_table "users_roles", id: false, force: :cascade do |t|
t.integer "user_id", limit: 4
t.integer "role_id", limit: 4
end
add_index "users_roles", ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id", using: :btree
end
FactoryGirl.define do
factory :role do
end
end
require 'rails_helper'
RSpec.describe Role, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment