fpm-fry 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  require 'fpm/fry/source'
2
+ require 'fpm/fry/exec'
2
3
  require 'fileutils'
3
4
  require 'digest'
4
5
  module FPM; module Fry ; module Source
@@ -20,11 +21,7 @@ module FPM; module Fry ; module Source
20
21
  def_delegators :package, :url, :logger, :file_map
21
22
 
22
23
  def tar_io
23
- cmd = ['tar','-c','.']
24
- logger.debug("Running tar",cmd: cmd, dir: dir)
25
- ::Dir.chdir(dir) do
26
- return IO.popen(cmd)
27
- end
24
+ Exec::popen('tar','-c','.', chdir: dir, logger: logger)
28
25
  end
29
26
 
30
27
  def copy_to(dst)
@@ -1,16 +1,41 @@
1
1
  require 'fileutils'
2
2
  require 'forwardable'
3
- require 'open3'
3
+ require 'fpm/fry/exec'
4
4
  require 'fpm/fry/source'
5
5
  module FPM; module Fry ; module Source
6
+ # Used to build directly from git.
7
+ #
8
+ # @example in a recipe
9
+ # source 'https://github.com/ggreer/the_silver_searcher.git'
10
+ #
11
+ # It automatically recognizes the following url patterns:
12
+ #
13
+ # - git://…
14
+ # - git+…://…
15
+ # - user@host:….git
16
+ # - https://….git
17
+ # - https://git.…
18
+ #
6
19
  class Git
7
20
 
8
- REGEX = %r!\A(?:git:|\S+@\S+:\S+\.git\z|https?:.*\.git\z|ssh:.*\.git\z)!
21
+ REGEX = %r!\A(?:git:|\S+@\S+:\S+\.git\z|https?:(?://git\.|.*\.git\z)|ssh:.*\.git\z|git\+[a-z0-9]+:)!
9
22
 
23
+ # @return [:git]
10
24
  def self.name
11
25
  :git
12
26
  end
13
27
 
28
+ # Guesses if this url is a git url.
29
+ #
30
+ # @example not a git url
31
+ # FPM::Fry::Source::Git.guess( "bzr://something" ) #=> nil
32
+ #
33
+ # @example a git url
34
+ # FPM::Fry::Source::Git.guess( "git://something" ) #=> 4
35
+ #
36
+ # @param [URI,String] url
37
+ # @return [nil] when this uri doesn't match
38
+ # @return [Numeric] number of characters that were used
14
39
  def self.guess( url )
15
40
  Source::guess_regex(REGEX, url)
16
41
  end
@@ -20,63 +45,63 @@ module FPM; module Fry ; module Source
20
45
 
21
46
  def_delegators :package, :url, :rev, :logger, :file_map
22
47
 
23
- def update
24
- begin
25
- if !File.exists? repodir
26
- if (ecode = git('init', '--bare')) != 0
27
- raise CacheFailed.new("Initializing git repository failed", exit_code: ecode)
28
- end
29
- end
30
- if (ecode = git('fetch','--depth=1', url.to_s, rev)) != 0
31
- raise CacheFailed.new("Failed to fetch from remote", exit_code: ecode, url: url.to_s, rev: rev)
32
- end
33
- return self
34
- rescue Errno::ENOENT
35
- raise "Cannot find git binary. Is it installed?"
36
- end
37
- end
38
-
39
48
  def tar_io
40
- cmd = [package.git, "--git-dir=#{repodir}",'archive','--format=tar','FETCH_HEAD']
41
- logger.debug("Running git",cmd: cmd)
42
- IO.popen(cmd)
49
+ Exec::popen(package.git, "--git-dir=#{repodir}",'archive','--format=tar','FETCH_HEAD', logger: logger)
43
50
  end
44
51
 
45
52
  def copy_to(dst)
46
- cmd = [package.git, "--git-dir=#{repodir}", "--work-tree=#{dst}",'checkout','FETCH_HEAD','--','*']
47
- logger.debug("Running git",cmd: cmd)
48
- system(*cmd, chdir: dst)
53
+ Exec[
54
+ package.git, "--git-dir=#{repodir}", "--work-tree=#{dst}",'checkout','FETCH_HEAD','--','*',
55
+ chdir: dst, logger: logger
56
+ ]
49
57
  end
50
58
 
51
59
  def cachekey
52
- cmd = [package.git, "--git-dir=#{repodir}",'rev-parse','FETCH_HEAD^{tree}']
53
- logger.debug("Running git",cmd: cmd)
54
- return IO.popen(cmd).read.chomp
60
+ Exec::exec(package.git, "--git-dir=#{repodir}",'rev-parse','FETCH_HEAD^{tree}', logger: logger).chomp
55
61
  end
56
62
  private
57
- def repodir
58
- File.join(tempdir,File.basename(url.path))
63
+ def initialize(*_)
64
+ super
65
+ update
59
66
  end
60
67
 
61
- def git(*args)
62
- cmd = [package.git, "--git-dir=#{repodir}",*args]
63
- logger.debug("Running git",cmd: cmd.join(' '))
64
- Open3.popen3(*cmd) do |sin, out, err, thr|
65
- sin.close
66
- out.each_line do |line|
67
- logger.debug(line.chomp)
68
- end
69
- err.each_line do |line|
70
- logger.debug(line.chomp)
68
+ def update
69
+ begin
70
+ if !File.exists? repodir
71
+ Exec::exec(package.git, "--git-dir=#{repodir}",'init', '--bare', description: "initializing git repository", logger: logger)
71
72
  end
72
- return thr.value.exitstatus
73
+ Exec::exec(package.git, "--git-dir=#{repodir}",'fetch','--depth=1', url.to_s, rev, description: 'fetching from remote', logger: logger)
74
+ return self
75
+ rescue => e
76
+ raise CacheFailed.new(e, url: url.to_s, rev: rev)
73
77
  end
74
78
  end
75
-
79
+ def repodir
80
+ File.join(tempdir,File.basename(url.path))
81
+ end
76
82
  end
77
83
 
78
- attr :logger, :git, :rev, :file_map, :url
84
+ # @return [Cabin::Channel] logger
85
+ attr :logger
86
+
87
+ # @return [String] the git binary (default: "git")
88
+ attr :git
89
+
90
+ # @return [String] the git rev to pull (default "HEAD")
91
+ attr :rev
92
+
93
+ # @return [Hash<String,String>] the file map for generating a docker file
94
+ attr :file_map
95
+
96
+ # @return [URI] the uri to pull from
97
+ attr :url
79
98
 
99
+ # @param [URI] url the url to pull from
100
+ # @param [Hash] options
101
+ # @option options [Cabin::Channel] :logger (cabin default channel)
102
+ # @option options [String] :branch git branch to pull
103
+ # @option options [String] :tag git tag to pull
104
+ # @option options [Hash<String,String>] :file_map ({""=>""}) the file map to create the docker file from
80
105
  def initialize( url, options = {} )
81
106
  url = url.sub(/\A(\S+@\S+):(\S+\.git)\z/,'ssh://\1/\2')
82
107
  @url = URI(url)
@@ -86,8 +111,10 @@ module FPM; module Fry ; module Source
86
111
  @git = options[:git] || 'git'
87
112
  end
88
113
 
114
+ # @param [String] tempdir
115
+ # @return [Cache]
89
116
  def build_cache(tempdir)
90
- Cache.new(self, tempdir).update
117
+ Cache.new(self, tempdir)
91
118
  end
92
119
 
93
120
  end
@@ -1,4 +1,5 @@
1
1
  require 'fpm/fry/tar'
2
+ require 'fpm/fry/exec'
2
3
  require 'digest'
3
4
  module FPM; module Fry ; module Source
4
5
  class Patched
@@ -40,8 +41,11 @@ module FPM; module Fry ; module Source
40
41
  package.patches.each do |patch|
41
42
  cmd = ['patch','-p1','-i',patch[:file]]
42
43
  chdir = File.expand_path(patch.fetch(:chdir,'.'),workdir)
43
- logger.debug("Running patch",cmd: cmd, dir: chdir )
44
- system(*cmd, chdir: chdir, out: :close)
44
+ begin
45
+ Fry::Exec[*cmd, chdir: chdir, logger: logger]
46
+ rescue Exec::Failed => e
47
+ raise CacheFailed.new(e, patch: patch[:file])
48
+ end
45
49
  end
46
50
  File.rename(workdir, unpacked_tmpdir)
47
51
  end
@@ -52,12 +56,7 @@ module FPM; module Fry ; module Source
52
56
 
53
57
  def tar_io
54
58
  update!
55
- cmd = ['tar','-c','.']
56
- logger.debug("Running tar",cmd: cmd, dir: unpacked_tmpdir)
57
- # IO.popen( ..., chdir: ... ) doesn't work on older ruby
58
- ::Dir.chdir(unpacked_tmpdir) do
59
- return IO.popen(cmd)
60
- end
59
+ return Exec::popen('tar','-c','.',chdir: unpacked_tmpdir, logger: logger)
61
60
  end
62
61
 
63
62
  def cachekey
@@ -76,11 +75,11 @@ module FPM; module Fry ; module Source
76
75
 
77
76
  end
78
77
 
79
- attr :inner, :patches
78
+ attr :inner, :logger, :patches
80
79
 
81
80
  extend Forwardable
82
81
 
83
- def_delegators :inner, :logger, :file_map
82
+ def_delegators :inner, :file_map
84
83
 
85
84
  def initialize( inner , options = {})
86
85
  @inner = inner
@@ -98,6 +97,11 @@ module FPM; module Fry ; module Source
98
97
  end
99
98
  options
100
99
  end
100
+ if @inner.respond_to? :logger
101
+ @logger = @inner.logger
102
+ else
103
+ @logger = Cabin::Channel.get
104
+ end
101
105
  end
102
106
 
103
107
  def build_cache(tmpdir)
@@ -16,4 +16,38 @@ module FPM ; module Fry
16
16
  return ex
17
17
  end
18
18
 
19
+ # Adds a data method to an exception. This overrides initialize so it may
20
+ # not work everywhere.
21
+ module WithData
22
+
23
+ # @return [Hash] debugging/logging data
24
+ attr :data
25
+
26
+ # @overload initialize(data = {})
27
+ # @param data [Hash]
28
+ #
29
+ # @overload initialize(cause, data = {})
30
+ # If cause responds to #data the data will be merged.
31
+ # @param cause [Exception]
32
+ # @param data [Hash]
33
+ #
34
+ # @overload initialize(message, data = {})
35
+ # @param message [String]
36
+ # @param data [Hash]
37
+ #
38
+ def initialize(e=self.class.name, data = {})
39
+ if e.kind_of? Exception
40
+ if e.respond_to? :data
41
+ @data = e.data.merge(data)
42
+ else
43
+ @data = data.dup.freeze
44
+ end
45
+ super(e.message)
46
+ else
47
+ @data = data.dup.freeze
48
+ super(e.to_s)
49
+ end
50
+ end
51
+ end
52
+
19
53
  end ; end
@@ -3,8 +3,12 @@ require 'fpm/package'
3
3
 
4
4
  require 'fpm/fry/client'
5
5
 
6
+ # An {FPM::Package} that loads files from a docker container diff.
6
7
  class FPM::Package::Docker < FPM::Package
7
8
 
9
+ # @param [Hash] options
10
+ # @option options [Cabin::Channel] :logger Logger
11
+ # @option options [FPM::Fry::Client] :client Docker client
8
12
  def initialize( options = {} )
9
13
  super()
10
14
  if options[:logger]
@@ -18,10 +22,19 @@ class FPM::Package::Docker < FPM::Package
18
22
  end
19
23
  end
20
24
 
25
+ # Loads all files from a docker container with the given name to the staging
26
+ # path.
27
+ #
28
+ # @param [String] name docker container name
21
29
  def input(name)
22
30
  split( name, '**' => staging_path)
23
31
  end
24
32
 
33
+ # Loads all files from a docker container into multiple paths defined by map
34
+ # param.
35
+ #
36
+ # @param [String] name docker container name
37
+ # @param [Hash<String,String>] map
25
38
  def split( name, map )
26
39
  changes = changes(name)
27
40
  changes.remove_modified_leaves! do | kind, ml |
@@ -44,6 +57,7 @@ class FPM::Package::Docker < FPM::Package
44
57
  directories.each do |chg|
45
58
  client.copy(name, chg, fmap ,chown: false)
46
59
  end
60
+ return nil
47
61
  end
48
62
 
49
63
  private
@@ -80,6 +94,7 @@ private
80
94
  CREATED = 1
81
95
  DELETED = 2
82
96
 
97
+ # @api private
83
98
  class Node < Struct.new(:children, :kind)
84
99
 
85
100
  def initialize
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fpm-fry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hannes Georg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-05 00:00:00.000000000 Z
11
+ date: 2016-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -70,8 +70,9 @@ files:
70
70
  - lib/fpm/fry/command/cook.rb
71
71
  - lib/fpm/fry/detector.rb
72
72
  - lib/fpm/fry/docker_file.rb
73
+ - lib/fpm/fry/exec.rb
74
+ - lib/fpm/fry/inspector.rb
73
75
  - lib/fpm/fry/joined_io.rb
74
- - lib/fpm/fry/os_db.rb
75
76
  - lib/fpm/fry/plugin.rb
76
77
  - lib/fpm/fry/plugin/alternatives.rb
77
78
  - lib/fpm/fry/plugin/config.rb
@@ -87,9 +88,9 @@ files:
87
88
  - lib/fpm/fry/recipe/builder.rb
88
89
  - lib/fpm/fry/recipe/error.rb
89
90
  - lib/fpm/fry/source.rb
91
+ - lib/fpm/fry/source/archive.rb
90
92
  - lib/fpm/fry/source/dir.rb
91
93
  - lib/fpm/fry/source/git.rb
92
- - lib/fpm/fry/source/package.rb
93
94
  - lib/fpm/fry/source/patched.rb
94
95
  - lib/fpm/fry/stream_parser.rb
95
96
  - lib/fpm/fry/tar.rb
data/lib/fpm/fry/os_db.rb DELETED
@@ -1,36 +0,0 @@
1
- module FPM; module Fry
2
-
3
- # Structure is
4
- #
5
- # <distribution> => {
6
- # codenames: {
7
- # <codename> => <version>
8
- # },
9
- # flavour: <flavour>
10
- # }
11
- OsDb = {
12
- 'centos' => {
13
- codenames: {},
14
- flavour: 'redhat'
15
- },
16
-
17
- 'debian' => {
18
- codenames: {
19
- 'lenny' => '5',
20
- 'squeeze' => '6',
21
- 'wheezy' => '7'
22
- },
23
- flavour: 'debian'
24
- },
25
-
26
- 'ubuntu' => {
27
- codenames: {
28
- 'precise' => '12.04',
29
- 'trusty' => '14.04',
30
- 'xenial' => '16.04'
31
- },
32
- flavour: 'debian'
33
- }
34
- }
35
-
36
- end ; end