Commit 97dbc504 by Tran Hoang Viet

VietTH: Update info for deploy

parent e6e8a16c
...@@ -5,6 +5,8 @@ require 'capistrano/bundler' ...@@ -5,6 +5,8 @@ require 'capistrano/bundler'
require 'capistrano/rails/assets' require 'capistrano/rails/assets'
require 'capistrano/rails/migrations' require 'capistrano/rails/migrations'
require 'capistrano3/unicorn' require 'capistrano3/unicorn'
# require 'capistrano/sidekiq'
# require 'capistrano/sidekiq/monit' #to require monit tasks # Only for capistrano3
# Load custom tasks from `lib/capistrano/tasks' if you have any defined # Load custom tasks from `lib/capistrano/tasks' if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
\ No newline at end of file
...@@ -87,6 +87,7 @@ group :development do ...@@ -87,6 +87,7 @@ group :development do
gem 'capistrano-rails' gem 'capistrano-rails'
gem 'capistrano-rvm' gem 'capistrano-rvm'
gem 'capistrano3-unicorn' gem 'capistrano3-unicorn'
gem 'capistrano-sidekiq', '~> 0.5.2'
end end
gem 'rubocop', '~> 0.32.1' gem 'rubocop', '~> 0.32.1'
\ No newline at end of file
...@@ -60,6 +60,9 @@ GEM ...@@ -60,6 +60,9 @@ GEM
capistrano-rvm (0.1.2) capistrano-rvm (0.1.2)
capistrano (~> 3.0) capistrano (~> 3.0)
sshkit (~> 1.2) sshkit (~> 1.2)
capistrano-sidekiq (0.5.3)
capistrano
sidekiq
capistrano3-unicorn (0.2.1) capistrano3-unicorn (0.2.1)
capistrano (~> 3.1, >= 3.1.0) capistrano (~> 3.1, >= 3.1.0)
carrierwave (0.10.0) carrierwave (0.10.0)
...@@ -318,6 +321,7 @@ DEPENDENCIES ...@@ -318,6 +321,7 @@ DEPENDENCIES
byebug byebug
capistrano-rails capistrano-rails
capistrano-rvm capistrano-rvm
capistrano-sidekiq (~> 0.5.2)
capistrano3-unicorn capistrano3-unicorn
carrierwave (~> 0.10.0) carrierwave (~> 0.10.0)
coffee-rails (~> 4.1.0) coffee-rails (~> 4.1.0)
...@@ -355,6 +359,3 @@ DEPENDENCIES ...@@ -355,6 +359,3 @@ DEPENDENCIES
unicorn unicorn
vacuum (~> 1.3.0) vacuum (~> 1.3.0)
web-console (~> 2.0) web-console (~> 2.0)
BUNDLED WITH
1.10.5
class OrderMailer < ActionMailer::Base class OrderMailer < ActionMailer::Base
default from: 'demo@example.com' default from: 'alicuche@gmail.com'
def send_checkout(email, order) def send_checkout(email, order)
@order = order @order = order
......
...@@ -47,6 +47,11 @@ test: ...@@ -47,6 +47,11 @@ test:
# production: # production:
# url: <%= ENV['DATABASE_URL'] %> # url: <%= ENV['DATABASE_URL'] %>
# #
staging:
<<: *default
database: venshop_staging
password: 123456
production: production:
<<: *default <<: *default
database: venshop_vietth database: venshop_vietth
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
lock '3.4.0' lock '3.4.0'
set :application, 'vietth' set :application, 'vietth'
set :repo_url, 'git@gitlab.zigexn.vn:vietth/VietTH-VenShop.git' set :repo_url, 'git@bitbucket.org:alicuche/venshop.git'
set :pty, false
# set :branch, 'master' # set :branch, 'master'
ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call
...@@ -10,19 +11,69 @@ ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call ...@@ -10,19 +11,69 @@ ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call
set :use_sudo, false set :use_sudo, false
set :bundle_binstubs, nil set :bundle_binstubs, nil
set :linked_files, fetch(:linked_files, []).push('config/database.yml') 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') set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads')
after 'deploy:publishing', 'deploy:restart'
namespace :deploy do namespace :deploy do
task :restart do task :restart do
# invoke 'unicorn:reload'
on roles(:app) do on roles(:app) do
within current_path do within current_path do
with rails_env: fetch(:rails_env) do if test("[ -f #{fetch(:unicorn_pid)} ]")
execute :bundle, "exec unicorn -c /web/training/vietth/current/config/unicorn/production.rb -D" execute :kill, capture(:cat, fetch(:unicorn_pid))
end
# run "redis-server --daemonize yes"
with rails_env: fetch(:rails_env), wait: 3 do
execute :bundle, "exec rake seed:migrate"
config_file = if fetch(:rails_env) == :production
"/web/training/vietth/current/config/unicorn/production.rb"
else
"/home/alicuche/Web/venshop/current/config/unicorn/#{fetch(:rails_env)}.rb"
end
execute :bundle, "exec unicorn -c #{config_file} -D"
end end
end end
invoke('sidekiq:restart')
end end
end end
end end
\ No newline at end of file
namespace :sidekiq do
def sidekiq_pid
current_path + 'tmp/pids/sidekiq.pid'
end
def pid_file_exists?
test(*("[ -f #{sidekiq_pid} ]").split(' '))
end
def pid_process_exists?
pid_file_exists? and test(*("kill -0 $( cat #{sidekiq_pid} )").split(' '))
end
task :start do
on roles(:app) do
if !pid_process_exists?
execute "cd #{current_path} && RAILS_ENV=#{fetch(:rails_env)} ~/.rvm/bin/rvm default do bundle exec sidekiq -L log/sidekiq.log -P #{sidekiq_pid} -q default -q mailers -d"
end
end
end
task :stop do
on roles(:app) do
if pid_process_exists?
execute "kill `cat #{sidekiq_pid}`"
execute "rm #{sidekiq_pid}"
end
end
end
task :restart do
on roles(:app) do
invoke "sidekiq:stop"
invoke "sidekiq:start"
end
end
end
after 'deploy:publishing', 'deploy:restart'
# server-based syntax set :port, 22
# ====================== set :user, 'alicuche'
# Defines a single server with a list of roles and multiple properties. set :deploy_via, :remote_cache
# You can define all roles on a single server, or split them: set :use_sudo, false
# server 'example.com', user: 'deploy', roles: %w{app db web}, my_property: :my_value server 'alicuche.koding.io',
# server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value roles: [:web, :app, :db],
# server 'db.example.com', user: 'deploy', roles: %w{db} port: fetch(:port),
user: fetch(:user),
primary: true
# role-based syntax set :deploy_to, "/home/alicuche/Web/venshop"
# ==================
set :ssh_options, {
# Defines a role with one or multiple servers. The primary server in each forward_agent: true,
# group is considered to be the first unless any hosts have the primary auth_methods: %w(publickey),
# property set. Specify the username and a domain or IP for the server. user: 'alicuche',
# Don't use `:all`, it's a meta role. }
# role :app, %w{deploy@example.com}, my_property: :my_value set :rails_env, :staging
# role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value set :conditionally_migrate, true
# role :db, %w{deploy@example.com} \ No newline at end of file
# Configuration
# =============
# You can set any configuration variable like in config/deploy.rb
# These variables are then only loaded and set in this stage.
# For available Capistrano configuration variables see the documentation page.
# http://capistranorb.com/documentation/getting-started/configuration/
# Feel free to add new variables to customise your setup.
# Custom SSH Options
# ==================
# You may pass any option but keep in mind that net/ssh understands a
# limited set of options, consult the Net::SSH documentation.
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
#
# Global options
# --------------
# set :ssh_options, {
# keys: %w(/home/rlisowski/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(password)
# }
#
# The server-based syntax can be used to override options:
# ------------------------------------
# server 'example.com',
# user: 'user_name',
# roles: %w{web app},
# ssh_options: {
# user: 'user_name', # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(publickey password)
# # password: 'please use keys'
# }
...@@ -40,6 +40,5 @@ Rails.application.configure do ...@@ -40,6 +40,5 @@ Rails.application.configure do
# config.action_view.raise_on_missing_translations = true # config.action_view.raise_on_missing_translations = true
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :letter_opener config.action_mailer.delivery_method = :letter_opener
end end
...@@ -76,4 +76,17 @@ Rails.application.configure do ...@@ -76,4 +76,17 @@ Rails.application.configure do
# Do not dump schema after migrations. # Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false config.active_record.dump_schema_after_migration = false
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "alicuche@gmail.com",
:password => "syghbwuxfzfkgmch",
:authentication => :login,
:enable_starttls_auto => true
}
# ActionMailer Config
config.action_mailer.default_url_options = { :host => '192.168.1.204', port: 3005 }
config.action_mailer.delivery_method = :smtp
end end
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 threaded 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 serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
# 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
# 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
# `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
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
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 cannot 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
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "alicuche@gmail.com",
:password => "syghbwuxfzfkgmch",
:authentication => :login,
:enable_starttls_auto => true
}
# ActionMailer Config
config.action_mailer.default_url_options = { :host => 'uakk111d5a2e.alicuche.koding.io', port: 80 }
config.action_mailer.delivery_method = :smtp
end
...@@ -20,3 +20,6 @@ test: ...@@ -20,3 +20,6 @@ test:
# instead read values from the environment. # instead read values from the environment.
production: production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
staging:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
...@@ -13,4 +13,8 @@ test: ...@@ -13,4 +13,8 @@ test:
production: production:
<<: *defaults <<: *defaults
solr_url: http://localhost:8080/solr/venshop_pro solr_url: http://localhost:8080/solr/venshop
\ No newline at end of file
staging:
<<: *defaults
solr_url: http://localhost:8080/solr/venshop
\ No newline at end of file
root = "/home/alicuche/Web/venshop/current"
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
stdout_path "#{root}/log/unicorn.log"
listen "/tmp/unicorn.venshop.sock"
worker_processes 2
timeout 30
preload_app true
###########################################
before_fork do |server, worker|
Signal.trap 'TERM' do
Process.kill 'QUIT', Process.pid || -1
end
defined?(ActiveRecord::Base) &&
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
end
defined?(ActiveRecord::Base) &&
ActiveRecord::Base.establish_connection
end
# Force the bundler gemfile environment variable to
# reference the capistrano "current" symlink
before_exec do |_|
ENV['BUNDLE_GEMFILE'] = File.join(root, 'Gemfile')
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