@@ -8,6 +8,14 @@ class BuildpackLifecycleDataValidator
88
99 validate :buildpacks_are_uri_or_nil
1010 validate :stack_exists_in_db
11+ validate :custom_stack_requires_custom_buildpack
12+
13+ def custom_stack_requires_custom_buildpack
14+ return unless stack . is_a? ( String ) && stack . include? ( 'docker://' )
15+ return if buildpack_infos . all? ( &:custom? )
16+
17+ errors . add ( :buildpack , 'must be a custom buildpack when using a custom stack' )
18+ end
1119
1220 def buildpacks_are_uri_or_nil
1321 buildpack_infos . each do |buildpack_info |
@@ -16,15 +24,31 @@ def buildpacks_are_uri_or_nil
1624 next if buildpack_info . buildpack_url
1725
1826 if stack
19- errors . add ( :buildpack , %("#{ buildpack_info . buildpack } " for stack "#{ stack . name } " must be an existing admin buildpack or a valid git URI) )
27+ stack_name = stack . is_a? ( String ) ? stack : stack . name
28+ errors . add ( :buildpack , %("#{ buildpack_info . buildpack } " for stack "#{ stack_name } " must be an existing admin buildpack or a valid git URI) )
2029 else
2130 errors . add ( :buildpack , %("#{ buildpack_info . buildpack } " must be an existing admin buildpack or a valid git URI) )
2231 end
2332 end
2433 end
2534
2635 def stack_exists_in_db
27- errors . add ( :stack , 'must be an existing stack' ) if stack . nil?
36+ return if stack . nil?
37+
38+ # Handle custom stacks (docker:// URLs passed as strings)
39+ if stack . is_a? ( String ) && stack . include? ( 'docker://' ) && FeatureFlag . enabled? ( :diego_custom_stacks )
40+ return
41+ end
42+
43+ # Handle existing stack objects or string names
44+ if stack . is_a? ( String )
45+ return if VCAP ::CloudController ::Stack . where ( name : stack ) . any?
46+ else
47+ # stack is a Stack object, it exists in DB by definition
48+ return
49+ end
50+
51+ errors . add ( :stack , 'must be an existing stack' )
2852 end
2953 end
3054end
0 commit comments