Module: Kitchen::Yansible::Tools::Dependencies

Included in:
Provisioner::Yansible
Defined in:
lib/kitchen-yansible/tools/dependencies.rb

Instance Method Summary collapse

Instance Method Details

#git_clone(name, url, path) ⇒ Object



27
28
29
30
# File 'lib/kitchen-yansible/tools/dependencies.rb', line 27

def git_clone(name, url, path)
  info("Cloning '#{name}' Git repository.")
  Rugged::Repository.clone_at(url, path, { :ignore_cert_errors => true })
end

#prepare_dependencies(dependencies) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/kitchen-yansible/tools/dependencies.rb', line 32

def prepare_dependencies(dependencies)
  dependencies.each do |dependency|
    info("Processing '#{dependency[:name]}' dependency.")
    dependency_target_path = File.join(dependencies_tmp_dir, dependency[:name])
    if dependency.key?(:path)
      info('Processing as path type.')
      if File.exist?(dependency[:path])
        copy_dirs(dependency[:path], dependency_target_path)
      else
        warn("Dependency path '#{dependency[:path]}' doesn't exists. Omitting copy operation.")
      end
    end
    if dependency.key?(:repo)
      if dependency[:repo].downcase == 'git'
        info('Processing as Git repository.')
        begin
          repo = Rugged::Repository.new(dependency_target_path)
          if repo.remotes.first.url.eql?(dependency[:url])
            warn("Dependency cloned already.")
          else
            warn("Removing directory #{dependency_target_path} due to repository origin difference.")
            FileUtils.remove_entry_secure(dependency_target_path)
            git_clone(dependency[:name], dependency[:url], dependency_target_path)
          end
        rescue
          if File.exist?(dependency_target_path)
            warn("Dependency path '#{dependency_target_path}' is not a valid Git repository. Removing then.")
            FileUtils.remove_entry_secure(dependency_target_path)
          end
          repo = git_clone(dependency[:name], dependency[:url], dependency_target_path)
        end

        raw_ref = dependency.key?(:ref) ? dependency[:ref] : 'master'
        begin
          repo.rev_parse(raw_ref)
        rescue
          message = unindent(<<-MSG)

            ===============================================================================
             Invalid Git reference - #{raw_ref}
             Please check '#{dependency[:name]}' dependency configuration.
            ===============================================================================
          MSG
          raise UserError, message
        end

        info("Resetting '#{dependency[:name]}' repository to '#{raw_ref}' reference.")
        repo.checkout(raw_ref, {:strategy => :force})
        repo.close
      else
        raise UserError, "Working with '#{dependency[:repo]}' repository is not implemented yet."
      end
    end
  end unless dependencies.nil?
end