Skip to content

Commit 692c6c0

Browse files
c0d1ngm0nk3ypbusko
authored andcommitted
set --auto-detect flag when no buildpacks were requested
Co-authored-by: Pavel Busko <[email protected]>
1 parent ec15ddc commit 692c6c0

File tree

8 files changed

+40
-15
lines changed

8 files changed

+40
-15
lines changed

lib/cloud_controller/diego/cnb/lifecycle_data.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module CNB
44
class LifecycleData
55
attr_accessor :app_bits_download_uri, :build_artifacts_cache_download_uri, :build_artifacts_cache_upload_uri,
66
:buildpacks, :app_bits_checksum, :droplet_upload_uri, :stack, :buildpack_cache_checksum,
7-
:credentials
7+
:credentials, :auto_detect
88

99
def message
1010
message = {
@@ -13,7 +13,8 @@ def message
1313
droplet_upload_uri:,
1414
buildpacks:,
1515
stack:,
16-
app_bits_checksum:
16+
app_bits_checksum:,
17+
auto_detect:
1718
}
1819
message[:build_artifacts_cache_download_uri] = build_artifacts_cache_download_uri if build_artifacts_cache_download_uri
1920
message[:buildpack_cache_checksum] = buildpack_cache_checksum if buildpack_cache_checksum
@@ -36,7 +37,8 @@ def schema
3637
buildpacks: Array,
3738
stack: String,
3839
app_bits_checksum: Hash,
39-
optional(:credentials) => String
40+
optional(:credentials) => String,
41+
auto_detect: bool
4042
}
4143
end
4244
end

lib/cloud_controller/diego/cnb/lifecycle_protocol.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def desired_lrp_builder(config, process)
2525
def new_lifecycle_data(staging_details)
2626
lifecycle_data = LifecycleData.new
2727
lifecycle_data.credentials = staging_details.lifecycle.credentials
28+
lifecycle_data.auto_detect = staging_details.lifecycle.buildpack_infos.empty?
2829

2930
lifecycle_data
3031
end

lib/cloud_controller/diego/cnb/staging_action_builder.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ def stage_action
3030
'--cache-output', '/tmp/cache-output.tgz'
3131
]
3232

33+
args.push('--auto-detect') if lifecycle_data[:auto_detect]
3334
lifecycle_data[:buildpacks].each do |buildpack|
3435
args.push('--buildpack', buildpack[:url]) if buildpack[:name] == 'custom'
35-
args.push('--system-buildpack', buildpack[:key]) unless buildpack[:name] == 'custom'
36+
args.push('--buildpack', buildpack[:key]) unless buildpack[:name] == 'custom'
3637
end
3738

3839
env_vars = BbsEnvironmentBuilder.build(staging_details.environment_variables)

lib/cloud_controller/diego/lifecycles/lifecycle_base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def initialize(package, staging_message)
99
@staging_message = staging_message
1010
@package = package
1111

12-
db_result = BuildpackLifecycleFetcher.fetch(buildpacks_to_use, staging_stack)
12+
db_result = BuildpackLifecycleFetcher.fetch(buildpacks_to_use, staging_stack, type)
1313
@buildpack_infos = db_result[:buildpack_infos]
1414
@validator = BuildpackLifecycleDataValidator.new({ buildpack_infos: buildpack_infos, stack: db_result[:stack] })
1515
end

spec/unit/lib/cloud_controller/diego/cnb/lifecycle_data_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module CNB
1616
data.buildpack_cache_checksum = 'bp-cache-checksum'
1717
data.app_bits_checksum = { type: 'sha256', value: 'package-checksum' }
1818
data.credentials = '{"registry":{"username":"password"}}'
19+
data.auto_detect = false
1920
data
2021
end
2122

@@ -29,7 +30,8 @@ module CNB
2930
stack: 'stack',
3031
buildpack_cache_checksum: 'bp-cache-checksum',
3132
app_bits_checksum: { type: 'sha256', value: 'package-checksum' },
32-
credentials: '{"registry":{"username":"password"}}'
33+
credentials: '{"registry":{"username":"password"}}',
34+
auto_detect: false
3335
}
3436
end
3537

@@ -98,7 +100,7 @@ module CNB
98100
expect do
99101
data.message
100102
end.to raise_error(
101-
Membrane::SchemaValidationError, /{ #{key} => Expected instance of (String|Array|Hash), given an instance of NilClass }/
103+
Membrane::SchemaValidationError, /{ #{key} => Expected instance of (String|Array|Hash|true or false), given .*}/
102104
)
103105
end
104106
end

spec/unit/lib/cloud_controller/diego/cnb/lifecycle_protocol_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ module CNB
7777
end
7878
end
7979

80+
context 'when buildpack_infos is empty' do
81+
let(:buildpack_infos) { [] }
82+
83+
it 'sets auto_detect: true' do
84+
lifecycle_data = lifecycle_protocol.lifecycle_data(staging_details)
85+
86+
expect(lifecycle_data[:auto_detect]).to be true
87+
end
88+
end
89+
8090
context 'when the generated message has invalid data' do
8191
let(:buildpack_infos) { [] }
8292

spec/unit/lib/cloud_controller/diego/cnb/staging_action_builder_spec.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,23 @@ module CNB
241241
end
242242
end
243243

244-
context('when system-buildpaks are used') do
244+
context('when system-buildpacks are used') do
245245
let(:buildpacks) do
246246
[
247247
{ name: 'node-cnb', key: 'node-key', skip_detect: false },
248248
{ name: 'java-cnb', key: 'java-key', skip_detect: false }
249249
]
250250
end
251251

252+
before do
253+
lifecycle_data[:auto_detect] = true
254+
end
255+
252256
let(:run_staging_action) do
253257
::Diego::Bbs::Models::RunAction.new(
254258
path: '/tmp/lifecycle/builder',
255259
user: 'vcap',
256-
args: ['--cache-dir', '/tmp/cache', '--cache-output', '/tmp/cache-output.tgz', '--system-buildpack', 'node-key', '--system-buildpack',
260+
args: ['--cache-dir', '/tmp/cache', '--cache-output', '/tmp/cache-output.tgz', '--auto-detect', '--buildpack', 'node-key', '--buildpack',
257261
'java-key', '--pass-env-var', 'FOO', '--pass-env-var', 'BAR'],
258262
env: bbs_env
259263
)
@@ -269,17 +273,17 @@ module CNB
269273
expect(builder.cached_dependencies).to include(::Diego::Bbs::Models::CachedDependency.new(
270274
name: 'node-cnb',
271275
from: '',
272-
to: '/tmp/buildpacks/54548f35489d6234',
273-
cache_key: 'node-cnb',
276+
to: '/tmp/buildpacks/0dcf6bb539d77cbc',
277+
cache_key: 'node-key',
274278
log_source: '',
275279
checksum_algorithm: '',
276280
checksum_value: ''
277281
))
278282
expect(builder.cached_dependencies).to include(::Diego::Bbs::Models::CachedDependency.new(
279283
name: 'java-cnb',
280284
from: '',
281-
to: '/tmp/buildpacks/c56b3bfdba7aa4dd',
282-
cache_key: 'java-cnb',
285+
to: '/tmp/buildpacks/be0ef1aa1092a6db',
286+
cache_key: 'java-key',
283287
log_source: '',
284288
checksum_algorithm: '',
285289
checksum_value: ''

spec/unit/lib/cloud_controller/diego/lifecycles/cnb_lifecycle_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ module VCAP::CloudController
1616
context 'when the user specifies buildpacks' do
1717
let(:request_data) do
1818
{
19-
buildpacks: %w[docker://cool-buildpack docker://rad-buildpack]
19+
buildpacks: %w[docker://nodejs cool-buildpack]
2020
}
2121
end
2222

23+
before do
24+
Buildpack.make(name: 'cool-buildpack', lifecycle: 'cnb')
25+
Buildpack.make(name: 'rad-buildpack')
26+
end
27+
2328
it 'uses the buildpacks from the user' do
2429
build = BuildModel.make(:cnb)
2530

@@ -29,7 +34,7 @@ module VCAP::CloudController
2934

3035
data_model = VCAP::CloudController::CNBLifecycleDataModel.last
3136

32-
expect(data_model.buildpacks).to eq(%w[docker://cool-buildpack docker://rad-buildpack])
37+
expect(data_model.buildpacks).to eq(%w[docker://nodejs cool-buildpack])
3338
expect(data_model.build).to eq(build)
3439
end
3540
end

0 commit comments

Comments
 (0)