fpm-fry 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9052cdc66f349423b938cefae76a81ddf5504c65
4
- data.tar.gz: 6084e244c0f01eb10f0c4ec2dbd6f18f1831ddd4
3
+ metadata.gz: 30f03302993885946a899feba8c6f6a63f9cc46a
4
+ data.tar.gz: 6cf9d78c60aca34c1c8feab1b58ddd9234fe28b9
5
5
  SHA512:
6
- metadata.gz: 3667766c65cb233def8e06ae14029bea06ebae06f03a8f9b5a4c45ae9d851557dcef27a510c8a361d8099b8a50f1ebb632182598192c27ae5355f1c908611ec0
7
- data.tar.gz: 81c95585118d529c4438b09aff3c96b3044b60a8b181d65bb6611635dc5fed9d672083796b13afb3fe6b4e38acdf81b1f9b54fbf3ade555b68237b12cc74d132
6
+ metadata.gz: d832baed68a8f809a009bcdb7d8addb4847393475f1bc4ae12d5a562210ddbc3506f1e6e310d4798b68197b75a649152ea05449ce2ef18ad4e34f321094efb9d
7
+ data.tar.gz: ca77a79b3aad02271b8dd9cf4e9c31d556c7125065ea7b1df0917d3677a433b64b8a32a7bd90e3a527a5f7016533dcd766393472cf5c30cb8b4d99e16fb6107f
data/bin/fpm-fry CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "rubygems"
4
4
  $: << File.expand_path(File.join( "..", "lib"),File.dirname(__FILE__))
5
+ require "json"
5
6
  require "fpm"
6
7
  require "fpm/command"
7
8
  require "fpm/package/docker"
@@ -35,6 +35,14 @@ class Cabin::NiceOutput
35
35
 
36
36
  def <<(event)
37
37
  data = event.clone
38
+ if data[:exception].respond_to? :data
39
+ ed = data[:exception].data
40
+ if ed.kind_of? Hash
41
+ data = ed.merge( data )
42
+ else
43
+ data[:exception_data] = ed.inspect
44
+ end
45
+ end
38
46
  data.delete(:line)
39
47
  data.delete(:file)
40
48
  level = data.delete(:level) || :normal
@@ -70,12 +70,11 @@ class FPM::Fry::Client
70
70
 
71
71
  def read(name, resource)
72
72
  return to_enum(:read, name, resource) unless block_given?
73
- body = JSON.generate({'Resource' => resource})
74
- res = agent.post(
75
- path: url('containers',name,'copy'),
73
+ res = agent.get(
74
+ path: url('containers',name,'archive'),
75
+ query: URI.encode_www_form('path' => resource),
76
76
  headers: { 'Content-Type' => 'application/json' },
77
- body: body,
78
- expects: [200,500]
77
+ expects: [200,404,500]
79
78
  )
80
79
  if res.status == 500
81
80
  raise FileNotFound, "File #{resource.inspect} not found: #{res.body}"
@@ -237,7 +237,7 @@ module FPM; module Fry
237
237
  )
238
238
  json = JSON.parse(res.body)
239
239
  if json["StatusCode"] != 0
240
- raise "Build failed with exit code #{json["StatusCode"]}"
240
+ raise Fry::WithData("Build failed", exit_code: json["StatusCode"])
241
241
  end
242
242
  return yield container
243
243
  ensure
@@ -90,6 +90,15 @@ module FPM; module Fry
90
90
  df << "FROM #{base}"
91
91
  df << "WORKDIR /tmp/build"
92
92
 
93
+ # need to add external sources before running any command
94
+ recipe.build_mounts.each do |source, target|
95
+ df << "ADD #{source} /tmp/build/#{target}"
96
+ end
97
+
98
+ recipe.apt_setup.each do |step|
99
+ df << "RUN #{step}"
100
+ end
101
+
93
102
  if build_dependencies.any?
94
103
  case(variables[:flavour])
95
104
  when 'debian'
@@ -137,6 +146,11 @@ module FPM; module Fry
137
146
  tar.add_file(NAME,'0777') do |io|
138
147
  io.write(dockerfile)
139
148
  end
149
+ recipe.build_mounts.each do |source, _|
150
+ tar.add_file(source,'0777') do |io|
151
+ io.write(File.read(source))
152
+ end
153
+ end
140
154
  #tar.close
141
155
  sio.rewind
142
156
  return sio
data/lib/fpm/fry/os_db.rb CHANGED
@@ -26,7 +26,8 @@ module FPM; module Fry
26
26
  'ubuntu' => {
27
27
  codenames: {
28
28
  'precise' => '12.04',
29
- 'trusty' => '14.04'
29
+ 'trusty' => '14.04',
30
+ 'xenial' => '16.04'
30
31
  },
31
32
  flavour: 'debian'
32
33
  }
@@ -94,7 +94,8 @@ module FPM::Fry::Plugin::ScriptHelper
94
94
 
95
95
  class AfterRemove < Script
96
96
 
97
- def initialize
97
+ def initialize(*_)
98
+ super
98
99
  @remove = []
99
100
  @upgrade = []
100
101
  end
@@ -129,7 +129,20 @@ BASH
129
129
  co.include "etc/init.d/#{name}"
130
130
  end
131
131
  when 'systemd' then
132
+ edit.add_file "/lib/systemd/system/#{name}.service", StringIO.new( env.render('systemd.erb') ), chmod: '644'
133
+ builder.plugin('script_helper') do |sh|
134
+ sh.after_install_or_upgrade(<<BASH)
135
+ systemctl preset #{Shellwords.shellescape name}.service
136
+ if systemctl is-enabled --quiet #{Shellwords.shellescape name}.service ; then
137
+ systemctl --system daemon-reload
138
+ systemctl try-reload-or-restart #{Shellwords.shellescape name}.service
139
+ fi
140
+ BASH
141
+ sh.before_remove_entirely(<<BASH)
142
+ systemctl disable --now #{Shellwords.shellescape name}.service
143
+ BASH
132
144
 
145
+ end
133
146
  end
134
147
  end
135
148
 
@@ -213,6 +213,14 @@ module FPM::Fry
213
213
  recipe.source = source
214
214
  end
215
215
 
216
+ def add(source, target)
217
+ recipe.build_mounts << [source, target]
218
+ end
219
+
220
+ def apt_setup(cmd)
221
+ recipe.apt_setup << cmd
222
+ end
223
+
216
224
  def run(*args)
217
225
  if args.first.kind_of? Hash
218
226
  options = args.shift
@@ -125,6 +125,8 @@ module FPM; module Fry
125
125
  end
126
126
 
127
127
  attr_accessor :source,
128
+ :build_mounts,
129
+ :apt_setup,
128
130
  :before_build_steps,
129
131
  :steps,
130
132
  :packages,
@@ -139,6 +141,8 @@ module FPM; module Fry
139
141
  @packages[0].files << '**'
140
142
  @build_depends = {}
141
143
  @input_hooks = []
144
+ @build_mounts = []
145
+ @apt_setup = []
142
146
  end
143
147
 
144
148
  def depends
@@ -23,12 +23,12 @@ module FPM; module Fry ; module Source
23
23
  def update
24
24
  begin
25
25
  if !File.exists? repodir
26
- if git('init', '--bare') != 0
27
- raise "Initializing git repository failed"
26
+ if (ecode = git('init', '--bare')) != 0
27
+ raise CacheFailed.new("Initializing git repository failed", exit_code: ecode)
28
28
  end
29
29
  end
30
- if git('fetch','--depth=1', url.to_s, rev) != 0
31
- raise "Failed to fetch from remote #{url.to_s} ( #{rev} )"
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
32
  end
33
33
  return self
34
34
  rescue Errno::ENOENT
@@ -69,7 +69,7 @@ module FPM; module Fry ; module Source
69
69
  err.each_line do |line|
70
70
  logger.debug(line.chomp)
71
71
  end
72
- return thr.value
72
+ return thr.value.exitstatus
73
73
  end
74
74
  end
75
75
 
@@ -4,6 +4,7 @@ require 'net/http'
4
4
  require 'forwardable'
5
5
  require 'zlib'
6
6
  require 'fpm/fry/source'
7
+ require 'cabin'
7
8
  module FPM; module Fry ; module Source
8
9
  class Package
9
10
 
@@ -29,6 +30,12 @@ module FPM; module Fry ; module Source
29
30
 
30
31
  def_delegators :package, :url, :checksum, :checksum_algorithm, :agent, :logger, :file_map
31
32
 
33
+ def cachekey
34
+ @observed_checksum || checksum
35
+ end
36
+
37
+ private
38
+
32
39
  def initialize(*_)
33
40
  super
34
41
  if !checksum
@@ -52,7 +59,9 @@ module FPM; module Fry ; module Source
52
59
  end
53
60
  d = checksum_algorithm.new
54
61
  f = nil
55
- fetch_url(url) do |resp|
62
+ actual_url = url.to_s
63
+ fetch_url(url) do | last_url, resp|
64
+ actual_url = last_url.to_s
56
65
  begin
57
66
  f = File.new(tempfile,'w')
58
67
  resp.read_body do | chunk |
@@ -67,10 +76,10 @@ module FPM; module Fry ; module Source
67
76
  end
68
77
 
69
78
  @observed_checksum = d.hexdigest
70
- logger.debug("got checksum", checksum: @observed_checksum)
79
+ logger.debug("Got checksum", checksum: @observed_checksum, url: actual_url)
71
80
  if checksum
72
81
  if d.hexdigest != checksum
73
- raise CacheFailed.new("Checksum failed",given: d.hexdigest, expected: checksum)
82
+ raise CacheFailed.new("Checksum failed",given: d.hexdigest, expected: checksum, url: actual_url)
74
83
  end
75
84
  else
76
85
  return true
@@ -88,9 +97,9 @@ module FPM; module Fry ; module Source
88
97
  logger.debug("Following redirect", url: url.to_s , location: resp['location'])
89
98
  return fetch_url( resp['location'], redirs - 1, &block)
90
99
  when Net::HTTPSuccess
91
- return block.call(resp)
100
+ return block.call( url, resp)
92
101
  else
93
- raise CacheFailed.new('Unable to fetch file',url: url.to_s, http_code: resp.code, http_message: resp.message)
102
+ raise CacheFailed.new('Unable to fetch file',url: url.to_s, http_code: resp.code.to_i, http_message: resp.message)
94
103
  end
95
104
  end
96
105
  end
@@ -99,10 +108,6 @@ module FPM; module Fry ; module Source
99
108
  File.join(tempdir,File.basename(url.path))
100
109
  end
101
110
 
102
- def cachekey
103
- @observed_checksum || checksum
104
- end
105
-
106
111
  end
107
112
 
108
113
  class TarCache < Cache
@@ -133,6 +138,17 @@ module FPM; module Fry ; module Source
133
138
  end
134
139
  end
135
140
 
141
+ class TarBz2Cache < TarCache
142
+
143
+ def tar_io
144
+ update!
145
+ cmd = ['bzcat',tempfile]
146
+ logger.debug("Running bzcat",cmd: cmd)
147
+ return IO.popen(cmd)
148
+ end
149
+
150
+ end
151
+
136
152
  class ZipCache < Cache
137
153
 
138
154
  def tar_io
@@ -189,6 +205,7 @@ module FPM; module Fry ; module Source
189
205
  '.tar' => TarCache,
190
206
  '.tar.gz' => TarGzCache,
191
207
  '.tgz' => TarGzCache,
208
+ '.tar.bz2' => TarBz2Cache,
192
209
  '.zip' => ZipCache,
193
210
  '.bin' => PlainCache,
194
211
  '.bundle' => PlainCache
@@ -2,14 +2,14 @@ module FPM; module Fry ; module Source
2
2
 
3
3
  class CacheFailed < StandardError
4
4
 
5
- attr :options
5
+ attr :data
6
6
 
7
- def initialize(e, opts = {})
7
+ def initialize(e, data = {})
8
8
  if e.kind_of? Exception
9
- @options = {reason: e}.merge opts
9
+ @data = {reason: e}.merge data
10
10
  super(e.message)
11
11
  else
12
- @options = opts.dup
12
+ @data = data.dup
13
13
  super(e.to_s)
14
14
  end
15
15
  end
@@ -0,0 +1,13 @@
1
+ #!/bin/bash
2
+
3
+ case "$1" in
4
+ remove)
5
+ <%= remove.join("\n") %>
6
+ ;;
7
+ upgrade)
8
+ <%= upgrade.join("\n") %>
9
+ ;;
10
+ *)
11
+ exit 1
12
+ ;;
13
+ esac
@@ -0,0 +1,6 @@
1
+ #!/bin/bash
2
+ if [[ $1 -eq 0 ]] ; then
3
+ <%= remove.join("\n") %>
4
+ elif [[ $1 -ge 1 ]] ; then
5
+ <%= upgrade.join("\n") %>
6
+ fi
@@ -0,0 +1,19 @@
1
+ [Unit]
2
+ Description=<%= description %>
3
+
4
+ [Service]
5
+ Type=simple
6
+ ExecStart=<%= Shellwords.shelljoin(command) %>
7
+ Restart=on-failure
8
+ <% if user %>User=<%= user %>
9
+ <% end -%>
10
+ <% if group %>Group=<%= group %>
11
+ <% end -%>
12
+ <% if chdir %>WorkingDirectory=<%= chdir %>
13
+ <% end -%>
14
+ <% limits.each do | name, (soft, hard) | -%>
15
+ Limit<%= name.upcase %>=<%= soft %>:<%= hard %>
16
+ <% end -%>
17
+
18
+ [Install]
19
+ WantedBy=multi-user.target
@@ -1,6 +1,17 @@
1
1
  module FPM ; module Fry
2
2
 
3
+ # Annotates an arbitrary exception with logable data.
4
+ #
5
+ # @example
6
+ # raise FPM::Fry::WithData("Something went wrong", key: "value")
7
+ # @param [String,Exception] ex
8
+ # @param [Hash] data
9
+ # @return [Exception] annotated exception
10
+ #
3
11
  def self.WithData(ex, data)
12
+ if ex.kind_of? String
13
+ ex = StandardError.new(ex)
14
+ end
4
15
  ex.define_singleton_method(:data){ data }
5
16
  return ex
6
17
  end
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.1
4
+ version: 0.2.2
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-04-18 00:00:00.000000000 Z
11
+ date: 2016-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
41
55
  description: deep-fried package builder
42
56
  email: hannes.georg@xing.com
43
57
  executables:
@@ -80,11 +94,14 @@ files:
80
94
  - lib/fpm/fry/stream_parser.rb
81
95
  - lib/fpm/fry/tar.rb
82
96
  - lib/fpm/fry/templates/debian/after_install.erb
97
+ - lib/fpm/fry/templates/debian/after_remove.erb
83
98
  - lib/fpm/fry/templates/debian/before_install.erb
84
99
  - lib/fpm/fry/templates/debian/before_remove.erb
85
100
  - lib/fpm/fry/templates/redhat/after_install.erb
101
+ - lib/fpm/fry/templates/redhat/after_remove.erb
86
102
  - lib/fpm/fry/templates/redhat/before_install.erb
87
103
  - lib/fpm/fry/templates/redhat/before_remove.erb
104
+ - lib/fpm/fry/templates/systemd.erb
88
105
  - lib/fpm/fry/templates/sysv.erb
89
106
  - lib/fpm/fry/templates/upstart.erb
90
107
  - lib/fpm/fry/ui.rb