Class: Putpaws::Provision::Resources::Service
- Inherits:
-
Base
- Object
- Base
- Putpaws::Provision::Resources::Service
show all
- Defined in:
- lib/putpaws/provision/resources/service.rb
Instance Attribute Summary
Attributes inherited from Base
#clients, #config, #state
Instance Method Summary
collapse
Methods inherited from Base
#ensure!, #initialize, #kind, #plan
Instance Method Details
#changed?(current) ⇒ Boolean
30
31
32
33
|
# File 'lib/putpaws/provision/resources/service.rb', line 30
def changed?(current)
current_family = current.task_definition.to_s.split('/').last.to_s.split(':').first
current_family != task_definition_family || current.desired_count != desired_count
end
|
#create! ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/putpaws/provision/resources/service.rb', line 35
def create!
res = clients.ecs.create_service(
cluster: config.cluster_name,
service_name: name,
task_definition: task_definition_family,
desired_count: desired_count,
launch_type: 'FARGATE',
enable_execute_command: true,
network_configuration: {
awsvpc_configuration: {
subnets: config.base[:subnets],
security_groups: security_group_ids,
assign_public_ip: config.settings[:assign_public_ip] || 'DISABLED',
}
},
tags: [MANAGED_TAG]
)
{service_arn: res.service.service_arn, service_name: name}
end
|
#current ⇒ Object
25
26
27
28
|
# File 'lib/putpaws/provision/resources/service.rb', line 25
def current
res = clients.ecs.describe_services(cluster: config.cluster_name, services: [name])
res.services.detect{|s| s.status == 'ACTIVE'}
end
|
#desired_count ⇒ Object
11
12
13
|
# File 'lib/putpaws/provision/resources/service.rb', line 11
def desired_count
(config.settings[:desired_count] || 1).to_i
end
|
#name ⇒ Object
7
8
9
|
# File 'lib/putpaws/provision/resources/service.rb', line 7
def name
config.service_name
end
|
#outputs(current) ⇒ Object
65
66
67
|
# File 'lib/putpaws/provision/resources/service.rb', line 65
def outputs(current)
{service_arn: current.service_arn, service_name: name}
end
|
#security_group_ids ⇒ Object
19
20
21
22
23
|
# File 'lib/putpaws/provision/resources/service.rb', line 19
def security_group_ids
ids = state.resources[:security_group_ids]
raise "security_group_ids not found in state. Run the security group step first." if ids.nil? || ids.empty?
ids
end
|
#task_definition_family ⇒ Object
15
16
17
|
# File 'lib/putpaws/provision/resources/service.rb', line 15
def task_definition_family
config.service_task_definition_family
end
|
#update!(_current) ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File 'lib/putpaws/provision/resources/service.rb', line 55
def update!(_current)
res = clients.ecs.update_service(
cluster: config.cluster_name,
service: name,
task_definition: task_definition_family,
desired_count: desired_count
)
{service_arn: res.service.service_arn, service_name: name}
end
|