Capstrano经验分享

阅读: 评论:0

Capstrano经验分享

Capstrano经验分享

Capstrano经验分享

Capstrano经验分享 » 社区 | Ruby China

Capstrano经验分享

5小时前 由
piginzoo
在 部署 节点 中发起 最后由 piginzoo 于 3小时前回复 ,
70次阅读

最近鼓捣capstrano并被之折磨,终于有了一些心得,不敢独享,share给大家。

1.我们的的capstrona配置

# encoding: utf-8
require 'bundler/capistrano'                #添加之后部署时会调用bundle install, 如果不需要就可以注释掉
set   :keep_releases, 10                    #只保留10个备份
set   :application, "myapp"     #应用名称
set   :repository,  "git@myapp:/data/gitrepo/myapp"
set   :deploy_to,   "/data/www"
set   :current_public,   "/data/www/current/public"
set   :shared_path,      "/data/www/shared"
set   :user, "deploy"                       #登录部署机器(myapp)的用户名
set   :password, "123456"                   #登录部署机器的密码, 如果不设部署时需要输入密码
set   :use_sudo, false                      #执行的命令中含有sudo, 如果设为false, 用户所有操作都有权限
set   :scm, :git
set   :bundle_flags, '--quiet'
set   :copy_exclude, [".git", "spec"]
set   :group_writable, false
role  :web, "192.168.0.106"                     #Your HTTP server, Apache/etc
role  :app, "192.168.0.106"                     #This may be the same as your `Web` server
role  :db,  "192.168.0.106", :primary => true   #This is where Rails migrations will run
default_run_options[:pty] = true            #pty: 伪登录设备
#after, before 表示在特定操作之后或之前执行其他任务
after "deploy:update", "deploy:migrate"
after "deploy:migrate", "deploy:symbol_resource"
# If you are using Passenger mod_rails uncomment this:
namespace :deploy dodesc "restart the paozhoumo application"task :restart, :roles => :app, :except => { :no_release => true } dorun "#{try_sudo} touch #{File.join(current_path,'tmp',&#')}"# rails 3.1首次访问时间较长,发布成功后先访问一下,进行初始化run "curl -s -o /dev/null 127.0.0.1"end#用新的拉下来的public里面的内容替换旧的shared目录的,然后删除掉public,用shared链接到publicdesc "copy everyting to overwrite the shared public folder"task :symbol_resource do#拷贝新拉下来的images/css/jslib,以及目录下的文件run "rm -rf #{shared_path}/images/*"run "cp -r #{current_public}/images/* #{shared_path}/images/"run "rm -rf #{shared_path}/css/*"run "cp -r #{current_public}/css/* #{shared_path}/css/"run "rm -rf #{shared_path}/jslib/*"run "cp -r #{current_public}/jslib/* #{shared_path}/jslib/"run "rm -f #{shared_path}/*.*"run "cp #{current_public}/*.* #{shared_path}"#然后把拉下来的public目录删除掉run "rm -rf #{current_public}"#把共享的share文件夹中run "ln -sf #{shared_path} #{current_public}"end
end

2.几点说明:

这里有两个帐号,一个是“git@myapp:/data/gitrepo/myapp”,也就是git服务器上的git帐号,还有一个是要部署到某台机器上的时候登录用的帐号:deploy。因此,如果你做本地的ssh的密码配置,在cap deploy过程中,需要输入git用户的密码,和deploy用户的密码。

这里有3台机器将卷入这个部署

  1. 你的开发机
  2. 你的git服务器(放着team的merge后的代码滴最新版)
  3. 你要去部署的服务器

过程就是你在你的开发机器上运行 cap deploy,然后远程登录到被部署的机器上跑cap的脚本,期间会自动到git服务器上拉代码,过程大抵如此。

后面我trace了一个整个过程的shell脚本,并加上注释,可以细看。

在第一次运行 cap deploy:setup的时候,会报权限错误,毕竟deploy用户权限很低,不能随便创建目录,那么就用root或者其他有权限的帐号,先建好my app的根目录,然后chown deploy:deploy_group /my_app_root即可。

由于脚本中有了这行require 'bundler/capistrano' ,cap会在部署的时候,重新拉一份gem下来,放到 shared/bunld目录下, 即使你生产机器上已经有gem了,小哥们还是会不知疲倦地下载一份,原因是,这个脚本触发了这条命令:bundle install --gemfile /data/www/releases/20120321020234/Gemfile --path /data/www/shared/bundle --quiet --without development test.我曾经担心过rails启动的时候,是去找这里面的gem还是去找系统目录下的gem呢,后来得知在Myapp目录下会生成一个 .bundld/config,告诉rails用哪个gem目录,就释然了。

3. cap运行过程中的脚本:

#列出remote上最新的head
git ls-remote deploy@paozhoumo:/data/gitrepo/paozhoumo HEAD
#做一些目录清场和准备
rm -rf /data/www/releases/20120321020234/public/assets
mkdir -p /data/www/releases/20120321020234/public
mkdir -p /data/www/shared/assets
#做1个软连接,后面还有3个
ln -s /data/www/shared/assets /data/www/releases/20120321020234/public/assets
#改变目录为组可写
chmod -R g+w /data/www/releases/20120321020234
rm -rf /data/www/releases/20120321020234/log /data/www/releases/20120321020234/public/system /data/www/releases/20120321020234/tmp/pids
mkdir -p /data/www/releases/20120321020234/public
mkdir -p /data/www/releases/20120321020234/tmp
#做了3个软连接
ln -s /data/www/shared/log /data/www/releases/20120321020234/log
ln -s /data/www/shared/system /data/www/releases/20120321020234/public/system
ln -s /data/www/shared/pids /data/www/releases/20120321020234/tmp/pids
#重新touch一下这些目录中的所有的文件
find /data/www/releases/20120321020234/public/images /data/www/releases/20120321020234/public/stylesheets /data/www/releases/20120321020234/public/javascripts -exec touch -t 201203210202.50 {} ';'; true
#列出文件来,-x是在一行的意思,不知道要干嘛?
ls -x /data/www/releases
cd /data/www/releases/20120321020234
#安装bundle到/shared/bundle里面,但是用的Gemfile是新拉下来的gemfile
bundle install --gemfile /data/www/releases/20120321020234/Gemfile --path /data/www/shared/bundle --quiet --without development test
cd /data/www/releases/20120321030939
#做资源预编译,地球人都知道
bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile
#改链接之类的后续活
rm -f /data/www/current && ln -s /data/www/releases/20120321030939 /data/www/current
cd /data/www/releases/20120321030939
#执行migration
bundle exec rake RAILS_ENV=production  db:migrate
。。。。
# 后面就没啥了

4.参考:

官方给的流程图:

  • .x-Significant-Configuration-Variables
  • .html
  3人喜欢


截止 3小时前, 共收到 2 条回复 comme

1楼, 于3小时前回复

@piginzoo 用过 keep_releases 选项了么?使用貌似不会默认保留指定的版本数,需要手动执行cap deploy:cleanup

piginzoo

2楼, 于3小时前回复

@comme ,还真没有,这个选项是照着文档上拷的,回头我试试。

Capstrano经验分享 » 社区 | Ruby China

Capstrano经验分享

5小时前 由
piginzoo
在 部署 节点 中发起 最后由 piginzoo 于 3小时前回复 ,
70次阅读

最近鼓捣capstrano并被之折磨,终于有了一些心得,不敢独享,share给大家。

1.我们的的capstrona配置

# encoding: utf-8
require 'bundler/capistrano'                #添加之后部署时会调用bundle install, 如果不需要就可以注释掉
set   :keep_releases, 10                    #只保留10个备份
set   :application, "myapp"     #应用名称
set   :repository,  "git@myapp:/data/gitrepo/myapp"
set   :deploy_to,   "/data/www"
set   :current_public,   "/data/www/current/public"
set   :shared_path,      "/data/www/shared"
set   :user, "deploy"                       #登录部署机器(myapp)的用户名
set   :password, "123456"                   #登录部署机器的密码, 如果不设部署时需要输入密码
set   :use_sudo, false                      #执行的命令中含有sudo, 如果设为false, 用户所有操作都有权限
set   :scm, :git
set   :bundle_flags, '--quiet'
set   :copy_exclude, [".git", "spec"]
set   :group_writable, false
role  :web, "192.168.0.106"                     #Your HTTP server, Apache/etc
role  :app, "192.168.0.106"                     #This may be the same as your `Web` server
role  :db,  "192.168.0.106", :primary => true   #This is where Rails migrations will run
default_run_options[:pty] = true            #pty: 伪登录设备
#after, before 表示在特定操作之后或之前执行其他任务
after "deploy:update", "deploy:migrate"
after "deploy:migrate", "deploy:symbol_resource"
# If you are using Passenger mod_rails uncomment this:
namespace :deploy dodesc "restart the paozhoumo application"task :restart, :roles => :app, :except => { :no_release => true } dorun "#{try_sudo} touch #{File.join(current_path,'tmp',&#')}"# rails 3.1首次访问时间较长,发布成功后先访问一下,进行初始化run "curl -s -o /dev/null 127.0.0.1"end#用新的拉下来的public里面的内容替换旧的shared目录的,然后删除掉public,用shared链接到publicdesc "copy everyting to overwrite the shared public folder"task :symbol_resource do#拷贝新拉下来的images/css/jslib,以及目录下的文件run "rm -rf #{shared_path}/images/*"run "cp -r #{current_public}/images/* #{shared_path}/images/"run "rm -rf #{shared_path}/css/*"run "cp -r #{current_public}/css/* #{shared_path}/css/"run "rm -rf #{shared_path}/jslib/*"run "cp -r #{current_public}/jslib/* #{shared_path}/jslib/"run "rm -f #{shared_path}/*.*"run "cp #{current_public}/*.* #{shared_path}"#然后把拉下来的public目录删除掉run "rm -rf #{current_public}"#把共享的share文件夹中run "ln -sf #{shared_path} #{current_public}"end
end

2.几点说明:

这里有两个帐号,一个是“git@myapp:/data/gitrepo/myapp”,也就是git服务器上的git帐号,还有一个是要部署到某台机器上的时候登录用的帐号:deploy。因此,如果你做本地的ssh的密码配置,在cap deploy过程中,需要输入git用户的密码,和deploy用户的密码。

这里有3台机器将卷入这个部署

  1. 你的开发机
  2. 你的git服务器(放着team的merge后的代码滴最新版)
  3. 你要去部署的服务器

过程就是你在你的开发机器上运行 cap deploy,然后远程登录到被部署的机器上跑cap的脚本,期间会自动到git服务器上拉代码,过程大抵如此。

后面我trace了一个整个过程的shell脚本,并加上注释,可以细看。

在第一次运行 cap deploy:setup的时候,会报权限错误,毕竟deploy用户权限很低,不能随便创建目录,那么就用root或者其他有权限的帐号,先建好my app的根目录,然后chown deploy:deploy_group /my_app_root即可。

由于脚本中有了这行require 'bundler/capistrano' ,cap会在部署的时候,重新拉一份gem下来,放到 shared/bunld目录下, 即使你生产机器上已经有gem了,小哥们还是会不知疲倦地下载一份,原因是,这个脚本触发了这条命令:bundle install --gemfile /data/www/releases/20120321020234/Gemfile --path /data/www/shared/bundle --quiet --without development test.我曾经担心过rails启动的时候,是去找这里面的gem还是去找系统目录下的gem呢,后来得知在Myapp目录下会生成一个 .bundld/config,告诉rails用哪个gem目录,就释然了。

3. cap运行过程中的脚本:

#列出remote上最新的head
git ls-remote deploy@paozhoumo:/data/gitrepo/paozhoumo HEAD
#做一些目录清场和准备
rm -rf /data/www/releases/20120321020234/public/assets
mkdir -p /data/www/releases/20120321020234/public
mkdir -p /data/www/shared/assets
#做1个软连接,后面还有3个
ln -s /data/www/shared/assets /data/www/releases/20120321020234/public/assets
#改变目录为组可写
chmod -R g+w /data/www/releases/20120321020234
rm -rf /data/www/releases/20120321020234/log /data/www/releases/20120321020234/public/system /data/www/releases/20120321020234/tmp/pids
mkdir -p /data/www/releases/20120321020234/public
mkdir -p /data/www/releases/20120321020234/tmp
#做了3个软连接
ln -s /data/www/shared/log /data/www/releases/20120321020234/log
ln -s /data/www/shared/system /data/www/releases/20120321020234/public/system
ln -s /data/www/shared/pids /data/www/releases/20120321020234/tmp/pids
#重新touch一下这些目录中的所有的文件
find /data/www/releases/20120321020234/public/images /data/www/releases/20120321020234/public/stylesheets /data/www/releases/20120321020234/public/javascripts -exec touch -t 201203210202.50 {} ';'; true
#列出文件来,-x是在一行的意思,不知道要干嘛?
ls -x /data/www/releases
cd /data/www/releases/20120321020234
#安装bundle到/shared/bundle里面,但是用的Gemfile是新拉下来的gemfile
bundle install --gemfile /data/www/releases/20120321020234/Gemfile --path /data/www/shared/bundle --quiet --without development test
cd /data/www/releases/20120321030939
#做资源预编译,地球人都知道
bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile
#改链接之类的后续活
rm -f /data/www/current && ln -s /data/www/releases/20120321030939 /data/www/current
cd /data/www/releases/20120321030939
#执行migration
bundle exec rake RAILS_ENV=production  db:migrate
。。。。
# 后面就没啥了

4.参考:

官方给的流程图:

  • .x-Significant-Configuration-Variables
  • .html
  3人喜欢


截止 3小时前, 共收到 2 条回复 comme

1楼, 于3小时前回复

@piginzoo 用过 keep_releases 选项了么?使用貌似不会默认保留指定的版本数,需要手动执行cap deploy:cleanup

piginzoo

2楼, 于3小时前回复

@comme ,还真没有,这个选项是照着文档上拷的,回头我试试。

Capstrano经验分享 » 社区 | Ruby China

Capstrano经验分享

5小时前 由
piginzoo
在 部署 节点 中发起 最后由 piginzoo 于 3小时前回复 ,
70次阅读

最近鼓捣capstrano并被之折磨,终于有了一些心得,不敢独享,share给大家。

1.我们的的capstrona配置

# encoding: utf-8
require 'bundler/capistrano'                #添加之后部署时会调用bundle install, 如果不需要就可以注释掉
set   :keep_releases, 10                    #只保留10个备份
set   :application, "myapp"     #应用名称
set   :repository,  "git@myapp:/data/gitrepo/myapp"
set   :deploy_to,   "/data/www"
set   :current_public,   "/data/www/current/public"
set   :shared_path,      "/data/www/shared"
set   :user, "deploy"                       #登录部署机器(myapp)的用户名
set   :password, "123456"                   #登录部署机器的密码, 如果不设部署时需要输入密码
set   :use_sudo, false                      #执行的命令中含有sudo, 如果设为false, 用户所有操作都有权限
set   :scm, :git
set   :bundle_flags, '--quiet'
set   :copy_exclude, [".git", "spec"]
set   :group_writable, false
role  :web, "192.168.0.106"                     #Your HTTP server, Apache/etc
role  :app, "192.168.0.106"                     #This may be the same as your `Web` server
role  :db,  "192.168.0.106", :primary => true   #This is where Rails migrations will run
default_run_options[:pty] = true            #pty: 伪登录设备
#after, before 表示在特定操作之后或之前执行其他任务
after "deploy:update", "deploy:migrate"
after "deploy:migrate", "deploy:symbol_resource"
# If you are using Passenger mod_rails uncomment this:
namespace :deploy dodesc "restart the paozhoumo application"task :restart, :roles => :app, :except => { :no_release => true } dorun "#{try_sudo} touch #{File.join(current_path,'tmp',&#')}"# rails 3.1首次访问时间较长,发布成功后先访问一下,进行初始化run "curl -s -o /dev/null 127.0.0.1"end#用新的拉下来的public里面的内容替换旧的shared目录的,然后删除掉public,用shared链接到publicdesc "copy everyting to overwrite the shared public folder"task :symbol_resource do#拷贝新拉下来的images/css/jslib,以及目录下的文件run "rm -rf #{shared_path}/images/*"run "cp -r #{current_public}/images/* #{shared_path}/images/"run "rm -rf #{shared_path}/css/*"run "cp -r #{current_public}/css/* #{shared_path}/css/"run "rm -rf #{shared_path}/jslib/*"run "cp -r #{current_public}/jslib/* #{shared_path}/jslib/"run "rm -f #{shared_path}/*.*"run "cp #{current_public}/*.* #{shared_path}"#然后把拉下来的public目录删除掉run "rm -rf #{current_public}"#把共享的share文件夹中run "ln -sf #{shared_path} #{current_public}"end
end

2.几点说明:

这里有两个帐号,一个是“git@myapp:/data/gitrepo/myapp”,也就是git服务器上的git帐号,还有一个是要部署到某台机器上的时候登录用的帐号:deploy。因此,如果你做本地的ssh的密码配置,在cap deploy过程中,需要输入git用户的密码,和deploy用户的密码。

这里有3台机器将卷入这个部署

  1. 你的开发机
  2. 你的git服务器(放着team的merge后的代码滴最新版)
  3. 你要去部署的服务器

过程就是你在你的开发机器上运行 cap deploy,然后远程登录到被部署的机器上跑cap的脚本,期间会自动到git服务器上拉代码,过程大抵如此。

后面我trace了一个整个过程的shell脚本,并加上注释,可以细看。

在第一次运行 cap deploy:setup的时候,会报权限错误,毕竟deploy用户权限很低,不能随便创建目录,那么就用root或者其他有权限的帐号,先建好my app的根目录,然后chown deploy:deploy_group /my_app_root即可。

由于脚本中有了这行require 'bundler/capistrano' ,cap会在部署的时候,重新拉一份gem下来,放到 shared/bunld目录下, 即使你生产机器上已经有gem了,小哥们还是会不知疲倦地下载一份,原因是,这个脚本触发了这条命令:bundle install --gemfile /data/www/releases/20120321020234/Gemfile --path /data/www/shared/bundle --quiet --without development test.我曾经担心过rails启动的时候,是去找这里面的gem还是去找系统目录下的gem呢,后来得知在Myapp目录下会生成一个 .bundld/config,告诉rails用哪个gem目录,就释然了。

3. cap运行过程中的脚本:

#列出remote上最新的head
git ls-remote deploy@paozhoumo:/data/gitrepo/paozhoumo HEAD
#做一些目录清场和准备
rm -rf /data/www/releases/20120321020234/public/assets
mkdir -p /data/www/releases/20120321020234/public
mkdir -p /data/www/shared/assets
#做1个软连接,后面还有3个
ln -s /data/www/shared/assets /data/www/releases/20120321020234/public/assets
#改变目录为组可写
chmod -R g+w /data/www/releases/20120321020234
rm -rf /data/www/releases/20120321020234/log /data/www/releases/20120321020234/public/system /data/www/releases/20120321020234/tmp/pids
mkdir -p /data/www/releases/20120321020234/public
mkdir -p /data/www/releases/20120321020234/tmp
#做了3个软连接
ln -s /data/www/shared/log /data/www/releases/20120321020234/log
ln -s /data/www/shared/system /data/www/releases/20120321020234/public/system
ln -s /data/www/shared/pids /data/www/releases/20120321020234/tmp/pids
#重新touch一下这些目录中的所有的文件
find /data/www/releases/20120321020234/public/images /data/www/releases/20120321020234/public/stylesheets /data/www/releases/20120321020234/public/javascripts -exec touch -t 201203210202.50 {} ';'; true
#列出文件来,-x是在一行的意思,不知道要干嘛?
ls -x /data/www/releases
cd /data/www/releases/20120321020234
#安装bundle到/shared/bundle里面,但是用的Gemfile是新拉下来的gemfile
bundle install --gemfile /data/www/releases/20120321020234/Gemfile --path /data/www/shared/bundle --quiet --without development test
cd /data/www/releases/20120321030939
#做资源预编译,地球人都知道
bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile
#改链接之类的后续活
rm -f /data/www/current && ln -s /data/www/releases/20120321030939 /data/www/current
cd /data/www/releases/20120321030939
#执行migration
bundle exec rake RAILS_ENV=production  db:migrate
。。。。
# 后面就没啥了

4.参考:

官方给的流程图:

  • .x-Significant-Configuration-Variables
  • .html
  3人喜欢


截止 3小时前, 共收到 2 条回复 comme

1楼, 于3小时前回复

@piginzoo 用过 keep_releases 选项了么?使用貌似不会默认保留指定的版本数,需要手动执行cap deploy:cleanup

piginzoo

2楼, 于3小时前回复

@comme ,还真没有,这个选项是照着文档上拷的,回头我试试。

Capstrano经验分享 » 社区 | Ruby China

Capstrano经验分享

5小时前 由
piginzoo
在 部署 节点 中发起 最后由 piginzoo 于 3小时前回复 ,
70次阅读

最近鼓捣capstrano并被之折磨,终于有了一些心得,不敢独享,share给大家。

1.我们的的capstrona配置

# encoding: utf-8
require 'bundler/capistrano'                #添加之后部署时会调用bundle install, 如果不需要就可以注释掉
set   :keep_releases, 10                    #只保留10个备份
set   :application, "myapp"     #应用名称
set   :repository,  "git@myapp:/data/gitrepo/myapp"
set   :deploy_to,   "/data/www"
set   :current_public,   "/data/www/current/public"
set   :shared_path,      "/data/www/shared"
set   :user, "deploy"                       #登录部署机器(myapp)的用户名
set   :password, "123456"                   #登录部署机器的密码, 如果不设部署时需要输入密码
set   :use_sudo, false                      #执行的命令中含有sudo, 如果设为false, 用户所有操作都有权限
set   :scm, :git
set   :bundle_flags, '--quiet'
set   :copy_exclude, [".git", "spec"]
set   :group_writable, false
role  :web, "192.168.0.106"                     #Your HTTP server, Apache/etc
role  :app, "192.168.0.106"                     #This may be the same as your `Web` server
role  :db,  "192.168.0.106", :primary => true   #This is where Rails migrations will run
default_run_options[:pty] = true            #pty: 伪登录设备
#after, before 表示在特定操作之后或之前执行其他任务
after "deploy:update", "deploy:migrate"
after "deploy:migrate", "deploy:symbol_resource"
# If you are using Passenger mod_rails uncomment this:
namespace :deploy dodesc "restart the paozhoumo application"task :restart, :roles => :app, :except => { :no_release => true } dorun "#{try_sudo} touch #{File.join(current_path,'tmp',&#')}"# rails 3.1首次访问时间较长,发布成功后先访问一下,进行初始化run "curl -s -o /dev/null 127.0.0.1"end#用新的拉下来的public里面的内容替换旧的shared目录的,然后删除掉public,用shared链接到publicdesc "copy everyting to overwrite the shared public folder"task :symbol_resource do#拷贝新拉下来的images/css/jslib,以及目录下的文件run "rm -rf #{shared_path}/images/*"run "cp -r #{current_public}/images/* #{shared_path}/images/"run "rm -rf #{shared_path}/css/*"run "cp -r #{current_public}/css/* #{shared_path}/css/"run "rm -rf #{shared_path}/jslib/*"run "cp -r #{current_public}/jslib/* #{shared_path}/jslib/"run "rm -f #{shared_path}/*.*"run "cp #{current_public}/*.* #{shared_path}"#然后把拉下来的public目录删除掉run "rm -rf #{current_public}"#把共享的share文件夹中run "ln -sf #{shared_path} #{current_public}"end
end

2.几点说明:

这里有两个帐号,一个是“git@myapp:/data/gitrepo/myapp”,也就是git服务器上的git帐号,还有一个是要部署到某台机器上的时候登录用的帐号:deploy。因此,如果你做本地的ssh的密码配置,在cap deploy过程中,需要输入git用户的密码,和deploy用户的密码。

这里有3台机器将卷入这个部署

  1. 你的开发机
  2. 你的git服务器(放着team的merge后的代码滴最新版)
  3. 你要去部署的服务器

过程就是你在你的开发机器上运行 cap deploy,然后远程登录到被部署的机器上跑cap的脚本,期间会自动到git服务器上拉代码,过程大抵如此。

后面我trace了一个整个过程的shell脚本,并加上注释,可以细看。

在第一次运行 cap deploy:setup的时候,会报权限错误,毕竟deploy用户权限很低,不能随便创建目录,那么就用root或者其他有权限的帐号,先建好my app的根目录,然后chown deploy:deploy_group /my_app_root即可。

由于脚本中有了这行require 'bundler/capistrano' ,cap会在部署的时候,重新拉一份gem下来,放到 shared/bunld目录下, 即使你生产机器上已经有gem了,小哥们还是会不知疲倦地下载一份,原因是,这个脚本触发了这条命令:bundle install --gemfile /data/www/releases/20120321020234/Gemfile --path /data/www/shared/bundle --quiet --without development test.我曾经担心过rails启动的时候,是去找这里面的gem还是去找系统目录下的gem呢,后来得知在Myapp目录下会生成一个 .bundld/config,告诉rails用哪个gem目录,就释然了。

3. cap运行过程中的脚本:

#列出remote上最新的head
git ls-remote deploy@paozhoumo:/data/gitrepo/paozhoumo HEAD
#做一些目录清场和准备
rm -rf /data/www/releases/20120321020234/public/assets
mkdir -p /data/www/releases/20120321020234/public
mkdir -p /data/www/shared/assets
#做1个软连接,后面还有3个
ln -s /data/www/shared/assets /data/www/releases/20120321020234/public/assets
#改变目录为组可写
chmod -R g+w /data/www/releases/20120321020234
rm -rf /data/www/releases/20120321020234/log /data/www/releases/20120321020234/public/system /data/www/releases/20120321020234/tmp/pids
mkdir -p /data/www/releases/20120321020234/public
mkdir -p /data/www/releases/20120321020234/tmp
#做了3个软连接
ln -s /data/www/shared/log /data/www/releases/20120321020234/log
ln -s /data/www/shared/system /data/www/releases/20120321020234/public/system
ln -s /data/www/shared/pids /data/www/releases/20120321020234/tmp/pids
#重新touch一下这些目录中的所有的文件
find /data/www/releases/20120321020234/public/images /data/www/releases/20120321020234/public/stylesheets /data/www/releases/20120321020234/public/javascripts -exec touch -t 201203210202.50 {} ';'; true
#列出文件来,-x是在一行的意思,不知道要干嘛?
ls -x /data/www/releases
cd /data/www/releases/20120321020234
#安装bundle到/shared/bundle里面,但是用的Gemfile是新拉下来的gemfile
bundle install --gemfile /data/www/releases/20120321020234/Gemfile --path /data/www/shared/bundle --quiet --without development test
cd /data/www/releases/20120321030939
#做资源预编译,地球人都知道
bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile
#改链接之类的后续活
rm -f /data/www/current && ln -s /data/www/releases/20120321030939 /data/www/current
cd /data/www/releases/20120321030939
#执行migration
bundle exec rake RAILS_ENV=production  db:migrate
。。。。
# 后面就没啥了

4.参考:

官方给的流程图:

  • .x-Significant-Configuration-Variables
  • .html
  3人喜欢


截止 3小时前, 共收到 2 条回复 comme

1楼, 于3小时前回复

@piginzoo 用过 keep_releases 选项了么?使用貌似不会默认保留指定的版本数,需要手动执行cap deploy:cleanup

piginzoo

2楼, 于3小时前回复

@comme ,还真没有,这个选项是照着文档上拷的,回头我试试。

posted on 2012-03-21 16:11  lexus 阅读( ...) 评论( ...) 编辑 收藏

转载于:.html

本文发布于:2024-02-02 16:06:54,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170686121244912.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:经验   Capstrano
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23