-
Notifications
You must be signed in to change notification settings - Fork 367
Expand file tree
/
Copy pathdesired_lrp_builder.rb
More file actions
123 lines (102 loc) · 4.49 KB
/
desired_lrp_builder.rb
File metadata and controls
123 lines (102 loc) · 4.49 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
module VCAP::CloudController
module Diego
module Buildpack
class DesiredLrpBuilder
include ::Diego::ActionBuilder
class InvalidStack < StandardError; end
attr_reader :start_command, :action_user
def initialize(config, opts)
@config = config
@stack = opts[:stack]
@droplet_uri = opts[:droplet_uri]
@process_guid = opts[:process_guid]
@droplet_hash = opts[:droplet_hash]
@ports = opts[:ports]
@checksum_algorithm = opts[:checksum_algorithm]
@checksum_value = opts[:checksum_value]
@start_command = opts[:start_command]
@action_user = opts[:action_user]
@additional_container_env_vars = opts[:additional_container_env_vars]
end
def cached_dependencies
return nil if @config.get(:diego, :enable_declarative_asset_downloads)
lifecycle_bundle_key = :"buildpack/#{@stack}"
lifecycle_bundle = @config.get(:diego, :lifecycle_bundles)[lifecycle_bundle_key]
raise InvalidStack.new("no compiler defined for requested stack '#{@stack}'") unless lifecycle_bundle
[
::Diego::Bbs::Models::CachedDependency.new(
from: LifecycleBundleUriGenerator.uri(lifecycle_bundle),
to: '/tmp/lifecycle',
cache_key: "buildpack-#{@stack}-lifecycle"
)
]
end
def root_fs
@stack_obj ||= Stack.find(name: @stack)
raise CloudController::Errors::ApiError.new_from_details('StackNotFound', @stack) unless @stack_obj
"preloaded:#{@stack_obj.run_rootfs_image}"
end
def setup
return nil if @config.get(:diego, :enable_declarative_asset_downloads) && @checksum_algorithm == 'sha256'
serial([
::Diego::Bbs::Models::DownloadAction.new({
artifact: 'droplet',
from: @droplet_uri,
to: '.',
cache_key: "droplets-#{@process_guid}",
user: action_user,
checksum_algorithm: @checksum_algorithm,
checksum_value: @checksum_value
}.compact)
])
end
def image_layers
return [] unless @config.get(:diego, :enable_declarative_asset_downloads)
lifecycle_bundle_key = :"buildpack/#{@stack}"
lifecycle_bundle = @config.get(:diego, :lifecycle_bundles)[lifecycle_bundle_key]
raise InvalidStack.new("no compiler defined for requested stack '#{@stack}'") unless lifecycle_bundle
destination = @config.get(:diego, :droplet_destinations)[@stack.to_sym]
raise InvalidStack.new("no droplet destination defined for requested stack '#{@stack}'") unless destination
layers = [
::Diego::Bbs::Models::ImageLayer.new(
name: "buildpack-#{@stack}-lifecycle",
url: LifecycleBundleUriGenerator.uri(lifecycle_bundle),
destination_path: '/tmp/lifecycle',
layer_type: ::Diego::Bbs::Models::ImageLayer::Type::SHARED,
media_type: ::Diego::Bbs::Models::ImageLayer::MediaType::TGZ
)
]
if @checksum_algorithm == 'sha256'
layers << ::Diego::Bbs::Models::ImageLayer.new({
name: 'droplet',
url: UriUtils.uri_escape(@droplet_uri),
destination_path: destination,
layer_type: ::Diego::Bbs::Models::ImageLayer::Type::EXCLUSIVE,
media_type: ::Diego::Bbs::Models::ImageLayer::MediaType::TGZ,
digest_value: @checksum_value,
digest_algorithm: ::Diego::Bbs::Models::ImageLayer::DigestAlgorithm::SHA256
}.compact)
end
layers
end
def global_environment_variables
[::Diego::Bbs::Models::EnvironmentVariable.new(name: 'LANG', value: DEFAULT_LANG)] + @additional_container_env_vars
end
def ports
return @ports if @ports.present?
[DEFAULT_APP_PORT]
end
def port_environment_variables
[
::Diego::Bbs::Models::EnvironmentVariable.new(name: 'PORT', value: ports.first.to_s),
::Diego::Bbs::Models::EnvironmentVariable.new(name: 'VCAP_APP_PORT', value: ports.first.to_s),
::Diego::Bbs::Models::EnvironmentVariable.new(name: 'VCAP_APP_HOST', value: '0.0.0.0')
]
end
def privileged?
@config.get(:diego, :use_privileged_containers_for_running)
end
end
end
end
end