slugbuilder 1.3.0 → 2.0.0

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: 06dc50b7ddf97d49f958e3a06e4129a6b049caed
4
- data.tar.gz: c3a927ef28e60b0fa83d9d897478519b4806362b
3
+ metadata.gz: dc40a6d4591cdf1c3d38112e9d1bc4bde1012687
4
+ data.tar.gz: '0102491f9b95b694905db3e7876d588a2e067f62'
5
5
  SHA512:
6
- metadata.gz: f86f5ad1ce6ad981cc2a8dd0b8f9d0911501e162ff7ad18915c6723bef994a62aee344cc7ca1e705981adff23ce9a6d79c1e04565c784072ed39ed30e71266ab
7
- data.tar.gz: 01a9a03760f92205a8a372dd99f6317476b47574c720fc71bc902068b358319aebac5b164d30d73c37fdd3b012cd40520cb720fa5b455d8891db3a293f3ef8eb
6
+ metadata.gz: f64bcd5db7366dadd1f09d63a2a61a441ace5de3020a3827d5b60a0e39ce09e577eb6c600db871434038c21de73901794dde097b34b2185eac601719bf723659
7
+ data.tar.gz: f41a21fd11a8196aa2b2fd46f6f2197a7641ba11e6afb18092c5902a691d78b8054d2b721a86814604cc14015e85d6884a3b79a762b5410c5b6932f8ee316d34
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.0 (2017-5-3)
4
+
5
+ Changed:
6
+
7
+ - Prebuild and postbuild hooks now take `git_url` as a keyword argument
8
+
9
+ Added:
10
+
11
+ - The `protocol` configuration option allows specifying the protocol to use when downloading git repositories
12
+ - Buildpack and repository urls now accept more formats (`<organization>/<repository_name>`, `git@<git_service>:<organization>/<repository_name>.git`, and `https://<git_service>/<organization>/<repository_name>.git`
13
+
3
14
  ## 1.3.0 (2017-3-7)
4
15
 
5
16
  Added:
data/README.md CHANGED
@@ -61,11 +61,11 @@ sb.build(clear_cache: true)
61
61
  # using a Proc or Proc-like object (responds to `call` method)
62
62
  sb = Slugbuilder::Builder.new(repo: 'heroku/node-js-sample', git_ref: 'master')
63
63
  class PostBuildInterface
64
- def self.call(repo:, git_ref:, stats:, slug:)
64
+ def self.call(repo:, git_ref:, git_url:, stats:, slug:)
65
65
  # postbuild logic
66
66
  end
67
67
  end
68
- sb.build(prebuild: ->(repo: repo, git_ref: git_ref) { p "prebuild logic" }, postbuild: PostBuildInterface)
68
+ sb.build(prebuild: ->(repo: repo, git_ref: git_ref, git_url: git_url) { p "prebuild logic" }, postbuild: PostBuildInterface)
69
69
 
70
70
  # prebuild/postbuild with optional blocks
71
71
  sb = Slugbuilder::Builder.new(repo: 'heroku/node-js-sample', git_ref: 'master') do |args|
@@ -84,12 +84,13 @@ You can optionally define a `pre-compile` or `post-compile` script in your appli
84
84
 
85
85
  ### Builder#initialize(repo:, git_ref:, &block)
86
86
 
87
- - `repo` String (required): the github repo in the form `<organization>/<repository>`
87
+ - `repo` String (required): the github repo in the form `<organization>/<repository_name>`, `https://<git_service>/<organization>/<repository_name>.git`, or `git@<git_service>:<organization>/<repository_name>.git`
88
88
  - `git_ref` String (required): the SHA or branch to build
89
89
  - `stdout` IO (optional): the IO stream to write build output to. This defaults to `$stdout`
90
90
  - `block` Block (optional): an optional block that runs pre-build. It receives a Hash with the structure:
91
- - `repo` String: The git repo identifier
91
+ - `repo` String: The git repo identifier in the form `<organization>/<repository_name>`
92
92
  - `git_ref` String: The git branchname or SHA
93
+ - `git_url` String: The git URL (this will be in the form specified by the `Slugbuilder.config.protocol`)
93
94
 
94
95
  Alternatively, a Proc can be passed to `build` method's keyword argument `prebuild` to achieve the same effect.
95
96
 
@@ -104,11 +105,13 @@ Alternatively, a Proc can be passed to `build` method's keyword argument `prebui
104
105
  - `prebuild` Proc (optional): an optional Proc (or anything that conforms to the `call` API of a Proc) that will be run before the build. The Proc will receive a Hash with the structure:
105
106
  - `repo` String: The git repo identifier
106
107
  - `git_ref` String: The git branchname or SHA
108
+ - `git_url` String: The git URL (this will be in the form specified by the `Slugbuilder.config.protocol`)
107
109
  Alternatively, a block can be passed to the `initialize` method to the same effect.
108
110
  - `postbuild` Proc (optional): an optional Proc (or anything that conforms to the `call` API of a Proc) that will run post-build. The Proc will receive a Hash with the structure:
109
111
  - `slug` String: Location of the built slug file
110
112
  - `repo` String: The git repo identifier
111
113
  - `git_ref` String: The git branchname or SHA
114
+ - `git_url` String: The git URL (this will be in the form specified by the `Slugbuilder.config.protocol`)
112
115
  - `git_sha` String: The git SHA (even if the git ref was a branch name)
113
116
  - `request_id` String: The unique id of the build request
114
117
  - `stats` Hash:
@@ -143,8 +146,9 @@ Slugbuilder.config.output_dir = './slugs'
143
146
  @cache_dir = '/tmp/slugbuilder-cache'
144
147
  @output_dir = './slugs'
145
148
  @git_service = 'github.com'
149
+ @protocol = 'https'
146
150
  @buildpacks = [
147
- 'https://github.com/heroku/heroku-buildpack-nodejs.git',
151
+ 'git@github.com:heroku/heroku-buildpack-nodejs.git',
148
152
  'https://github.com/heroku/heroku-buildpack-ruby.git#37ed188'
149
153
  ]
150
154
  ```
@@ -173,6 +177,12 @@ This is where the git repositories live (github.com, gitlab.com, bitbucket.org,
173
177
 
174
178
  > Defaults to `github.com`
175
179
 
180
+ **protocol**
181
+
182
+ The protocol that should be used to pull down git repositories (including buildbpacks). This can be either `https` or `ssh`
183
+
184
+ > Defaults to `https` (also uses `https` if `protocol` is not valid)
185
+
176
186
  **buildpacks**
177
187
 
178
188
  Buildpacks is an array of valid git clone-able [buildpack](https://devcenter.heroku.com/articles/buildpacks) URLs.
@@ -12,15 +12,17 @@ module Slugbuilder
12
12
  @output_dir = Slugbuilder.config.output_dir
13
13
  @buildpacks_dir = File.join(@cache_dir, 'buildpacks')
14
14
  @env_dir = File.join(@base_dir, 'environment')
15
- @repo = repo
15
+ repo_matches = parse_git_url(repo)
16
+ @repo = "#{repo_matches[:org]}/#{repo_matches[:name]}"
17
+ @git_url = normalize_git_url(repo)
16
18
  @git_ref = git_ref
17
- @git_dir = Shellwords.escape(File.join(@base_dir, 'git', repo))
18
- @build_dir = Shellwords.escape(File.join(@base_dir, repo, git_ref))
19
+ @git_dir = Shellwords.escape(File.join(@base_dir, 'git', @repo))
20
+ @build_dir = Shellwords.escape(File.join(@base_dir, @repo, git_ref))
19
21
 
20
22
  setup
21
23
 
22
24
  if block_given?
23
- yield(repo: repo, git_ref: git_ref)
25
+ yield(repo: @repo, git_ref: git_ref, git_url: @git_url)
24
26
  end
25
27
  end
26
28
 
@@ -35,7 +37,7 @@ module Slugbuilder
35
37
  @slug_file = slug_name ? "#{slug_name}.tgz" : Shellwords.escape("#{@repo.gsub('/', '.')}.#{@git_ref}.#{@git_sha}.tgz")
36
38
  wipe_cache if clear_cache
37
39
 
38
- prebuild.call(repo: @repo, git_ref: @git_ref) if prebuild
40
+ prebuild.call(repo: @repo, git_ref: @git_ref, git_url: @git_url) if prebuild
39
41
 
40
42
  with_clean_env do
41
43
  build_and_release
@@ -53,9 +55,9 @@ module Slugbuilder
53
55
  output: build_output.join('')
54
56
  }
55
57
 
56
- postbuild.call(repo: @repo, git_ref: @git_ref, git_sha: @git_sha, request_id: @request_id, stats: stats, slug: File.join(@output_dir, @slug_file)) if postbuild
58
+ postbuild.call(repo: @repo, git_ref: @git_ref, git_sha: @git_sha, git_url: @git_url, request_id: @request_id, stats: stats, slug: File.join(@output_dir, @slug_file)) if postbuild
57
59
  if block_given?
58
- yield(repo: @repo, git_ref: @git_ref, git_sha: @git_sha, request_id: @request_id, stats: stats, slug: File.join(@output_dir, @slug_file))
60
+ yield(repo: @repo, git_ref: @git_ref, git_sha: @git_sha, git_url: @git_url, request_id: @request_id, stats: stats, slug: File.join(@output_dir, @slug_file))
59
61
  end
60
62
  return true
61
63
  rescue => e
@@ -154,7 +156,7 @@ module Slugbuilder
154
156
 
155
157
  def download_repo
156
158
  stitle("Fetching #{@repo}")
157
- rc = run("git clone --quiet git@#{Slugbuilder.config.git_service}:#{@repo}.git #{@git_dir}")
159
+ rc = run("git clone --quiet #{@git_url} #{@git_dir}")
158
160
  fail "Failed to download repo: #{@repo}" if rc != 0
159
161
  end
160
162
 
@@ -165,7 +167,8 @@ module Slugbuilder
165
167
  end
166
168
 
167
169
  def get_buildpack_name(url)
168
- url.match(/.+\/(.+?)\.git$/)[1]
170
+ matches = parse_git_url(url)
171
+ "#{matches[:org]}__#{matches[:name]}#{matches[:hash]}"
169
172
  end
170
173
 
171
174
  def fetch_buildpacks
@@ -174,11 +177,12 @@ module Slugbuilder
174
177
 
175
178
  existing_buildpacks = Dir.entries(@buildpacks_dir)
176
179
  @buildpacks.each do |buildpack_url|
180
+ buildpack_matches = parse_git_url(buildpack_url)
177
181
  buildpack_name = get_buildpack_name(buildpack_url)
178
182
  if !existing_buildpacks.include?(buildpack_name)
179
183
  # download buildpack
180
184
  stitle("Fetching buildpack: #{buildpack_name}")
181
- rc = run("git clone --quiet --depth=1 #{buildpack_url} #{@buildpacks_dir}/#{buildpack_name}")
185
+ rc = run("git clone --quiet #{normalize_git_url(buildpack_url)} #{@buildpacks_dir}/#{buildpack_name}")
182
186
  fail "Failed to download buildpack: #{buildpack_name}" if rc != 0
183
187
  else
184
188
  # fetch latest
@@ -188,6 +192,14 @@ module Slugbuilder
188
192
  fail "Failed to update: #{buildpack_name}" if rc != 0
189
193
  end
190
194
  end
195
+
196
+ # checkout hash
197
+ if buildpack_matches[:hash]
198
+ Dir.chdir("#{@buildpacks_dir}/#{buildpack_name}") do
199
+ rc = run("git fetch --quiet --all && git checkout --quiet #{buildpack_matches[:hash]}")
200
+ fail "Failed to fetch and checkout: #{buildpack_matches[:hash]}" if rc != 0
201
+ end
202
+ end
191
203
  end
192
204
 
193
205
  @buildpacks
@@ -251,6 +263,29 @@ module Slugbuilder
251
263
  stitle("Slug size is #{@slug_size} Megabytes.")
252
264
  end
253
265
 
266
+ def parse_git_url(url)
267
+ regex = %r{
268
+ ^
269
+ .*?
270
+ (?:(?<host>[^\/@]+)(\/|:))?
271
+ (?<org>[^\/:]+)
272
+ \/
273
+ (?<name>[^\/#\.]+)
274
+ (?:\.git(?:\#(?<hash>.+))?)?
275
+ $
276
+ }x
277
+ url.match(regex)
278
+ end
279
+
280
+ def normalize_git_url(url)
281
+ matches = parse_git_url(url)
282
+ if Slugbuilder.config.protocol == 'ssh'
283
+ "git@#{matches[:host] || Slugbuilder.config.git_service}:#{matches[:org]}/#{matches[:name]}.git"
284
+ else
285
+ "https://#{matches[:host] || Slugbuilder.config.git_service}/#{matches[:org]}/#{matches[:name]}.git"
286
+ end
287
+ end
288
+
254
289
  def print_workers
255
290
  workers = {}
256
291
  if File.exists?("#{@build_dir}/Procfile")
@@ -17,13 +17,14 @@ module Slugbuilder
17
17
 
18
18
  class Configuration
19
19
  attr_accessor :base_dir, :cache_dir, :output_dir,
20
- :git_service, :buildpacks
20
+ :git_service, :buildpacks, :protocol
21
21
 
22
22
  def initialize
23
23
  @base_dir = '/tmp/slugbuilder'
24
24
  @cache_dir = '/tmp/slugbuilder-cache'
25
25
  @output_dir = '.'
26
26
  @git_service = 'github.com'
27
+ @protocol = 'https'
27
28
  @buildpacks = []
28
29
  end
29
30
  end
@@ -1,3 +1,3 @@
1
1
  module Slugbuilder
2
- VERSION = '1.3.0'
2
+ VERSION = '2.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: 1.3.0
4
+ version: 2.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-03-07 00:00:00.000000000 Z
11
+ date: 2017-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler