Skip to content

Commit d815656

Browse files
modulo11pbusko
authored andcommitted
add support for system cnbs
Co-authored-by: Pavel Busko <[email protected]>
1 parent 328e478 commit d815656

File tree

8 files changed

+31
-52
lines changed

8 files changed

+31
-52
lines changed

app/messages/app_manifest_message.rb

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,6 @@ def docker_lifecycle_data
284284
end
285285

286286
def cnb_lifecycle_data
287-
return unless requested?(:buildpacks) || requested?(:buildpack) || requested?(:stack)
288-
289-
if requested?(:buildpacks)
290-
requested_buildpacks = @buildpacks
291-
elsif requested?(:buildpack)
292-
requested_buildpacks = []
293-
requested_buildpacks.push(@buildpack) unless should_autodetect?(@buildpack)
294-
end
295-
296287
{
297288
type: Lifecycles::CNB,
298289
data: {
@@ -304,16 +295,8 @@ def cnb_lifecycle_data
304295
end
305296

306297
def buildpacks_lifecycle_data
307-
return unless requested?(:buildpacks) || requested?(:buildpack) || requested?(:stack)
308-
309-
if requested?(:buildpacks)
310-
requested_buildpacks = @buildpacks
311-
elsif requested?(:buildpack)
312-
requested_buildpacks = []
313-
requested_buildpacks.push(@buildpack) unless should_autodetect?(@buildpack)
314-
end
315-
316298
{
299+
type: Lifecycles::BUILDPACK,
317300
data: {
318301
buildpacks: requested_buildpacks,
319302
stack: @stack
@@ -493,5 +476,15 @@ def validate_docker_buildpacks_combination!
493476
def add_process_error!(error_message, type)
494477
errors.add(:base, %(Process "#{type}": #{error_message}))
495478
end
479+
480+
def requested_buildpacks
481+
return nil unless requested?(:buildpacks) || requested?(:buildpack)
482+
return @buildpacks if requested?(:buildpacks)
483+
484+
buildpacks = []
485+
buildpacks.push(@buildpack) if requested?(:buildpack) && !should_autodetect?(@buildpack)
486+
487+
buildpacks
488+
end
496489
end
497490
end

lib/cloud_controller/diego/buildpack/lifecycle_protocol.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def desired_lrp_builder(config, process)
2323
def new_lifecycle_data(_)
2424
LifecycleData.new
2525
end
26+
27+
def type
28+
VCAP::CloudController::Lifecycles::BUILDPACK
29+
end
2630
end
2731
end
2832
end

lib/cloud_controller/diego/buildpack_entry_generator.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module VCAP::CloudController
22
module Diego
33
class BuildpackEntryGenerator
4-
def initialize(blobstore_url_generator)
4+
def initialize(blobstore_url_generator, type)
55
@blobstore_url_generator = blobstore_url_generator
6+
@type = type
67
end
78

89
def buildpack_entries(buildpack_infos, stack_name)
@@ -26,7 +27,7 @@ def custom_buildpack_entry(buildpack)
2627
end
2728

2829
def default_admin_buildpacks(stack_name)
29-
VCAP::CloudController::Buildpack.list_admin_buildpacks(stack_name).
30+
VCAP::CloudController::Buildpack.list_admin_buildpacks(stack_name, @type).
3031
select(&:enabled).
3132
collect { |buildpack| admin_buildpack_entry(buildpack) }
3233
end

lib/cloud_controller/diego/cnb/lifecycle_protocol.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def new_lifecycle_data(staging_details)
2828

2929
lifecycle_data
3030
end
31+
32+
def type
33+
VCAP::CloudController::Lifecycles::CNB
34+
end
3135
end
3236
end
3337
end

lib/cloud_controller/diego/cnb/staging_action_builder.rb

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,6 @@ def initialize(config, staging_details, lifecycle_data)
1111
super(config, staging_details, lifecycle_data, 'cnb', '/home/vcap/workspace', '/tmp/cache-output.tgz', ::Diego::Bbs::Models::ImageLayer::MediaType::TGZ)
1212
end
1313

14-
def cached_dependencies
15-
return nil if @config.get(:diego, :enable_declarative_asset_downloads)
16-
17-
[
18-
::Diego::Bbs::Models::CachedDependency.new(
19-
from: LifecycleBundleUriGenerator.uri(config.get(:diego, :lifecycle_bundles)[lifecycle_bundle_key]),
20-
to: '/tmp/lifecycle',
21-
cache_key: "#{@prefix}-#{lifecycle_stack}-lifecycle"
22-
)
23-
]
24-
end
25-
2614
def task_environment_variables
2715
env = [
2816
::Diego::Bbs::Models::EnvironmentVariable.new(name: 'CNB_USER_ID', value: '2000'),
@@ -43,7 +31,8 @@ def stage_action
4331
]
4432

4533
lifecycle_data[:buildpacks].each do |buildpack|
46-
args.push('--buildpack', buildpack[:url])
34+
args.push('--buildpack', buildpack[:url]) if buildpack[:name] == 'custom'
35+
args.push('--system-buildpack', buildpack[:key]) unless buildpack[:name] == 'custom'
4736
end
4837

4938
env_vars = BbsEnvironmentBuilder.build(staging_details.environment_variables)

lib/cloud_controller/diego/lifecycle_protocol.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class InvalidDownloadUri < StandardError; end
1919
def initialize(blobstore_url_generator=::CloudController::DependencyLocator.instance.blobstore_url_generator,
2020
droplet_url_generator=::CloudController::DependencyLocator.instance.droplet_url_generator)
2121
@blobstore_url_generator = blobstore_url_generator
22-
@buildpack_entry_generator = BuildpackEntryGenerator.new(@blobstore_url_generator)
22+
@buildpack_entry_generator = BuildpackEntryGenerator.new(@blobstore_url_generator, type)
2323
@droplet_url_generator = droplet_url_generator
2424
end
2525

lib/cloud_controller/upload_buildpack.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'vcap/digester'
2+
require 'cloud_controller/diego/lifecycles/lifecycles'
23

34
module VCAP::CloudController
45
class UploadBuildpack
@@ -69,6 +70,8 @@ def determine_new_stack(buildpack, bits_file_path)
6970
extracted_stack = Buildpacks::StackNameExtractor.extract_from_file(bits_file_path)
7071
[extracted_stack, buildpack.stack].find(&:present?)
7172
rescue CloudController::Errors::BuildpackError => e
73+
return buildpack.stack if buildpack.lifecycle == Lifecycles::CNB
74+
7275
raise CloudController::Errors::ApiError.new_from_details('BuildpackZipError', e.message)
7376
end
7477

spec/unit/messages/app_manifest_message_spec.rb

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,22 +1114,6 @@ module VCAP::CloudController
11141114
expect(message.errors.full_messages).to match_array(error_messages)
11151115
end
11161116
end
1117-
1118-
context 'when cnb: true and no buildpacks provided' do
1119-
before do
1120-
FeatureFlag.make(name: 'diego_cnb', enabled: true, error_message: nil)
1121-
end
1122-
1123-
let(:params_from_yaml) { { name: 'eugene', lifecycle: 'cnb' } }
1124-
1125-
it 'is not valid' do
1126-
message = AppManifestMessage.create_from_yml(params_from_yaml)
1127-
1128-
expect(message).not_to be_valid
1129-
expect(message.errors).to have(1).items
1130-
expect(message.errors.full_messages).to include('Buildpack(s) must be specified when using Cloud Native Buildpacks')
1131-
end
1132-
end
11331117
end
11341118

11351119
describe '.create_from_yml' do
@@ -2009,10 +1993,11 @@ module VCAP::CloudController
20091993
context 'when no lifecycle data is requested in the manifest' do
20101994
let(:parsed_yaml) { {} }
20111995

2012-
it 'does not forward missing attributes to the AppUpdateMessage' do
1996+
it 'defaults to the buildpack lifecycle' do
20131997
message = AppManifestMessage.create_from_yml(parsed_yaml)
20141998

2015-
expect(message.app_update_message.requested?(:lifecycle)).to be false
1999+
expect(message.app_update_message.requested?(:lifecycle)).to be true
2000+
expect(message.app_update_message.lifecycle_type).to eq('buildpack')
20162001
end
20172002
end
20182003

0 commit comments

Comments
 (0)