-
Notifications
You must be signed in to change notification settings - Fork 361
/
buildpack_lifecycle.rb
62 lines (49 loc) · 1.59 KB
/
buildpack_lifecycle.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'cloud_controller/diego/lifecycles/buildpack_info'
require 'cloud_controller/diego/lifecycles/buildpack_lifecycle_data_validator'
require 'fetchers/buildpack_lifecycle_fetcher'
module VCAP::CloudController
class BuildpackLifecycle
attr_reader :staging_message, :buildpack_infos
def initialize(package, staging_message)
@staging_message = staging_message
@package = package
db_result = BuildpackLifecycleFetcher.fetch(buildpacks_to_use, staging_stack)
@buildpack_infos = db_result[:buildpack_infos]
@validator = BuildpackLifecycleDataValidator.new({ buildpack_infos: buildpack_infos, stack: db_result[:stack] })
end
delegate :valid?, :errors, to: :validator
def type
Lifecycles::BUILDPACK
end
def create_lifecycle_data_model(build)
VCAP::CloudController::BuildpackLifecycleDataModel.create(
buildpacks: Array(buildpacks_to_use),
stack: staging_stack,
build: build
)
end
def staging_environment_variables
{
'CF_STACK' => staging_stack
}
end
def staging_stack
requested_stack || app_stack || VCAP::CloudController::Stack.default.name
end
private
def buildpacks_to_use
if staging_message.buildpack_data.buildpacks
staging_message.buildpack_data.buildpacks
else
@package.app.lifecycle_data.buildpacks
end
end
def requested_stack
@staging_message.buildpack_data.stack
end
def app_stack
@package.app.buildpack_lifecycle_data.try(:stack)
end
attr_reader :validator
end
end