我在厨师的git资源面临一个奇怪的问题。即使存储库和标记存在,我也会收到UnresolvableGitReference
错误。
配方中编译的资源:
git("/opt/some-repo") do
action [:sync]
retries 0
retry_delay 2
default_guard_interpreter :default
destination "/opt/some-repo"
enable_checkout true
revision "tags/v3.0.4"
remote "origin"
checkout_branch "deploy"
declared_type :git
cookbook_name :"some-cookbook"
recipe_name "install"
user "ubuntu"
repository "git@github.com:someUser/some-repo.git"
end
实例可以访问git repo和引用。
git ls-remote 'git@github.com:someUser/some-repo.git' 'tags/v3.0.4*'
返回提交ID。
这本食谱在厨师v11.8.2中运作良好,但在厨师v12.5.1
中失败了答案 0 :(得分:2)
使用git
资源,您只能使用标记名称'v3.0.4'
。如果您需要指定它是标记,您还可以使用完整路径:'refs/tags/v3.0.4'
。
之前有效,因为Chef 11 checks against the reference sufix:
found = refs.find { |m| m[1].end_with?(@new_resource.revision) }
但是你可能会想到这可能会有问题。我认为'tags/v3.0.4'
工作从来都不是预期的行为。
无论如何,in Chef 12 the implementation has changed,现在按前缀搜索,追加'ref/tags/'
和'refs/heads/'
分别搜索标签和分支:
def find_revision(refs, revision, suffix="")
found = refs_search(refs, rev_match_pattern('refs/tags/', revision) + suffix)
found = refs_search(refs, rev_match_pattern('refs/heads/', revision) + suffix) if found.empty?
found = refs_search(refs, revision + suffix) if found.empty?
found
end
def rev_match_pattern(prefix, revision)
if revision.start_with?(prefix)
revision
else
prefix + revision
end
end
答案 1 :(得分:0)
所以,我玩了一下,发现了问题。 属性 tag
的git repo的revision
不需要以tags/
开头。我不知道它改变了哪个版本的厨师,但我确认它在厨师版11.8.2
中有效。
因此revision "tags/v3.0.4"
更改为revision "v3.0.4"