fpm-fry 0.2.2 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -7,6 +8,7 @@ module FPM; module Fry ; module Source
7
8
  extend Forwardable
8
9
 
9
10
  def_delegators :package, :logger, :file_map
11
+ def_delegators :inner, :prefix, :to
10
12
 
11
13
  attr :inner
12
14
 
@@ -17,47 +19,70 @@ module FPM; module Fry ; module Source
17
19
  end
18
20
 
19
21
  def update!
20
- @updated ||= begin
21
- if !File.directory?(unpacked_tmpdir)
22
- workdir = unpacked_tmpdir + '.tmp'
22
+ return if @updated
23
+ if !File.directory?(unpacked_tmpdir)
24
+ workdir = unpacked_tmpdir + '.tmp'
25
+ begin
26
+ FileUtils.mkdir(workdir)
27
+ rescue Errno::EEXIST
28
+ FileUtils.rm_rf(workdir)
29
+ FileUtils.mkdir(workdir)
30
+ end
31
+ if inner.respond_to? :copy_to
32
+ inner.copy_to(workdir)
33
+ else
34
+ ex = Tar::Extractor.new(logger: logger)
35
+ tio = inner.tar_io
23
36
  begin
24
- FileUtils.mkdir(workdir)
25
- rescue Errno::EEXIST
26
- FileUtils.rm_rf(workdir)
27
- FileUtils.mkdir(workdir)
37
+ ex.extract(workdir, FPM::Fry::Tar::Reader.new(tio), chown: false)
38
+ ensure
39
+ tio.close
28
40
  end
29
- if inner.respond_to? :copy_to
30
- inner.copy_to(workdir)
31
- else
32
- ex = Tar::Extractor.new(logger: logger)
33
- tio = inner.tar_io
34
- begin
35
- ex.extract(workdir, ::Gem::Package::TarReader.new(tio), chown: false)
36
- ensure
37
- tio.close
41
+ end
42
+ base = workdir
43
+ if inner.respond_to? :prefix
44
+ base = File.expand_path(inner.prefix, base)
45
+ end
46
+ package.patches.each do |patch|
47
+ cmd = ['patch','-p1','-i',patch[:file]]
48
+ chdir = base
49
+ if patch.key? :chdir
50
+ given_chdir = File.expand_path(patch[:chdir],workdir)
51
+ if given_chdir != chdir
52
+ chdir = given_chdir
53
+ else
54
+ logger.hint("You can remove the chdir: #{patch[:chdir].inspect} option for #{patch[:file]}. The given value is the default.", documentation: 'https://github.com/xing/fpm-fry/wiki/Source-patching#chdir' )
38
55
  end
39
56
  end
40
- package.patches.each do |patch|
41
- cmd = ['patch','-p1','-i',patch[:file]]
42
- chdir = File.expand_path(patch.fetch(:chdir,'.'),workdir)
43
- logger.debug("Running patch",cmd: cmd, dir: chdir )
44
- system(*cmd, chdir: chdir, out: :close)
57
+ begin
58
+ Fry::Exec[*cmd, chdir: chdir, logger: logger]
59
+ rescue Exec::Failed => e
60
+ raise CacheFailed.new(e, patch: patch[:file])
61
+ end
62
+ end
63
+ File.rename(workdir, unpacked_tmpdir)
64
+ else
65
+ #
66
+ base = unpacked_tmpdir
67
+ if inner.respond_to? :prefix
68
+ base = File.expand_path(inner.prefix, base)
69
+ end
70
+ package.patches.each do |patch|
71
+ if patch.key? :chdir
72
+ given_chdir = File.expand_path(patch[:chdir],unpacked_tmpdir)
73
+ if given_chdir == base
74
+ logger.hint("You can remove the chdir: #{patch[:chdir].inspect} option for #{patch[:file]}. The given value is the default.", documentation: 'https://github.com/xing/fpm-fry/wiki/Source-patching#chdir' )
75
+ end
45
76
  end
46
- File.rename(workdir, unpacked_tmpdir)
47
77
  end
48
- true
49
78
  end
79
+ @updated = true
50
80
  end
51
81
  private :update!
52
82
 
53
83
  def tar_io
54
84
  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
85
+ return Exec::popen('tar','-c','.',chdir: unpacked_tmpdir, logger: logger)
61
86
  end
62
87
 
63
88
  def cachekey
@@ -76,11 +101,11 @@ module FPM; module Fry ; module Source
76
101
 
77
102
  end
78
103
 
79
- attr :inner, :patches
104
+ attr :inner, :logger, :patches
80
105
 
81
106
  extend Forwardable
82
107
 
83
- def_delegators :inner, :logger, :file_map
108
+ def_delegators :inner, :file_map
84
109
 
85
110
  def initialize( inner , options = {})
86
111
  @inner = inner
@@ -98,6 +123,11 @@ module FPM; module Fry ; module Source
98
123
  end
99
124
  options
100
125
  end
126
+ if @inner.respond_to? :logger
127
+ @logger = @inner.logger
128
+ else
129
+ @logger = Cabin::Channel.get
130
+ end
101
131
  end
102
132
 
103
133
  def build_cache(tmpdir)
@@ -115,4 +145,3 @@ module FPM; module Fry ; module Source
115
145
  end
116
146
 
117
147
  end ; end ; end
118
-
@@ -1,7 +1,70 @@
1
+ require "rubygems/package"
2
+ require 'fpm/fry/channel'
3
+
1
4
  module FPM; module Fry; end ; end
2
5
 
3
6
  class FPM::Fry::Tar
4
7
 
8
+ class Reader
9
+ include Enumerable
10
+
11
+ def initialize(io)
12
+ @reader = Gem::Package::TarReader.new(io)
13
+ end
14
+
15
+ def each
16
+ return to_enum(:each) unless block_given?
17
+
18
+ last_pax_header = nil
19
+ @reader.each do |entry|
20
+ if entry.header.typeflag == 'x'
21
+ last_pax_header = extract_pax_header(entry.read)
22
+ else
23
+ if last_pax_header && (path = last_pax_header["path"])
24
+ entry.header.instance_variable_set :@name, path
25
+ last_pax_header = nil
26
+ end
27
+ yield entry
28
+ end
29
+ end
30
+ end
31
+
32
+ def map
33
+ return to_enum(:map) unless block_given?
34
+
35
+ res = []
36
+ each do |entry|
37
+ res << yield(entry)
38
+ end
39
+ res
40
+ end
41
+
42
+ private
43
+
44
+ def extract_pax_header(string)
45
+ res = {}
46
+ s = StringIO.new(string)
47
+ while !s.eof?
48
+ total_len = 0
49
+ prefix_len = 0
50
+ # read number prefix and following blank
51
+ while (c = s.getc) && (c =~ /\d/)
52
+ total_len = 10 * total_len + c.to_i
53
+ prefix_len += 1
54
+ end
55
+ field = s.read(total_len - prefix_len - 2)
56
+ if field =~ /\A([^=]+)=(.+)\z/
57
+ res[$1] = $2
58
+ else
59
+ raise "malformed pax header: #{field}"
60
+ end
61
+ s.read(1) # read trailing newline
62
+ end
63
+ res
64
+ end
65
+
66
+ end
67
+
5
68
  class Extractor
6
69
 
7
70
  def initialize( options = {} )
@@ -1,7 +1,7 @@
1
1
  #!/bin/bash
2
2
 
3
3
  case "$1" in
4
- remove)
4
+ remove|purge)
5
5
  <%= remove.join("\n") %>
6
6
  ;;
7
7
  upgrade)
@@ -1,7 +1,7 @@
1
1
  #!/bin/bash
2
2
 
3
3
  case "$1" in
4
- remove)
4
+ remove|purge)
5
5
  <%= remove.join("\n") %>
6
6
  ;;
7
7
  upgrade)
@@ -3,7 +3,7 @@ require 'fpm/fry/channel'
3
3
  module FPM; module Fry
4
4
  class UI < Struct.new(:out, :err, :logger, :tmpdir)
5
5
 
6
- def initialize( out = STDOUT, err = STDERR, logger = nil , tmpdir = '/tmp/fpm-fry' )
6
+ def initialize( out: STDOUT, err: STDERR, logger: nil , tmpdir: '/tmp/fpm-fry' )
7
7
  logger ||= Channel.new.tap{|chan| chan.subscribe(Cabin::NiceOutput.new(out)) }
8
8
  FileUtils.mkdir_p( tmpdir )
9
9
  super( out, err, logger, 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
@@ -1,10 +1,15 @@
1
1
  require 'fpm'
2
2
  require 'fpm/package'
3
+ require 'fpm/fry/channel'
3
4
 
4
5
  require 'fpm/fry/client'
5
6
 
7
+ # An {FPM::Package} that loads files from a docker container diff.
6
8
  class FPM::Package::Docker < FPM::Package
7
9
 
10
+ # @param [Hash] options
11
+ # @option options [Cabin::Channel] :logger Logger
12
+ # @option options [FPM::Fry::Client] :client Docker client
8
13
  def initialize( options = {} )
9
14
  super()
10
15
  if options[:logger]
@@ -18,10 +23,19 @@ class FPM::Package::Docker < FPM::Package
18
23
  end
19
24
  end
20
25
 
26
+ # Loads all files from a docker container with the given name to the staging
27
+ # path.
28
+ #
29
+ # @param [String] name docker container name
21
30
  def input(name)
22
31
  split( name, '**' => staging_path)
23
32
  end
24
33
 
34
+ # Loads all files from a docker container into multiple paths defined by map
35
+ # param.
36
+ #
37
+ # @param [String] name docker container name
38
+ # @param [Hash<String,String>] map
25
39
  def split( name, map )
26
40
  changes = changes(name)
27
41
  changes.remove_modified_leaves! do | kind, ml |
@@ -44,6 +58,7 @@ class FPM::Package::Docker < FPM::Package
44
58
  directories.each do |chg|
45
59
  client.copy(name, chg, fmap ,chown: false)
46
60
  end
61
+ return nil
47
62
  end
48
63
 
49
64
  private
@@ -80,6 +95,7 @@ private
80
95
  CREATED = 1
81
96
  DELETED = 2
82
97
 
98
+ # @api private
83
99
  class Node < Struct.new(:children, :kind)
84
100
 
85
101
  def initialize
metadata CHANGED
@@ -1,14 +1,18 @@
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.4.6
5
5
  platform: ruby
6
6
  authors:
7
+ - Maxime Lagresle
8
+ - Stefan Kaes
9
+ - Sebastian Brandt
7
10
  - Hannes Georg
11
+ - Julian Tabel
8
12
  autorequire:
9
13
  bindir: bin
10
14
  cert_chain: []
11
- date: 2016-09-05 00:00:00.000000000 Z
15
+ date: 2021-01-04 00:00:00.000000000 Z
12
16
  dependencies:
13
17
  - !ruby/object:Gem::Dependency
14
18
  name: excon
@@ -16,14 +20,14 @@ dependencies:
16
20
  requirements:
17
21
  - - "~>"
18
22
  - !ruby/object:Gem::Version
19
- version: '0.30'
23
+ version: 0.71.0
20
24
  type: :runtime
21
25
  prerelease: false
22
26
  version_requirements: !ruby/object:Gem::Requirement
23
27
  requirements:
24
28
  - - "~>"
25
29
  - !ruby/object:Gem::Version
26
- version: '0.30'
30
+ version: 0.71.0
27
31
  - !ruby/object:Gem::Dependency
28
32
  name: fpm
29
33
  requirement: !ruby/object:Gem::Requirement
@@ -39,21 +43,83 @@ dependencies:
39
43
  - !ruby/object:Gem::Version
40
44
  version: '1.0'
41
45
  - !ruby/object:Gem::Dependency
42
- name: json
46
+ name: rake
43
47
  requirement: !ruby/object:Gem::Requirement
44
48
  requirements:
45
49
  - - "~>"
46
50
  - !ruby/object:Gem::Version
47
- version: '1.8'
48
- type: :runtime
51
+ version: '12.0'
52
+ type: :development
53
+ prerelease: false
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - "~>"
57
+ - !ruby/object:Gem::Version
58
+ version: '12.0'
59
+ - !ruby/object:Gem::Dependency
60
+ name: rspec
61
+ requirement: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 3.0.0
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ - - "~>"
77
+ - !ruby/object:Gem::Version
78
+ version: '3.0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: webmock
81
+ requirement: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '3.0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - "~>"
91
+ - !ruby/object:Gem::Version
92
+ version: '3.0'
93
+ - !ruby/object:Gem::Dependency
94
+ name: coveralls
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ - !ruby/object:Gem::Dependency
108
+ name: simplecov
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ type: :development
49
115
  prerelease: false
50
116
  version_requirements: !ruby/object:Gem::Requirement
51
117
  requirements:
52
118
  - - "~>"
53
119
  - !ruby/object:Gem::Version
54
- version: '1.8'
120
+ version: '0'
55
121
  description: deep-fried package builder
56
- email: hannes.georg@xing.com
122
+ email: maxime.lagresle@xing.com
57
123
  executables:
58
124
  - fpm-fry
59
125
  extensions: []
@@ -70,26 +136,30 @@ files:
70
136
  - lib/fpm/fry/command/cook.rb
71
137
  - lib/fpm/fry/detector.rb
72
138
  - lib/fpm/fry/docker_file.rb
139
+ - lib/fpm/fry/exec.rb
140
+ - lib/fpm/fry/inspector.rb
73
141
  - lib/fpm/fry/joined_io.rb
74
- - lib/fpm/fry/os_db.rb
75
142
  - lib/fpm/fry/plugin.rb
76
143
  - lib/fpm/fry/plugin/alternatives.rb
144
+ - lib/fpm/fry/plugin/apt.rb
77
145
  - lib/fpm/fry/plugin/config.rb
78
146
  - lib/fpm/fry/plugin/edit_staging.rb
147
+ - lib/fpm/fry/plugin/env.rb
79
148
  - lib/fpm/fry/plugin/exclude.rb
80
149
  - lib/fpm/fry/plugin/init.rb
81
150
  - lib/fpm/fry/plugin/platforms.rb
82
151
  - lib/fpm/fry/plugin/same_version.rb
83
152
  - lib/fpm/fry/plugin/script_helper.rb
84
153
  - lib/fpm/fry/plugin/service.rb
154
+ - lib/fpm/fry/plugin/systemd.rb
85
155
  - lib/fpm/fry/plugin/user.rb
86
156
  - lib/fpm/fry/recipe.rb
87
157
  - lib/fpm/fry/recipe/builder.rb
88
158
  - lib/fpm/fry/recipe/error.rb
89
159
  - lib/fpm/fry/source.rb
160
+ - lib/fpm/fry/source/archive.rb
90
161
  - lib/fpm/fry/source/dir.rb
91
162
  - lib/fpm/fry/source/git.rb
92
- - lib/fpm/fry/source/package.rb
93
163
  - lib/fpm/fry/source/patched.rb
94
164
  - lib/fpm/fry/stream_parser.rb
95
165
  - lib/fpm/fry/tar.rb
@@ -126,8 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
196
  - !ruby/object:Gem::Version
127
197
  version: '0'
128
198
  requirements: []
129
- rubyforge_project:
130
- rubygems_version: 2.5.1
199
+ rubygems_version: 3.0.3
131
200
  signing_key:
132
201
  specification_version: 4
133
202
  summary: FPM Fry