lib/slugbuilder/builder.rb in slugbuilder-1.0.0 vs lib/slugbuilder/builder.rb in slugbuilder-1.1.0

- old
+ new

@@ -21,11 +21,12 @@ if block_given? yield(repo: repo, git_ref: git_ref) end end - def build(clear_cache: false, env: {}, prebuild: nil, postbuild: nil, slug_name: nil) + def build(clear_cache: false, env: {}, prebuild: nil, postbuild: nil, slug_name: nil, buildpacks: Slugbuilder.config.buildpacks) + @buildpacks = buildpacks @env = env @slug_file = slug_name ? "#{slug_name}.tgz" : Shellwords.escape("#{@repo.gsub('/', '.')}.#{@git_ref}.#{@git_sha}.tgz") wipe_cache if clear_cache prebuild.call(repo: @repo, git_ref: @git_ref) if prebuild @@ -48,19 +49,20 @@ if block_given? yield(repo: @repo, git_ref: @git_ref, git_sha: @git_sha, stats: stats, slug: File.join(@output_dir, @slug_file)) end return true rescue => e - stitle("Failed to create slug: #{e}") + stitle("Failed: #{e}") return false end private def wipe_cache FileUtils.rm_rf(@cache_dir) + FileUtils.mkdir_p(File.join(@cache_dir, 'buildpacks')) end def build_and_release @build_time = realtime do set_environment @@ -140,16 +142,15 @@ def get_buildpack_name(url) url.match(/.+\/(.+?)\.git$/)[1] end def fetch_buildpacks - buildpacks = Slugbuilder.config.buildpacks - buildpacks << Shellwords.escape(@env['BUILDPACK_URL']) if @env.key?('BUILDPACK_URL') - fail 'Could not detect buildpack' if buildpacks.size.zero? + @buildpacks << Shellwords.escape(@env['BUILDPACK_URL']) if @env.key?('BUILDPACK_URL') + fail 'Could not detect buildpack' if @buildpacks.size.zero? existing_buildpacks = Dir.entries(@buildpacks_dir) - buildpacks.each do |buildpack_url| + @buildpacks.each do |buildpack_url| buildpack_name = get_buildpack_name(buildpack_url) if !existing_buildpacks.include?(buildpack_name) # download buildpack stitle("Fetching buildpack: #{buildpack_name}") rc = run("git clone --depth=1 #{buildpack_url} #{@buildpacks_dir}/#{buildpack_name} 2>&1") @@ -162,10 +163,10 @@ fail "Failed to update: #{buildpack_name}" if rc != 0 end end end - buildpacks + @buildpacks end def run_buildpacks(buildpacks) @compile_time = 0