Module: Dockly::History
- Defined in:
- lib/dockly/history.rb
Overview
This module contains logic to find matching content hash for a given commit.
Constant Summary collapse
- ASCII_FILE_SEP =
28.chr
- ASCII_RECORD_SEP =
30.chr
- TAG_PREFIX =
'dockly-'
Class Method Summary collapse
- .content_hash_for(paths) ⇒ Object
- .content_tag ⇒ Object
- .duplicate_build? ⇒ Boolean
- .duplicate_build_sha ⇒ Object
- .ls_files ⇒ Object
- .push_content_tag! ⇒ Object
- .repo ⇒ Object
- .tags ⇒ Object
- .write_content_tag! ⇒ Object
Class Method Details
.content_hash_for(paths) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/dockly/history.rb', line 48 def content_hash_for(paths) paths.sort.each_with_object(Digest::SHA384.new) do |path, hash| next unless File.exist?(path) mode = File::Stat.new(path).mode data = File.read(path) str = [path, mode, data].join(ASCII_RECORD_SEP.chr) + ASCII_FILE_SEP.chr hash.update(str) end.hexdigest end |
.content_tag ⇒ Object
40 41 42 |
# File 'lib/dockly/history.rb', line 40 def content_tag @content_tag ||= TAG_PREFIX + content_hash_for(ls_files) end |
.duplicate_build? ⇒ Boolean
23 24 25 |
# File 'lib/dockly/history.rb', line 23 def duplicate_build? !duplicate_build_sha.nil? end |
.duplicate_build_sha ⇒ Object
27 28 29 30 31 |
# File 'lib/dockly/history.rb', line 27 def duplicate_build_sha return @duplicate_build_sha if @duplicate_build_sha sha = [content_tag] @duplicate_build_sha = sha unless sha == repo.capturing.rev_parse('HEAD').chomp end |
.ls_files ⇒ Object
44 45 46 |
# File 'lib/dockly/history.rb', line 44 def ls_files repo.capturing.ls_tree({ :name_only => true, :r => true }, 'HEAD').split end |
.push_content_tag! ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/dockly/history.rb', line 10 def push_content_tag! fail 'An SSH agent must be running to push the tag' if ENV['SSH_AUTH_SOCK'].nil? refs = ["refs/tags/#{content_tag}"] remotes = repo.capturing.remote(:v => true).split(/\n/).map{ |r| r.split.first }.uniq remotes.each do |remote| repo.push(remote, refs) end end |
.repo ⇒ Object
58 59 60 |
# File 'lib/dockly/history.rb', line 58 def repo @repo ||= MiniGit.new('.') end |
.tags ⇒ Object
33 34 35 36 37 38 |
# File 'lib/dockly/history.rb', line 33 def @tags ||= Hash.new do |hash, key| tag = repo.capturing.show_ref({ :tags => true }, key).chomp rescue nil hash[key] = repo.capturing.rev_parse(key).chomp if tag end end |
.write_content_tag! ⇒ Object
19 20 21 |
# File 'lib/dockly/history.rb', line 19 def write_content_tag! repo.tag('-f', content_tag, repo.capturing.rev_parse('HEAD').chomp) end |