I started using Capistrano to deploy my Rails application to different remote servers, however, deploying to a server using cap production deploy sets my RAILS_ENV to deployment instead of production. I have tried forcing the environment by adding ENV['RAILS_ENV'] ||= 'production' to the environment.rb, but that doesn't seem to fix the problem. I checked the production.log for Passenger, Apache, and Rails and nothing seems to be wrong, except for the incorrect environment deployment. What could be wrong with my Capistrano deployment?
production.rb
role :app, %w{deployer#*****}
role :web, %w{deployer#*****}
role :db, %w{deployer#*****}
# Define server(s)
server '*****', user: 'deployer', roles: %w{web}
# SSH Options
# See the example commented out section in the file
# for more options.
set :ssh_options, {
forward_agent: false,
auth_methods: %w(password),
password: '******',
user: 'deployer',
}
deploy.rb
# Define the name of the application
set :application, 'app_pro'
# Define where can Capistrano access the source repository
# set :repo_url, 'https://github.com/[user name]/[application name].git'
set :scm, :git
set :repo_url, 'https://github.com/awernick/app_pros.git'
# Define where to put your application code
set :deploy_to, "/var/sentora/hostdata/zadmin/public_html/app_dir"
set :pty, true
set :format, :pretty
# Set the post-deployment instructions here.
# Once the deployment is complete, Capistrano
# will begin performing them as described.
# To learn more about creating tasks,
# check out:
# http://capistranorb.com/
# namespace: deploy do
# desc 'Restart application'
# task :restart do
# on roles(:app), in: :sequence, wait: 5 do
# # Your restart mechanism here, for example:
# execute :touch, release_path.join('tmp/restart.txt')
# end
# end
# after :publishing, :restart
# after :restart, :clear_cache do
# on roles(:web), in: :groups, limit: 3, wait: 10 do
# # Here we can do anything such as:
# # within release_path do
# # execute :rake, 'cache:clear'
# # end
# end
# end
# end
Capfile
# Load DSL and set up stages
require 'capistrano/setup'
# Include default deployment tasks
require 'capistrano/deploy'
# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
# https://github.com/capistrano/passenger
#
# require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/passenger'
# Load custom tasks from `lib/capistrano/tasks' if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
*The fields in the files are filled out with the correct information.
I could be wrong, but normally Capistrano, as long as it does not have any special plugins for Apache or Nginx, deploys the code as it is, your problems appears to come from passenger configuration. It could be it tries to run the server under wrong environment. I don't remember how it is with Apache, but with nginx you have to make sure the line
...
passenger_app_env production;
...
Is inside /opt/nginx/conf/nginx.conf
Maybe this could help you with setting up Apache config:
https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html#PassengerAppEnv
In production.rb you should have:
set :stage, :production
or some say this option will not work in v3(I am using v3 and set stage works for me), however you might want to read this in case set stage doesn't work:
http://dylanmarkow.com/blog/2014/01/08/capistrano-3-setting-a-default-stage/
I was able to resolve my problem. My problem was occurring because I forgot to add my production secret_key_base as an environment variable in my production server.
Related
I can't figure out how to solve this problem. Capistrano didn't work correctly. So can't deploy my app.
Here's the error.
$ bundle exec cap staging deploy
(Backtrace restricted to imported tasks)
cap aborted!
Net::SSH::AuthenticationFailed: Authentication failed for user ec2-user#13.112.91.105
Here's config file, named config/deploy.rb
# config valid only for Capistrano 3.1
lock '3.5.0'
set :application, 'dola'
set :repo_url, 'git#ghe.intelligence-dev.com/inolab/eiicon-dola.git'
# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call
set :branch, 'master'
# Default deploy_to directory is /var/www/my_app
set :deploy_to, '/var/www/dola'
# Default value for keep_releases is 5
# set :keep_releases, 5
set :rbenv_type, :user
set :rbenv_ruby, '2.3.2-p217'
set :rbenv_map_bins, %w{rake gem bundle ruby rails}
set :rbenv_roles, :all
set :linked_dirs, %w{bin log tmp/backup tmp/pids tmp/cache tmp/sockets vendor/bundle}
role :web, %w{13.112.91.105}
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
# execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, :restart
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
And here's config/deploy/staging.rb
Simple Role Syntax
# ==================
# Supports bulk-adding hosts to roles, the primary server in each group
# is considered to be the first unless any hosts have the primary
# property set. Don't declare `role :all`, it's a meta role.
role :app, %w{ec2-user#13.112.91.105}
role :web, %w{ec2-user#13.112.91.105}
# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server definition into the
# server list. The second argument is a, or duck-types, Hash and is
# used to set extended properties on the server.
server '13.112.91.105', user: 'ec2-user', roles: %w{web app}, my_property: :my_value
# Custom SSH Options
# ==================
set :stage, :staging
set :rails_env, 'staging'
server '13.112.91.105', user: 'ec2-user',
roles: %w{web app}
set :ssh_options, {
keys: [File.expand_path('~/.ssh/id_rsa_ec2.pem)')]
}
Anyone, please!
Capistrano is trying to establish an SSH session between your computer and the machine to which you are trying to deploy your application - 13.112.91.105 in this case. In order to do that, given your Capistrano configuration, you need to be able to authenticate to the SSH server that is running on 13.112.91.105 as the user ec2-user using your SSH private key, which I'm assuming is ~/.ssh/id_rsa_ec2.pem. For this to happen, your corresponding SSH public key must be listed in the authorized_keys file for ec2-user on the machine 13.112.91.105.
I am running sidekiq in production and I deploy my app using capistrano. While processing background job, I am getting following error
I18n::InvalidLocaleData: can not load translations from /path/to/folder/releases/20160904153949/config/locales/en.yml: #<Errno::ENOENT: No such file or directory # rb_sysopen - /path/to/folder/releases/20160904153949/config/locales/en.yml>.
release 20160904153949 is old and has been deleted. I am wondering why sidekiq is still looking into older release.
Below is how my deploy.rb file looks like:
# config valid only for current version of Capistrano
lock '3.4.0'
set :application, 'app_name'
set :repo_url, 'git#github.com:reboot/app_name.git'
# Default branch is :master
set :branch, 'master'
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/path/to/app'
set :use_sudo, false
set :bundle_binstubs, nil
# 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, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
# Default value for linked_dirs is []
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/assets')
# 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
set :keep_assets, 3
after 'deploy:publishing', 'deploy:restart'
namespace :deploy do
task :restart do
on roles(:app) do
execute :touch, release_path.join('tmp/restart.txt')
end
end
end
Below is how my Capfile looks like
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/sidekiq'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
sidekiq stop/start is handled by capistrano/sidekiq gem. My app gets deployed fine. Problem is that sidekiq is looking into wrong release for required file.
Also I don't have sidekiq.yml file at this stage. My app is small so never created yml file for it.
Ruby: 2.3.0p0,
Rails: 4.2.5,
nginx/passenger combination,
Capistrano 3.4
Upadate
Below is full error message:
2016-09-07T19:33:22.349Z 3262 TID-md1a4 ContactUsEmailJob JID-fb18ad450d73ed857fe66aee INFO: fail: 0.069 sec
2016-09-07T19:33:22.350Z 3262 TID-md1a4 WARN: {"class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper","wrapped":"ContactUsEmailJob","queue":"default","args":[{"job_class":"ContactUsEmailJob","job_id":"e30dfe20-89b2-49a9-833c-8e479bdb8a2d","queue_name":"default","arguments":[{"utf8":"✓","authenticity_token":"i+OuDyC2c243UvC0FRWk1esASnUhQ2jKbfvZnoX2GZLela+mPCcOU6qtpU3OZhxr0wTCYUpmFXD6623Q==","name":"Test","message":"test","controller":"static_pages","action":"email_us","_aj_hash_with_indifferent_access":true}],"locale":"en"}],"retry":true,"jid":"fb18ad450d73ed857fe66aee","created_at":1473276802.277088,"enqueued_at":1473276802.2773373,"error_message":"can not load translations from /path/to/app/releases/20160904153949/config/locales/en.yml: #<Errno::ENOENT: No such file or directory # rb_sysopen - /path/to/app/releases/20160904153949/config/locales/en.yml>","error_class":"I18n::InvalidLocaleData","failed_at":1473276802.3480363,"retry_count":0}
2016-09-07T19:33:22.350Z 3262 TID-md1a4 WARN: I18n::InvalidLocaleData: can not load translations from /path/to/app/releases/20160904153949/config/locales/en.yml: #<Errno::ENOENT: No such file or directory # rb_sysopen - /path/to/app/releases/20160904153949/config/locales/en.yml>
2016-09-07T19:33:22.350Z 3262 TID-md1a4 WARN: /path/to/app/shared/bundle/ruby/2.3.0/gems/i18n-0.7.0/lib/i18n/backend/base.rb:184:in `rescue in load_yml'
Ok so I solved the problem by following these steps:
kill process of sidekiq pkill sidekiq
deleted sidekiq pid file from /path/to/app/current/tmp/pid/
started sidekiq using cap sidekiq:start, this will create pid file
finally deploy my app ( this process will restart sidekiq again)
Everything worked find after that.
There is this app which has been upgraded from Rails 3 to 4. (In addition to upgraded from Capistrano 2 to 3). This is an app that was built, has worked fine for a couple years and now we are adding some features and updating things - but deployment is failing.
I've tried reinstalling gems, passenger apache module, various capistrano deployment configuration options (with sudo, without sudo, setting specific gem paths with default_env ) and working through various Capistrano upgrade documentation, guides, blog posts and other SO posts...
Deployment errors
When attempting to push the changes to the staging server the deployment keeps failing.
Here's the base error when running cap staging deploy:
/dependency.rb:315:in `to_specs': Could not find 'passenger' (>= 0) among 14 total gem(s) (Gem::LoadError)
There must be some simple conflict / confusion with paths / sudo / rvmsudo and has taken more time than I'd like to admit debugging...
Initially I tried doing everything without sudo but wasn't getting success. According to the rvm documentation (https://rvm.io/integration/sudo) I tried editng the sudoers file.
So following rvm.io documentation I comment out Default secure_path=... and add Default env_keep and the following error occurs:
Exception while executing as user#example.org: sudo exit status: 127
sudo stdout: /usr/bin/env: ruby: No such file or directory
gem env
Output of $ gem env on the staging server:
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.6
- RUBY VERSION: 2.0.0 (2015-02-25 patchlevel 643) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/user/.rvm/gems/ruby-2.0.0-p643
- RUBY EXECUTABLE: /home/user/.rvm/rubies/ruby-2.0.0-p643/bin/ruby
- EXECUTABLE DIRECTORY: /home/user/.rvm/gems/ruby-2.0.0-p643/bin
- SPEC CACHE DIRECTORY: /home/user/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /home/user/.rvm/rubies/ruby-2.0.0-p643/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/user/.rvm/gems/ruby-2.0.0-p643
- /home/user/.rvm/gems/ruby-2.0.0-p643#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /home/user/.rvm/gems/ruby-2.0.0-p643/bin
- /home/user/.rvm/gems/ruby-2.0.0-p643#global/bin
- /home/user/.rvm/rubies/ruby-2.0.0-p643/bin
- /usr/local/sbin
- /usr/local/bin
- /usr/sbin
- /usr/bin
- /sbin
- /bin
- /usr/games
- /usr/local/games
- /home/user/.rvm/bin
- /home/user/.rvm/bin
config/deploy/staging.rb
# server-based syntax
# ======================
# Defines a single server with a list of roles and multiple properties.
# You can define all roles on a single server, or split them:
# server 'example.com', user: 'deploy', roles: %w{app db web}, my_property: :my_value
# server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value
# server 'db.example.com', user: 'deploy', roles: %w{db}
set :stage, :staging
server "example.org", user: "user", roles: %w{web, app, db}
# role-based syntax
# ==================
# Defines a role with one or multiple servers. The primary server in each
# group is considered to be the first unless any hosts have the primary
# property set. Specify the username and a domain or IP for the server.
# Don't use `:all`, it's a meta role.
role :app, %w{example.org}
role :web, %w{example.org}
role :db, %w{example.org}
# role :app, %w{deploy#example.com}, my_property: :my_value
# role :web, %w{user1#primary.com user2#additional.com}, other_property: :other_value
# role :db, %w{deploy#example.com}
# 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'
# }
set :rails_env, "staging"
set :application, "res.example.org"
set :repo_url, "user#example.org:/home/user/webdocs/appname.git"
# set :repo_url, "ssh://user#example.org:3699/home/user/webdocs/appname.git"
set :ssh_options, {
port: 3699,
verbose: :debug
}
# set :rvm_map_bins, %w{gem rake ruby bundle rvmsudo}
set :rvm_map_bins, fetch(:rvm_map_bins, []).push('rvmsudo')
# set :rbenv_ruby, "2.0.0"
set :port, 3699
set :scm, :git
set :pty, true
# set :use_sudo, true
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
# set :user, 'user'
set :use_sudo, false #true
set :deploy_to, "/var/www/res"
set :branch, "staging"
set :deploy_via, :remote_cache
set :passenger_rvm_ruby_version, "2.0.0"
set :default_env, {
rvm_bin_path: '~/.rvm/bin',
path: "/home/user/.rvm/gems/ruby-2.0.0-p643/bin:/home/user/.rvm/rubies/ruby-2.0.0-p643/bin/ruby:/home/user/.rvm/gems/ruby-2.0.0-p643/bin:$PATH"
}
set :passenger_restart_with_sudo, true
set :log_level, :debug
# set :passenger_restart_with_sudo, true
set :passenger_environment_variables, { :path => '/home/user/.rvm/gems/ruby-2.0.0-p643/bin:/home/user/.rvm/rubies/ruby-2.0.0-p643/bin/ruby:/home/user/.rvm/gems/ruby-2.0.0-p643/bin:$PATH' }
=begin
set :default_environment, {
'PATH' => 'home/user/.rvm/gems/ruby-1.9.3-p385/bin:/home/user/.rvm/gems/ruby-1.9.3-p385#global/bin:/home/user/.rvm/rubies/ruby-1.9.3-p385/bin:/home/user/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/user/.rvm/bin:$PATH'
#'PATH' => '/home/user/.rvm/gems/default/bin:/home/user/.rvm/gems/default#global/bin:/home/user/.rvm/rubies/default/bin:/home/user/.rvm/bin:$PATH'
#'PATH' => '/home/user/.rvm/gems/ruby-1.9.3-p385/bin:/home/user/.rvm/gems/ruby-1.9.3-p385#global/bin:/home/user/.rvm/rubies/ruby-1.9.3-p385/bin:/home/user/.rvm/bin:$PATH'
}
=end
#default_environment["GEM_PATH"] ="/home/user/.rvm/gems/ruby-1.9.2-p320"
# /home/bb/.rvm/gems/ruby-1.9.2-p318/bin:/home/bb/.rvm/gems/ruby-1.9.2-p318#global/bin:/home/bb/.rvm/rubies/ruby-1.9.2-p318/bin:/home/bb/.rvm/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/bb/.cabal/bin:/home/bb/.xmonad/bin
#default_environment["PATH"] = "/home/bb/.rvm/gems/ruby-1.9.2-p318/bin:/home/bb/.rvm/gems/ruby-1.9.2-p318#global/bin:/home/bb/.rvm/rubies/ruby-1.9.2-p318/bin:/home/bb/.rvm/bin:$PATH"
# role :web, "example.org" # Your HTTP server, Apache/etc
#role :app, "example.org" # This may be the same as your `Web` server
#role :db, "example.org", :primary => true # This is where Rails migrations will run
#role :db, "example.org"
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
#after "deploy", "deploy:bundle_gems"
#after "deploy:bundle_gems", "deploy:restart"
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
desc "Install gems"
task :bundle_gems do
on roles(:app), in: :sequence, wait: 5 do
run "cd #{deploy_to}/current && bundle install"
end
end
desc "Setup sym links for uploads..."
task :make_links do
on roles(:app), in: :sequence, wait: 5 do
run "ln -s #{shared_path}/uploads/ #{deploy_to}/current/public/uploads"
end
end
desc "Precompile assets...."
task :precompile_assets do
on roles(:app), in: :sequence, wait: 5 do
run "cd #{deploy_to}/current && bundle exec rake --trace assets:precompile RAILS_ENV=staging"
end
end
# task :start do ; end
# task :stop do ; end
=begin
desc "Restart App"
task :restart do
on roles(:app), in: :sequence, wait: 5 do
execute :touch, release_path.join('tmp/restart.txt')
# run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
=end
end
after "deploy", "deploy:make_links"
after "deploy", "deploy:bundle_gems"
# after "deploy", "deploy:precompile_assets"
Capfile
# Load DSL and set up stages
require 'capistrano/setup'
# Include default deployment tasks
require 'capistrano/deploy'
# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
# https://github.com/capistrano/passenger
#
require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/passenger'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
deploy.rb
# config valid only for current version of Capistrano
lock '3.4.0'
set :application, 'appname'
set :repo_url, 'user#example.org:/home/user/webdocs/appname.git'
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
# set :deploy_to, '/var/www/my_app_name'
# 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
set :stages, %w(staging production)
set :default_stage, "staging"
# Default value for :pty is false
# set :pty, true
# Default value for :linked_files is []
# set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
# Default value for linked_dirs is []
# set :linked_dirs, fetch(:linked_dirs, []).push('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 :deploy do
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
Any suggestions / direction appreciated!
After more testing and further reviewing the Passenger & Capistrano documentation (https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html & http://capistranorb.com/documentation/getting-started/authentication-and-authorisation/ ) there were a few points of confusion resolved.
The gem installation of passenger was uninstalled. Then following the Passenger documentation, and starting over from scratch, Passenger was installed via the Ubuntu repositories / apt-get.
In addition, passwordless sudo access needed to be setup for the deploy user - and update the Capistrano deployment file accordingly.
Specifically making sure
set :passenger_restart_with_sudo, true was set
So the Could not find 'passenger' (>= 0) error is now gone.
Capistrano deployment is getting further. Now it's just hanging up on my rake tasks which is a different issue to work out.
I am using capistrano for deployment, and for some reason my shared/bin folder is empty, and, well it should contain -rails, rake, bundle, setup, spring. now obviously I did something wrong, but as I am new to capistrano, I have no Idea what it is, because it is in my git repository, and as far as I know it copies the entire thing from the repository. since I am not sure wether it is relavent or not, I will just put everything I changed reguarding the capistrano deployment.
here's my deploy.rb
lock '3.4.0'
# application settings
set :application, 'SomeApplication'
set :user, 'someuser'
#set :repo_url, 'git#bitbucket.org:someapp/someappserver.git'
set :rails_env, 'production'
set :use_sudo, false
set :keep_releases, 5
#git settings
set :scm, :git
set :branch, "master"
set :repo_url, "git#bitbucket.org:someapplication/someapplicationserver.git"
set :deploy_via, :remote_cache
set :rvm_ruby_version, '2.2.1'
set :default_env, { rvm_bin_path: '~/.rvm/bin' }
SSHKit.config.command_map[:rake] = "#{fetch(:default_env)[:rvm_bin_path]}/rvm ruby-#{fetch(:rvm_ruby_version)} do bundle exec rake"
# dirs we want symlinked to the shared folder
# during deployment
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :pg_database, "someapp_production"
set :pg_user, "someapp_production"
set :pg_ask_for_password, true
namespace :deploy do
task :config_nginx do
pre = File.basename(previous_release)
cur = File.basename(release_path)
run "#{sudo} sed 's/#{pre}/#{cur}/g' /etc/nginx/sites-available/default"
end
task :restart_thin_server do
run "cd #{previous_release}; source $HOME/.bash_profile && thin stop -C thin_config.yml"
run "cd #{release_path}; source $HOME/.bash_profile && thin start -C thin_config.yml"
end
task :restart_nginx do
run "#{sudo} service nginx restart"
end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
# execute :touch, release_path.join('tmp/restart.txt')
#
# The capistrano-unicorn-nginx gem handles all this
# for this example
end
end
after :publishing, :restart
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
here is my deploy/production.rb
# production deployment
set :stage, :production
# use the master branch of the repository
set :branch, "master"
# the user login on the remote server
# used to connect and deploy
set :deploy_user, "someuser"
# the 'full name' of the application
set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}"
# the server(s) to deploy to
server 'someserver.cloudapp.net', user: 'someuser', roles: %w{web app db}, primary: true
# the path to deploy to
set :deploy_to, "/home/#{fetch(:deploy_user)}/apps/#{fetch(:full_app_name)}"
# set to production for Rails
set :rails_env, :production
and here is my cap file
require 'capistrano/setup'
# Include default deployment tasks
require 'capistrano/deploy'
# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
# https://github.com/capistrano/passenger
#
require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
# require 'capistrano/passenger'
require 'capistrano/thin'
require 'capistrano/postgresql'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
like #emj365 said
just remove bin form your linked_dirs in config/deploy.rb
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
#gilmishal Kindly check with this link .. capistrano-deploy-configuration
And keep your eye on directory path where i did mistake many a times
# Default deploy_to directory is /var/www/my_app_name
# set :deploy_to, '/var/www/my_app_name' # This conf is by default
Hope it will solve your problem
I want to deploy to production an app to my local server. i'm using capistrano 3.
this is my capfile
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails'
#require 'capistrano/rails/migrations'
#require 'capistrano/rails/assets'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
this is my deploy.rb
# config valid only for Capistrano 3.1
lock '3.1.0'
set :application, 'ImpresaZiliani'
set :repo_url, 'francesco#10.0.1.8:repos/impresaziliani.git'
set :branch, 'master'
# 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, '/home/francesco/impresaziliani'
# Default value for :scm is :git
set :scm, :git
set :deploy_user, "francesco"
set :rails_env, "production"
set :keep_releases, 5
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
# execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, :restart
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
set :rvm_ruby_version, '2.1.1'
set :default_env, { rvm_bin_path: '~/.rvm/bin' }
SSHKit.config.command_map[:rake] = "#{fetch(:default_env)[:rvm_bin_path]}/rvm ruby-# {fetch(:rvm_ruby_version)} do bundle exec rake"
my database.yml is ok since if i run manually the migrations on the server it works, i have tried with uncommenting the line of capistrano/rails/migrations and assets but nothing changes: when i deploy it runs fine till the bundler install, then without any warning or error, skip to the asset precompiler and doesn't run migrations.
how can i fix this?
thank you
You also need to make the user deploying has the role of db, such as:
server 'you_ip_address', user: 'user_name', roles: %w{web app db}
rake db:migrate is automatic per deploy in capistrano 3
you just need to uncomment #require 'capistrano/rails/migrations' in your Capfile
Both Jude Calimbas and hiveer's answers are more accurate than the accepted answer - the migration task is run automatically as part of the deploy task.
However, their answers do not explain the problem observed. The only thing that occurs to me is that the database.yml file is not explicitly linked in the deploy.rb file. So a line like
set :linked_files, %w{config/database.yml}
would have fixed it.
I know that this is an old question but it would be interesting to know more details from the OP regarding the problem and the fix.