rails 中使用Capistrano部署
git地址: https://github.com/capistrano/capistrano
在Gemfile
中添加Capistrano和其它用到的插件:
group :development do
gem 'capistrano'
gem 'capistrano-rails'
gem 'capistrano-rvm'
gem 'capistrano-sidekiq', require: false
gem 'capistrano3-puma'
end
安装bundle install
初始化:cap install
capfile中的设置可以根据自己的设置来选择
# Load DSL and set up stages
require "capistrano/setup"
# Include default deployment tasks
require "capistrano/deploy"
# Load the SCM plugin appropriate to your project:
#
# require "capistrano/scm/hg"
# install_plugin Capistrano::SCM::Hg
# or
# require "capistrano/scm/svn"
# install_plugin Capistrano::SCM::Svn
# or
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
# 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/sidekiq'
require 'capistrano/puma'
install_plugin Capistrano::Puma, load_hooks: false
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 }
配置好stage :不同的分支不同的设置 staging 、production等
发布命令: cap staging deploy
备注:如果在git中没有上传Gemfile.lock 一定要上传 不然一直会报错
然后就可以在服务器看到目录