【问题标题】:When does chef's deploy_revision/before_symlink run?厨师的 deploy_revision/before_symlink 什么时候运行?
【发布时间】:2012-07-12 04:42:22
【问题描述】:

我试图了解 before_symlink 的运行方式和时间,尤其是在出现故障的情况下。拿下这个块:

deploy_revision "foo" do
  action :deploy
  deploy_to "/opt/foo"
  ...
  symlink_before_migrate(app_symlinks.merge({
  ...     }))
  purge_before_symlink([])
  create_dirs_before_symlink([])
  symlinks({})
  before_symlink do
    current_release = release_path

    bash "foo_buildout_install" do
      user "foo"
      cwd current_release
      code <<-EOH
         ...
      EOH
    end
  end
  restart_command do
    current_release = release_path
    bash "foo_foreman_install_and_restart" do
        restart foo || start foo
      EOH
    end
  end
end

before_symlink 块在什么条件下运行?例如,如果构建失败,则重新配置 chef - 它会再次运行吗?如果创建了符号链接,它会再次被调用吗?

(我还在学习 Chef,而且我不做 ruby​​ 开发,所以请不要以为我对 deploy_revision 的工作原理或 rails 部署模型一无所知。)

【问题讨论】:

    标签: ruby deployment chef-infra


    【解决方案1】:

    我相信它会在您每次“部署”时运行,我相信每次您通过 Chef 配置时都​​会发生这种情况。

    如果您想自己进一步研究,请在您的 Ruby gems 路径中找到 Chef 安装并在里面查找 ./lib/chef/provider/deploy.rb

    deploy 方法很容易解释自己:

      def deploy
        enforce_ownership
        verify_directories_exist
        update_cached_repo
        copy_cached_repo
        install_gems
        enforce_ownership
        callback(:before_migrate, @new_resource.before_migrate)
        migrate
        callback(:before_symlink, @new_resource.before_symlink)
        symlink
        callback(:before_restart, @new_resource.before_restart)
        restart
        callback(:after_restart, @new_resource.after_restart)
        cleanup!
        Chef::Log.info "#{@new_resource} deployed to #{@new_resource.deploy_to}"
      end
    

    【讨论】:

    • 嗯,这很容易阅读 :) 如果存储库代码与已经部署的代码相同,是否有一个检查以避免重新部署?
    • 看起来不像,copy_cached_repo 方法只会将cached-copy 目录中的任何内容再次复制到发布目录,然后是上面的符号链接操作等。据推测,缓存副本的存在意味着不再从头开始检查 repo,只是一个 git pull 或其他什么。
    猜你喜欢
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-10
    • 1970-01-01
    • 1970-01-01
    • 2015-03-22
    • 2016-01-29
    相关资源
    最近更新 更多