slugbuilder 2.0.2 → 3.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 367b7b519e31d8a09a34a4a5be8d0d7fcc7f84d4
4
- data.tar.gz: 76ebf745bb4ac19173043db02eb11eac64c51b8b
3
+ metadata.gz: 323e6ddccbd05d566ad68ebaeee4454c844e2619
4
+ data.tar.gz: 7dbbed35c573e65f0ea3acb87fc9501ac2f88295
5
5
  SHA512:
6
- metadata.gz: 8121ef7398200674364e88db19bb757c5a3c2012b4f4202f3af102e858b55e1f69770af91a963b36c386ef4438e077eb6a124a8a5caa8a88a74d4122bb207339
7
- data.tar.gz: 7697a17820a6305ff5d3671cd3e1072238b976873ac7a0baf41d2ecf139c0ee9531f118ea574b383db869645af6cdfce4c3ba05e6be6d72b230f1134de991434
6
+ metadata.gz: 31864f4e69cd18c296a93ddff917c10cd545cc06baa4a7271bc8a070e56f0560bcd3ddc2bc2dd050a20137c47da49bfb389ea4345ec1fcfa8b84612d59a36e18
7
+ data.tar.gz: d80c8a58653ef8e26e059eb7ce81950ae532500439bb3887fce9e5488557594efdad22e40c8a9a4df24608dd14d2a329fbadd503210d19a1add80575cca45ca5
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.0.0 (2017-7-12)
4
+
5
+ Changed:
6
+
7
+ - Allow configuration of `STACK` environment variable. Now defaults to `heroku-16` instead of `cedar-14`. This is a potentially breaking change. [4ce8c61](../../commit/4ce8c61)
8
+
9
+ Added:
10
+
11
+ - Improved error messaging from buildpacks. Rather than showing the stack trace from slugbuilder, show the data piped to stderr where the error occurred. [dbf5142](../../commit/dbf5142)
12
+
3
13
  ## 2.0.2 (2017-5-26)
4
14
 
5
15
  Fixed:
data/README.md CHANGED
@@ -151,6 +151,7 @@ Slugbuilder.config.output_dir = './slugs'
151
151
  'git@github.com:heroku/heroku-buildpack-nodejs.git',
152
152
  'https://github.com/heroku/heroku-buildpack-ruby.git#37ed188'
153
153
  ]
154
+ @heroku_stack = 'heroku-16'
154
155
  ```
155
156
 
156
157
  **base_dir**
@@ -189,6 +190,12 @@ Buildpacks is an array of valid git clone-able [buildpack](https://devcenter.her
189
190
 
190
191
  > Defaults to []
191
192
 
193
+ **heroku_stack**
194
+
195
+ This is a string configuration option that may affect how certain buildpacks run. It is set as the `$STACK` environment variable. See [Heroku's documentation](https://devcenter.heroku.com/articles/stack) for more information about where this comes from. eg: 'heroku-16', 'cedar-14'
196
+
197
+ > Defaults to 'heroku-16'
198
+
192
199
  ## Development
193
200
 
194
201
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -2,6 +2,7 @@ require 'securerandom'
2
2
  require 'shellwords'
3
3
  require 'yaml'
4
4
  require 'fileutils'
5
+ require 'open3'
5
6
 
6
7
  module Slugbuilder
7
8
  class Builder
@@ -33,7 +34,7 @@ module Slugbuilder
33
34
  FileUtils.mkdir_p(@env_dir)
34
35
 
35
36
  @buildpacks = buildpacks
36
- @env = env
37
+ @env = env.map { |k, v| [k.to_s, v.to_s] }.to_h
37
38
  @slug_file = slug_name ? "#{slug_name}.tgz" : Shellwords.escape("#{@repo.gsub('/', '.')}.#{@git_ref}.#{@git_sha}.tgz")
38
39
  wipe_cache if clear_cache
39
40
 
@@ -61,7 +62,7 @@ module Slugbuilder
61
62
  end
62
63
  return true
63
64
  rescue => e
64
- stitle("Failed: #{e}\n#{e.backtrace.join("\n")}")
65
+ stitle("Failed: #{e}\n")
65
66
  return false
66
67
  ensure
67
68
  restore_env
@@ -120,7 +121,7 @@ module Slugbuilder
120
121
  def set_environment
121
122
  load_env_file("#{@cache_dir}/env")
122
123
  load_env_file("#{@build_dir}/.env")
123
- ENV['STACK'] = 'cedar-14'
124
+ ENV['STACK'] = Slugbuilder.config.heroku_stack
124
125
  @request_id = SecureRandom.urlsafe_base64(32)
125
126
  ENV['REQUEST_ID'] = @request_id
126
127
  ENV['SOURCE_VERSION'] = @git_sha
@@ -132,7 +133,7 @@ module Slugbuilder
132
133
  ENV['APP_DIR'] = @build_dir
133
134
 
134
135
  stitle('Build environment')
135
- ENV.each do |k, v|
136
+ ENV.to_h.merge(@env).each do |k, v|
136
137
  stext("#{k}=#{v}")
137
138
  end
138
139
  end
@@ -212,8 +213,8 @@ module Slugbuilder
212
213
  Dir.chdir(@build_dir) do
213
214
  script = "#{@build_dir}/bin/#{hook_name}"
214
215
  if File.exists?(script)
215
- rc = run(script)
216
- fail "Failed to run #{script}" if rc != 0
216
+ rc, errs = run_echo(script)
217
+ fail "#{errs.join('\n')}\nFailed to run #{script}" if rc != 0
217
218
  end
218
219
  end
219
220
  end
@@ -237,8 +238,8 @@ module Slugbuilder
237
238
  end
238
239
 
239
240
  def compile(buildpack)
240
- rc = run_echo("#{buildpack}/bin/compile '#{@build_dir}' '#{@cache_dir}' '#{@env_dir}'")
241
- fail "Couldn't compile application using buildpack #{buildpack}" if rc != 0
241
+ rc, errs = run_echo("#{buildpack}/bin/compile '#{@build_dir}' '#{@cache_dir}' '#{@env_dir}'")
242
+ fail "#{errs.join('\n')}\nCouldn't compile application using buildpack #{buildpack}" if rc != 0
242
243
  end
243
244
 
244
245
  def release(buildpack)
@@ -254,14 +255,15 @@ module Slugbuilder
254
255
 
255
256
  def build_slug
256
257
  rc = 1
258
+ errs = []
257
259
  # use pigz if available
258
260
  compression = `which pigz` != '' ? '--use-compress-program=pigz' : ''
259
261
  if File.exists?("#{@build_dir}/.slugignore")
260
- rc = run_echo("tar --exclude='.git' #{compression} -X #{@build_dir}/.slugignore -C #{@build_dir} -cf #{File.join(@output_dir, @slug_file)} .")
262
+ rc, errs = run_echo("tar --exclude='.git' #{compression} -X #{@build_dir}/.slugignore -C #{@build_dir} -cf #{File.join(@output_dir, @slug_file)} .")
261
263
  else
262
- rc = run_echo("tar --exclude='.git' #{compression} -C #{@build_dir} -cf #{File.join(@output_dir, @slug_file)} .")
264
+ rc, errs = run_echo("tar --exclude='.git' #{compression} -C #{@build_dir} -cf #{File.join(@output_dir, @slug_file)} .")
263
265
  end
264
- fail "Couldn't create slugfile" if rc != 0
266
+ fail "#{errs.join('\n')}\nCouldn't create slugfile" if rc != 0
265
267
  end
266
268
 
267
269
  def slug_size
@@ -329,20 +331,24 @@ module Slugbuilder
329
331
  end
330
332
 
331
333
  def run(cmd)
332
- IO.popen(cmd) do |io|
333
- until io.eof?
334
- data = io.gets
335
- yield data if block_given?
334
+ Open3.popen3(cmd) do |stdin, stdout, stderr, thread|
335
+ until stdout.eof? && stderr.eof?
336
+ out = stdout.gets
337
+ err = stderr.gets
338
+ yield(out, err) if block_given?
336
339
  end
340
+ thread.value.exitstatus
337
341
  end
338
- $?.exitstatus
339
342
  end
340
343
 
341
344
  def run_echo(cmd)
342
- run(cmd) do |line|
343
- build_output << line
344
- @stdout.print(line)
345
+ errors = []
346
+ status = run(cmd) do |stdout, stderr|
347
+ build_output << stdout if stdout
348
+ errors << stderr if stderr
349
+ @stdout.print(stdout)
345
350
  end
351
+ [status, errors]
346
352
  end
347
353
 
348
354
  def load_export_env(file)
@@ -17,7 +17,7 @@ module Slugbuilder
17
17
 
18
18
  class Configuration
19
19
  attr_accessor :base_dir, :cache_dir, :output_dir,
20
- :git_service, :buildpacks, :protocol
20
+ :git_service, :buildpacks, :protocol, :heroku_stack
21
21
 
22
22
  def initialize
23
23
  @base_dir = '/tmp/slugbuilder'
@@ -26,6 +26,7 @@ module Slugbuilder
26
26
  @git_service = 'github.com'
27
27
  @protocol = 'https'
28
28
  @buildpacks = []
29
+ @heroku_stack = 'heroku-16'
29
30
  end
30
31
  end
31
32
  end
@@ -1,3 +1,3 @@
1
1
  module Slugbuilder
2
- VERSION = '2.0.2'
2
+ VERSION = '3.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slugbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Panoply Dev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-26 00:00:00.000000000 Z
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler