@@ -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,34 @@ 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+ # Explicitly check for nil first
37+ if stack . nil?
38+ errors . add ( :stack , 'must be an existing stack' )
39+ return
40+ end
41+
42+ # Handle custom stacks (docker:// URLs passed as strings)
43+ if stack . is_a? ( String ) && stack . include? ( 'docker://' ) && FeatureFlag . enabled? ( :diego_custom_stacks )
44+ return
45+ end
46+
47+ # Handle existing stack objects or string names
48+ if stack . is_a? ( String )
49+ # For string stack names, verify they exist in the database
50+ unless VCAP ::CloudController ::Stack . where ( name : stack ) . any?
51+ errors . add ( :stack , 'must be an existing stack' )
52+ end
53+ end
54+ # If stack is an object (not nil, not string), assume it's valid
2855 end
2956 end
3057end
0 commit comments