Class: FPM::Fry::Source::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/fpm/fry/source/git.rb

Overview

Used to build directly from git.

It automatically recognizes the following url patterns:

- git://…
- git+…://…
- user@host:….git
- https://….git
- https://git.…

Examples:

in a recipe

source 'https://github.com/ggreer/the_silver_searcher.git'

Defined Under Namespace

Classes: Cache

Constant Summary collapse

REGEX =
%r!\A(?:git:|\S+@\S+:\S+\.git\z|https?:(?://git\.|.*\.git\z)|ssh:.*\.git\z|git\+[a-z0-9]+:)!

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Git

Returns a new instance of Git.

Parameters:

  • url (URI)

    the url to pull from

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :logger (Cabin::Channel) — default: cabin default channel
  • :branch (String)

    git branch to pull

  • :tag (String)

    git tag to pull

  • :file_map (Hash<String,String>) — default: {""=>""}

    the file map to create the docker file from



113
114
115
116
117
118
119
120
121
# File 'lib/fpm/fry/source/git.rb', line 113

def initialize( url, options = {} )
  url = url.sub(/\A(\S+@\S+):(\S+\.git)\z/,'ssh://\1/\2')
  @url = URI(url)
  @logger = options.fetch(:logger){ Cabin::Channel.get }
  @rev = options[:branch] || options[:tag] || options[:rev] || 'HEAD'
  @file_map = options[:file_map]
  @git = options[:git] || 'git'
  @to = options[:to]
end

Instance Attribute Details

#file_mapHash<String,String>? (readonly)

Returns the file map for generating a docker file.

Returns:

  • (Hash<String,String>, nil)

    the file map for generating a docker file



99
100
101
# File 'lib/fpm/fry/source/git.rb', line 99

def file_map
  @file_map
end

#gitString (readonly)

Returns the git binary (default: “git”).

Returns:

  • (String)

    the git binary (default: “git”)



93
94
95
# File 'lib/fpm/fry/source/git.rb', line 93

def git
  @git
end

#loggerCabin::Channel (readonly)

Returns logger.

Returns:

  • (Cabin::Channel)

    logger



90
91
92
# File 'lib/fpm/fry/source/git.rb', line 90

def logger
  @logger
end

#revString (readonly)

Returns the git rev to pull (default “HEAD”).

Returns:

  • (String)

    the git rev to pull (default “HEAD”)



96
97
98
# File 'lib/fpm/fry/source/git.rb', line 96

def rev
  @rev
end

#toString? (readonly)

Returns:

  • (String, nil)


105
106
107
# File 'lib/fpm/fry/source/git.rb', line 105

def to
  @to
end

#urlURI (readonly)

Returns the uri to pull from.

Returns:

  • (URI)

    the uri to pull from



102
103
104
# File 'lib/fpm/fry/source/git.rb', line 102

def url
  @url
end

Class Method Details

.guess(url) ⇒ nil, Numeric

Guesses if this url is a git url.

Examples:

not a git url

FPM::Fry::Source::Git.guess( "bzr://something" ) #=> nil

a git url

FPM::Fry::Source::Git.guess( "git://something" ) #=> 4

Parameters:

  • url (URI, String)

Returns:

  • (nil)

    when this uri doesn’t match

  • (Numeric)

    number of characters that were used



39
40
41
# File 'lib/fpm/fry/source/git.rb', line 39

def self.guess( url )
  Source::guess_regex(REGEX, url)
end

.name:git

Returns:

  • (:git)


24
25
26
# File 'lib/fpm/fry/source/git.rb', line 24

def self.name
  :git
end

Instance Method Details

#build_cache(tempdir) ⇒ Cache

Parameters:

  • tempdir (String)

Returns:



125
126
127
# File 'lib/fpm/fry/source/git.rb', line 125

def build_cache(tempdir)
  Cache.new(self, tempdir)
end