capistrano部署文件设置

本文介绍如何使用Capistrano进行项目部署,包括依赖配置、任务定义及自定义命令等关键步骤,适合Rails项目的自动化部署。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本地项目部署远程,并在远程进行操作
github:https://github.com/capistrano/capistrano
capistrano一般依存与于一个rails项目项目里面,也可以创建一个文件development然后cd进去 cap install也能初始化
(1)group :development do
gem 'capistrano'
gem 'capistrano-bundler'
gem 'capistrano-rails'
gem 'capistrano-rbenv'
# Add this if you're using rvm
# gem 'capistrano-rvm'
end 可以选择部分
(2)bundle exec cap install
├── Capfile
├── config
│ ├── deploy
│ │ ├── production.rb
│ │ └── staging.rb
│ └── deploy.rb
└── lib
└── capistrano
└── tasks
(3)deploy文件里 main可以设置
set :stage_dir, 'config/deploy'
set :stages, ["iqiyi_bj_production","iqiyi_sh_production","youku_production","tencent_production"]有些可以能直接是%w{development production}看自己需求吧,取其他名字对应在(2)config/deploy修改名字
(4)config/deploy/xxx_production.rb文件配置
set :application, 'iqiyi'
#server 部署两台,可以自己选一台
server 'remote_ip:30066', user: 'your remote serve name', password: 'your remote serve password', roles: %w{web app db}
server 'remote_ip:30066', user: 'your remote serve name', password: 'your remote serve password', roles: %w{web app db}

#代码仓库
set :repo_url, 'ssh://git@xxxxx/home/git/projects/xxxxx'
set :branch, 'master'

#目标目录
set :deploy_to, '/home/bbbb' #远程目录
set :scm, :git
set :rails_env, fetch(:stage)
set :pty, true

set :keep_releases, 5
(5)写task任务,操作命令
1)第一个任务把代码copy到远程(自动完成)
可以用的命令,after :finishing, 'deploy:cleanup'
after :published, :copy_yml_files
after :published, :build_xxx
还有其他命令 build_xxx这是一个task任务即在部署完成后自动运行的任务
2)自定义命令
task :start do
on roles(:all) do
(3101..3102).each do |i|
stage_param="#{fetch(:stage)}"
astage_param = stage_param.split("_")
stage_param = astage_param[2]
platform_param = astage_param[0]
if stage_param=="production"
stage_param="prod"
end
execute <<-EOBLOCK
logdir=/app/logs/xxx
if [ -d $logdir ]
then echo "$logdir exist!"
else mkdir $logdir
echo "$logdir created!"
fi
EOBLOCK
execute <<-EOBLOCK
echo "#{fetch(:stage)}"
EOBLOCK
execute "cd #{current_path}; ./eagle -r #{platform_param} -p #{i} -e #{stage_param} -c false -alsologtostderr=false -log_dir=\"/app/logs/bidder\" > #{current_path}/nohuplog 2>&1 &"#, pty: false
execute "cat #{current_path}/nohuplog"
end
end
end
上面定义了一个start任务 也可以其他
均是在namespace :deploy do
方法体里面
task :restart do
on roles(:all) do
Rake::Task["deploy:stop"].invoke
Rake::Task["deploy:start"].invoke
end
end
end有些可能不是用execute这个方法,直接run的方式


https://ruby-china.org/topics/18616
http://www.361way.com/capistrano-deploy/3563.html
文档很详细
cap xxx_production deploy
cap xxx_production deploy:start
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值