【发布时间】:2017-06-18 10:29:01
【问题描述】:
我正在配置自定义 SCM,因为我不需要本地开发环境中的默认 git,但我想触发自定义逻辑,主要基于从 source_directory 开始创建发布。 如文档 (http://capistranorb.com/documentation/advanced-features/custom-scm/) 中所述,我编写了一个扩展 Capistrano::Plugin 的模块,并设置了所需的方法来处理部署 Capistrano 流程使用的自定义 SCM 实现。
除此之外,当我输入我的 config/deploy/<environment>.rb 条目时:
set :scm, :<custom plugin name>
Capistrano 保持使用默认的 git scm,即使没有声明。
在我的 Capfile 中,两者都加载如下:
require_relative 'scm/local.rb'
install_plugin Capistrano::LocalPlugin
require 'capistrano/git
install_plugin Capistrano::SCM::Git
这里还有自定义单片机的模块:
require 'capistrano/scm/plugin'
module Capistrano
class Capistrano::SCM::LocalPlugin < ::Capistrano::Plugin
def set_defaults
set_if_empty :source_dir, 'non-exisisting-dir'
end
def define_tasks
namespace :local do
task :create_release do
run_locally do
execute :mkdir, '-p', :'tmp'
execute "cd #{fetch(:source_dir)} && tar -cz --exclude tests --exclude vendor --exclude .git --exclude node_modules --exclude tmp/#{fetch(:release_timestamp)}.tar.gz -f tmp/#{fetch(:release_timestamp)}.tar.gz ."
end
on release_roles :all do
execute :mkdir, '-p', release_path
upload! "tmp/#{fetch(:release_timestamp)}.tar.gz", "#{release_path}/#{fetch(:release_timestamp)}.tar.gz"
execute "tar -xvf #{release_path}/#{fetch(:release_timestamp)}.tar.gz --directory #{release_path}"
execute "rm #{release_path}/#{fetch(:release_timestamp)}.tar.gz"
end
run_locally do
execute "rm -rf tmp"
end
end
desc 'Determine the revision that will be deployed'
task :set_current_revision do
run_locally do
set :current_revision, capture(:git, " --git-dir #{fetch(:source_dir)}/.git rev-parse --short #{fetch(:branch)}")
end
end
end
end
def register_hooks
after 'deploy:new_release_path', 'local:create_release'
end
end
结束
有谁知道要使用哪个黑魔法来让 Capistrano 使用我的 scm 而不是默认的 git one?
【问题讨论】:
-
如果我评论
install_plugin Capistrano::SCM::git,自定义的scm将被加载。但显然我想选择使用哪一种,只需在正确的配置文件中设置set :scm, <custom scm>属性即可。
标签: ruby deployment devops capistrano3