Skip to content

Commit c0b85ca

Browse files
committed
Make sandbox directory on demand
Previously, the component sandbox directory was created aggressively each time a Droplet was instantiated. This caused issues because it would happen during the detect phase and corrupt the file system for the compile phase. This change removes the aggressive creation and instead makes the directory the first time that the sandbox is requested by a component. [#62947962]
1 parent 04065ee commit c0b85ca

5 files changed

Lines changed: 23 additions & 9 deletions

File tree

lib/java_buildpack/component/droplet.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ class Droplet
5353
# excludes files in the sandboxes of other components
5454
attr_reader :root
5555

56-
# @!attribute [r] sandbox
57-
# @return [Pathname] the root of the component's sandbox
58-
attr_reader :sandbox
59-
6056
# Creates a new instance of the droplet abstraction
6157
#
6258
# @param [AdditionalLibraries] additional_libraries the shared +AdditionalLibraries+ instance for all components
@@ -81,7 +77,6 @@ def initialize(additional_libraries, component_id, java_home, java_opts, root)
8177
@root = JavaBuildpack::Util::FilteringPathname.new(root,
8278
->(path) { !in?(path, buildpack_root) || in?(path, @sandbox) },
8379
true)
84-
FileUtils.mkdir_p @sandbox
8580
end
8681

8782
# Copy resources from a components resources directory to a directory
@@ -91,13 +86,22 @@ def copy_resources(target_directory = @sandbox)
9186
resources = RESOURCES_DIRECTORY + @component_id
9287

9388
if resources.exist?
89+
FileUtils.mkdir_p target_directory
9490
FileUtils.cp_r("#{resources}/.", target_directory)
9591
@logger.debug { "Resources #{resources} found" }
9692
else
9793
@logger.debug { "No resources #{resources} found" }
9894
end
9995
end
10096

97+
# Returns the root of the component's sandbox
98+
#
99+
# @return [Pathname] the root of the component's sandbox
100+
def sandbox
101+
FileUtils.mkdir_p @sandbox unless @sandbox.exist?
102+
@sandbox
103+
end
104+
101105
private
102106

103107
RESOURCES_DIRECTORY = Pathname.new(File.expand_path('../../../../resources', __FILE__))

lib/java_buildpack/container/tomcat.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ def download_support
112112

113113
def expand(file)
114114
with_timing "Expanding Tomcat to #{@droplet.sandbox.relative_path_from(@droplet.root)}" do
115-
FileUtils.mkdir_p @droplet.sandbox
116115
shell "tar xzf #{file.path} -C #{@droplet.sandbox} --strip 1 --exclude webapps 2>&1"
117116

118117
@droplet.copy_resources

lib/java_buildpack/framework/new_relic_agent.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ module JavaBuildpack::Framework
2424
class NewRelicAgent < JavaBuildpack::Component::VersionedDependencyComponent
2525

2626
def compile
27-
FileUtils.mkdir_p @droplet.sandbox
2827
FileUtils.mkdir_p logs_dir
2928

3029
download_jar

lib/java_buildpack/framework/spring_insight.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ def unpack_agent_installer(root, file)
109109
end
110110

111111
def install_insight(agent_dir)
112-
FileUtils.mkdir_p @droplet.sandbox
113-
114112
root = Pathname.glob(agent_dir + 'springsource-insight-uber-agent-*')[0]
115113

116114
init_container_libs root

spec/java_buildpack/component/droplet_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,18 @@
8282
droplet.copy_resources
8383
end
8484

85+
it 'should not initialize sandbox until it is used' do
86+
sandbox_dir = app_dir + '.java-buildpack/droplet'
87+
88+
expect(sandbox_dir).not_to exist
89+
90+
droplet
91+
92+
expect(sandbox_dir).not_to exist
93+
94+
droplet.sandbox
95+
96+
expect(sandbox_dir).to exist
97+
end
98+
8599
end

0 commit comments

Comments
 (0)