【问题标题】:Built in capistrano variables内置 capistrano 变量
【发布时间】:2010-12-07 19:41:54
【问题描述】:

有人知道所有内置 Capistrano 变量的列表,例如 current_path 等吗?

【问题讨论】:

    标签: ruby-on-rails ruby capistrano


    【解决方案1】:

    您可以在以下位置找到所有这些:

    https://github.com/capistrano/capistrano/blob/legacy-v2/lib/capistrano/recipes/deploy.rb

    更新:v3 不再具有与 v2 相同的配置选项。我链接了上面的 v2 配置选项,但 v3 有以下内容:

    这里是遗留的,保存在这篇文章中:

    # =========================================================================
    # These variables MUST be set in the client capfiles. If they are not set,
    # the deploy will fail with an error.
    # =========================================================================
    
    _cset(:application) { abort "Please specify the name of your application, set :application, 'foo'" }
    _cset(:repository)  { abort "Please specify the repository that houses your application's code, set :repository, 'foo'" }
    
    # =========================================================================
    # These variables may be set in the client capfile if their default values
    # are not sufficient.
    # =========================================================================
    
    _cset(:scm) { scm_default }
    _cset :deploy_via, :checkout
    
    _cset(:deploy_to) { "/u/apps/#{application}" }
    _cset(:revision)  { source.head }
    
    _cset :rails_env, "production"
    _cset :rake, "rake"
    
    # =========================================================================
    # These variables should NOT be changed unless you are very confident in
    # what you are doing. Make sure you understand all the implications of your
    # changes if you do decide to muck with these!
    # =========================================================================
    
    _cset(:source)            { Capistrano::Deploy::SCM.new(scm, self) }
    _cset(:real_revision)     { source.local.query_revision(revision) { |cmd| with_env("LC_ALL", "C") { run_locally(cmd) } } }
    
    _cset(:strategy)          { Capistrano::Deploy::Strategy.new(deploy_via, self) }
    
    # If overriding release name, please also select an appropriate setting for :releases below.
    _cset(:release_name)      { set :deploy_timestamped, true; Time.now.utc.strftime("%Y%m%d%H%M%S") }
    
    _cset :version_dir,       "releases"
    _cset :shared_dir,        "shared"
    _cset :shared_children,   %w(public/system log tmp/pids)
    _cset :current_dir,       "current"
    
    _cset(:releases_path)     { File.join(deploy_to, version_dir) }
    _cset(:shared_path)       { File.join(deploy_to, shared_dir) }
    _cset(:current_path)      { File.join(deploy_to, current_dir) }
    _cset(:release_path)      { File.join(releases_path, release_name) }
    
    _cset(:releases)          { capture("#{try_sudo} ls -x #{releases_path}", :except => { :no_release => true }).split.sort }
    _cset(:current_release)   { releases.length > 0 ? File.join(releases_path, releases.last) : nil }
    _cset(:previous_release)  { releases.length > 1 ? File.join(releases_path, releases[-2]) : nil }
    
    _cset(:current_revision)  { capture("#{try_sudo} cat #{current_path}/REVISION",     :except => { :no_release => true }).chomp }
    _cset(:latest_revision)   { capture("#{try_sudo} cat #{current_release}/REVISION",  :except => { :no_release => true }).chomp }
    _cset(:previous_revision) { capture("#{try_sudo} cat #{previous_release}/REVISION", :except => { :no_release => true }).chomp if previous_release }
    
    _cset(:run_method)        { fetch(:use_sudo, true) ? :sudo : :run }
    
    # some tasks, like symlink, need to always point at the latest release, but
    # they can also (occassionally) be called standalone. In the standalone case,
    # the timestamped release_path will be inaccurate, since the directory won't
    # actually exist. This variable lets tasks like symlink work either in the
    # standalone case, or during deployment.
    _cset(:latest_release) { exists?(:deploy_timestamped) ? release_path : current_release }
    
    _cset :maintenance_basename, "maintenance"
    _cset(:maintenance_template_path) { File.join(File.dirname(__FILE__), "templates", "maintenance.rhtml") }
    

    【讨论】:

    • 链接失效——这就是为什么不只是抛出一个链接作为答案是个好主意
    • @fotanus 好电话,我找到了遗留值并将它们放在答案中。感谢您指出这一点。
    【解决方案2】:

    Cap 3 似乎将默认设置分散到多个文件中。这是我基于从 Cap 3 主分支中发布的链接中搜索 Cap 2 默认值的重构:

    从第二个链接您可以看到 V2 中的一些变量现在已转换为读取器方法(这意味着您不需要 fetch 它们):

    • deploy_to
    • 部署路径
    • 当前路径
    • releases_path
    • release_path
    • stage_config_path
    • deploy_config_path
    • repo_url
    • repo_path
    • shared_pa​​th
    • 修订日志
    • 现在
    • 资产时间戳

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 2013-05-29
      • 2011-12-12
      • 1970-01-01
      • 2014-07-03
      相关资源
      最近更新 更多