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

Commit

Permalink
Move location of buildpacks cache directory
Browse files Browse the repository at this point in the history
- This won't affect anything, but protects against buildpacks that blow
away the entire cache directory rather than just things they created

Related: heroku/heroku-buildpack-go#187
  • Loading branch information
jdlehman committed May 25, 2017
1 parent 166985b commit 7e444e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
13 changes: 8 additions & 5 deletions lib/slugbuilder/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ module Slugbuilder
class Builder
def initialize(repo:, git_ref:, stdout: $stdout)
@stdout = stdout
@base_dir = Slugbuilder.config.base_dir
@base_dir = Shellwords.escape(Slugbuilder.config.base_dir)
@cache_dir = Shellwords.escape(Slugbuilder.config.cache_dir)
@output_dir = Slugbuilder.config.output_dir
@buildpacks_dir = File.join(@cache_dir, 'buildpacks')
@output_dir = Shellwords.escape(Slugbuilder.config.output_dir)
@buildpacks_dir = File.join(@base_dir, 'buildpacks')
@env_dir = File.join(@base_dir, 'environment')
repo_matches = parse_git_url(repo)
@repo = "#{repo_matches[:org]}/#{repo_matches[:name]}"
@git_url = normalize_git_url(repo)
@git_ref = git_ref
@git_dir = Shellwords.escape(File.join(@base_dir, 'git', @repo))
@build_dir = Shellwords.escape(File.join(@base_dir, @repo, git_ref))
@git_dir = File.join(@base_dir, 'git', @repo)
@build_dir = File.join(@base_dir, @repo, git_ref)

setup

Expand Down Expand Up @@ -83,6 +83,8 @@ def with_clean_env

def wipe_cache
FileUtils.rm_rf(@cache_dir)
FileUtils.rm_rf(@buildpacks_dir)
FileUtils.mkdir_p(@cache_dir)
FileUtils.mkdir_p(@buildpacks_dir)
end

Expand Down Expand Up @@ -136,6 +138,7 @@ def set_environment
end

def create_dirs
FileUtils.mkdir_p(@cache_dir)
FileUtils.mkdir_p(@base_dir)
FileUtils.mkdir_p(@buildpacks_dir)
FileUtils.mkdir_p(@output_dir)
Expand Down
19 changes: 10 additions & 9 deletions spec/slugbuilder/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

it 'creates directories' do
expect(Dir['/tmp/*']).to include('/tmp/slugbuilder', '/tmp/slugbuilder-cache', '/tmp/slugs')
expect(Dir['/tmp/slugbuilder/*']).to include('/tmp/slugbuilder/buildpacks')
end

it 'pulls down git repo and copies to build directory' do
Expand Down Expand Up @@ -100,20 +101,20 @@
Slugbuilder.config.buildpacks = ['https://github.com/heroku/heroku-buildpack-nodejs.git']
builder.build(clear_cache: true)
# make sure that ruby buildpack is no longer cached
expect(Dir['/tmp/slugbuilder-cache/buildpacks/*']).to eq(['/tmp/slugbuilder-cache/buildpacks/heroku__heroku-buildpack-nodejs'])
expect(Dir['/tmp/slugbuilder/buildpacks/*']).to eq(['/tmp/slugbuilder/buildpacks/heroku__heroku-buildpack-nodejs'])
end

it 'allows specifying the buildpacks for a build' do
builder.build
expect(Dir['/tmp/slugbuilder-cache/buildpacks/*']).to eq(['/tmp/slugbuilder-cache/buildpacks/heroku__heroku-buildpack-nodejs'])
expect(Dir['/tmp/slugbuilder/buildpacks/*']).to eq(['/tmp/slugbuilder/buildpacks/heroku__heroku-buildpack-nodejs'])
buildpacks = [
'https://github.com/heroku/heroku-buildpack-nodejs.git',
'https://github.com/heroku/heroku-buildpack-ruby.git'
]
builder.build(buildpacks: buildpacks)
expect(Dir['/tmp/slugbuilder-cache/buildpacks/*']).to eq([
'/tmp/slugbuilder-cache/buildpacks/heroku__heroku-buildpack-nodejs',
'/tmp/slugbuilder-cache/buildpacks/heroku__heroku-buildpack-ruby'
expect(Dir['/tmp/slugbuilder/buildpacks/*']).to eq([
'/tmp/slugbuilder/buildpacks/heroku__heroku-buildpack-nodejs',
'/tmp/slugbuilder/buildpacks/heroku__heroku-buildpack-ruby'
])
end

Expand All @@ -123,10 +124,10 @@
'git@github.com:heroku/heroku-buildpack-ruby.git#5a1ca011c568321077101028a11d24e6e09f1c36'
]
builder.build(buildpacks: buildpacks)
expect(Dir['/tmp/slugbuilder-cache/buildpacks/*']).to eq([
'/tmp/slugbuilder-cache/buildpacks/heroku__heroku-buildpack-nodejs',
'/tmp/slugbuilder-cache/buildpacks/heroku__heroku-buildpack-ruby',
'/tmp/slugbuilder-cache/buildpacks/heroku__heroku-buildpack-ruby5a1ca011c568321077101028a11d24e6e09f1c36'
expect(Dir['/tmp/slugbuilder/buildpacks/*']).to eq([
'/tmp/slugbuilder/buildpacks/heroku__heroku-buildpack-nodejs',
'/tmp/slugbuilder/buildpacks/heroku__heroku-buildpack-ruby',
'/tmp/slugbuilder/buildpacks/heroku__heroku-buildpack-ruby5a1ca011c568321077101028a11d24e6e09f1c36'
])
end

Expand Down

0 comments on commit 7e444e1

Please sign in to comment.