Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
Run buildpacks without context of environment
Browse files Browse the repository at this point in the history
- Prevents other ENVs (running this gem in another bundler context or
  within a Rails app etc) from leaking into the build
  • Loading branch information
jdlehman committed Feb 1, 2017
1 parent 051e281 commit d5767e8
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/slugbuilder/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def initialize(repo:, git_ref:, stdout: $stdout)
end

def build(clear_cache: false, env: {}, prebuild: nil, postbuild: nil, slug_name: nil, buildpacks: Slugbuilder.config.buildpacks)
@old_env = ENV.to_h
# clear environment from previous builds
FileUtils.rm_rf(@env_dir)
FileUtils.mkdir_p(@env_dir)
Expand All @@ -36,7 +37,9 @@ def build(clear_cache: false, env: {}, prebuild: nil, postbuild: nil, slug_name:

prebuild.call(repo: @repo, git_ref: @git_ref) if prebuild

build_and_release
with_clean_env do
build_and_release
end
stitle("Setup completed in #{@setup_time} seconds")
stitle("Build completed in #{@build_time} seconds")
stext("Application compiled in #{@compile_time} seconds")
Expand All @@ -58,11 +61,24 @@ def build(clear_cache: false, env: {}, prebuild: nil, postbuild: nil, slug_name:
rescue => e
stitle("Failed: #{e}\n#{e.backtrace.join("\n")}")
return false
ensure
restore_env
end


private

def restore_env
ENV.delete_if { true }
ENV.update(@old_env)
end

def with_clean_env
ENV.delete_if { true }
yield
restore_env
end

def wipe_cache
FileUtils.rm_rf(@cache_dir)
FileUtils.mkdir_p(@buildpacks_dir)
Expand Down

0 comments on commit d5767e8

Please sign in to comment.