putpaws 0.0.1 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/Putpawsfile +2 -1
- data/lib/putpaws/all.rb +1 -0
- data/lib/putpaws/application_config.rb +14 -0
- data/lib/putpaws/cloud_watch/log_command.rb +6 -2
- data/lib/putpaws/cloud_watch/tasks/log_task.rake +11 -4
- data/lib/putpaws/ecs/task_command.rb +3 -1
- data/lib/putpaws/ecs/tasks/ecs_task.rake +3 -3
- data/lib/putpaws/infra_network_config.rb +31 -0
- data/lib/putpaws/infra_target_config.rb +35 -0
- data/lib/putpaws/prompt.rb +9 -0
- data/lib/putpaws/schedule_config.rb +54 -0
- data/lib/putpaws/scheduler/schedule_command.rb +62 -0
- data/lib/putpaws/scheduler/scheduler_task.rb +1 -0
- data/lib/putpaws/scheduler/tasks/scheduler_task.rake +29 -0
- data/lib/putpaws/version.rb +1 -1
- metadata +35 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc81dde13186441af99e515508a418fddfda5abac1636ef734ca05b5796df3a7
|
4
|
+
data.tar.gz: fd003a6a360a6859026f8003471d5755645dcca68e359f6d16de91f16eb2e483
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d119637b098227c69d9c96eb258e9c0a04cd5a1a67840a5006a76014c7deca0ef3c6e750b9e2aa2791b5703eebcbdc4475548dafdcf97f145eed9ab9872d4ec
|
7
|
+
data.tar.gz: e7e6bf5cb5a343a23285dfed9c849267f421170406a9e437a3aee614455f756ebb15ffcf50447e9dd88d7f6f95f7aab4fcf710ffeab6fb788bc4b0af26915dcb
|
data/lib/Putpawsfile
CHANGED
data/lib/putpaws/all.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'pathname'
|
3
|
+
require "putpaws/schedule_config"
|
3
4
|
|
4
5
|
class Putpaws::ApplicationConfig < Struct.new(
|
5
6
|
:name, :region,
|
6
7
|
:cluster, :service, :task_name_prefix, :ecs_region,
|
7
8
|
:log_group_prefix, :log_region,
|
9
|
+
:build_project, :build_log_group_prefix, :build_region,
|
10
|
+
:schedules,
|
8
11
|
keyword_init: true)
|
9
12
|
def self.load(path_prefix: '.putpaws')
|
10
13
|
@application_data ||= begin
|
@@ -45,4 +48,15 @@ class Putpaws::ApplicationConfig < Struct.new(
|
|
45
48
|
log_group_prefix: log_group_prefix,
|
46
49
|
}
|
47
50
|
end
|
51
|
+
|
52
|
+
def build_log_command_params
|
53
|
+
{
|
54
|
+
region: build_region || region,
|
55
|
+
log_group_prefix: build_log_group_prefix,
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def schedules
|
60
|
+
@schedules ||= (self[:schedules] || []).map{|x| Putpaws::ScheduleConfig.find(x)}.compact
|
61
|
+
end
|
48
62
|
end
|
@@ -10,8 +10,12 @@ module Putpaws::CloudWatch
|
|
10
10
|
'w' => 60 * 60 * 24 * 7,
|
11
11
|
}
|
12
12
|
|
13
|
-
def self.config(config)
|
14
|
-
|
13
|
+
def self.config(config, type: "default")
|
14
|
+
if type == "build"
|
15
|
+
new(config.build_log_command_params)
|
16
|
+
else
|
17
|
+
new(config.log_command_params)
|
18
|
+
end
|
15
19
|
end
|
16
20
|
|
17
21
|
def self.parse_unit_time(ut)
|
@@ -1,20 +1,27 @@
|
|
1
|
-
require "
|
1
|
+
require "putpaws/prompt"
|
2
2
|
require "putpaws/cloud_watch/log_command"
|
3
3
|
require "putpaws/cloud_watch/default_log_formatter"
|
4
4
|
|
5
5
|
namespace :log do
|
6
6
|
desc "Set Log Group."
|
7
7
|
task :set_log_group do
|
8
|
-
|
8
|
+
app = fetch(:app)
|
9
|
+
prompt = Putpaws::Prompt.safe
|
10
|
+
log_type = if app.build_log_group_prefix
|
11
|
+
prompt.select("Choose log type", ["default", "build"])
|
12
|
+
else
|
13
|
+
"default"
|
14
|
+
end
|
15
|
+
aws = Putpaws::CloudWatch::LogCommand.config(app, type: log_type)
|
16
|
+
|
9
17
|
log_groups = aws.list_log_groups.map{|a|
|
10
18
|
[a.log_group_name, a]
|
11
19
|
}.to_h
|
12
20
|
raise "Log group not found on your permission" if log_groups.empty?
|
13
21
|
|
14
22
|
log_group = if log_groups.length == 1
|
15
|
-
log_groups.first
|
23
|
+
log_groups.values.first
|
16
24
|
else
|
17
|
-
prompt = TTY::Prompt.new
|
18
25
|
selected = prompt.select("Choose a log_group you're going to operate", log_groups.keys)
|
19
26
|
log_groups[selected]
|
20
27
|
end
|
@@ -40,6 +40,8 @@ module Putpaws::Ecs
|
|
40
40
|
task: ecs_task.task_arn,
|
41
41
|
})
|
42
42
|
|
43
|
+
ssm_region = ENV['AWS_REGION_SSM'] || @region
|
44
|
+
|
43
45
|
# https://github.com/aws/aws-cli/blob/2a6136010d8656a605d41d1e7b5fdab3c2930cad/awscli/customizations/ecs/executecommand.py#L105
|
44
46
|
session_json = {
|
45
47
|
"SessionId" => res.session.session_id,
|
@@ -56,7 +58,7 @@ module Putpaws::Ecs
|
|
56
58
|
"StartSession",
|
57
59
|
'test',
|
58
60
|
target_json.dump,
|
59
|
-
"https://ssm.
|
61
|
+
"https://ssm.#{ssm_region}.amazonaws.com"
|
60
62
|
]
|
61
63
|
cmd.join(' ')
|
62
64
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "putpaws/prompt"
|
2
2
|
require "putpaws/ecs/task_command"
|
3
3
|
|
4
4
|
namespace :ecs do
|
@@ -10,14 +10,14 @@ namespace :ecs do
|
|
10
10
|
task_def = t.task_definition_arn.split('/').last
|
11
11
|
["#{task_id} (#{task_def}) #{t.last_status}", t]
|
12
12
|
}.to_h
|
13
|
-
prompt =
|
13
|
+
prompt = Putpaws::Prompt.safe
|
14
14
|
selected = prompt.select("Choose a task you're going to operate", ecs_tasks.keys)
|
15
15
|
ecs_task = ecs_tasks[selected]
|
16
16
|
|
17
17
|
set :ecs_task, ecs_task
|
18
18
|
end
|
19
19
|
|
20
|
-
desc "Attach on ECS task. You need to enable ECS Exec on a specified task."
|
20
|
+
desc "Attach on ECS task. You need to enable ECS Exec on a specified task and also install session-manager-plugin."
|
21
21
|
task attach: :set_task do
|
22
22
|
ecs_task = fetch(:ecs_task)
|
23
23
|
aws = Putpaws::Ecs::TaskCommand.config(fetch(:app))
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
class Putpaws::InfraNetworkConfig < Struct.new(
|
5
|
+
:name, :subnets, :security_groups, :assign_public_ip,
|
6
|
+
keyword_init: true)
|
7
|
+
def self.load(path_prefix: '.putpaws')
|
8
|
+
@infra_network_data ||= begin
|
9
|
+
path = Pathname.new(path_prefix).join("infra.json").to_s
|
10
|
+
data = File.exists?(path) ?
|
11
|
+
JSON.parse(File.read(path), symbolize_names: true).to_h :
|
12
|
+
{}
|
13
|
+
data[:network] || {}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.all
|
18
|
+
load.map{|k,v|
|
19
|
+
data = v.slice(*self.members)
|
20
|
+
new(data.merge(name: k.to_s))
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.find(name)
|
25
|
+
infra_network_data = load
|
26
|
+
data = infra_network_data[name.to_sym]
|
27
|
+
return nil unless data
|
28
|
+
data = data.slice(*self.members)
|
29
|
+
new(data.merge({name: name.to_s}))
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
class Putpaws::InfraTargetConfig < Struct.new(
|
5
|
+
:name,
|
6
|
+
:scheduler_role,
|
7
|
+
:cluster,
|
8
|
+
:task_definition,
|
9
|
+
:container_name,
|
10
|
+
keyword_init: true)
|
11
|
+
def self.load(path_prefix: '.putpaws')
|
12
|
+
@infra_target_data ||= begin
|
13
|
+
path = Pathname.new(path_prefix).join("infra.json").to_s
|
14
|
+
data = File.exists?(path) ?
|
15
|
+
JSON.parse(File.read(path), symbolize_names: true).to_h :
|
16
|
+
{}
|
17
|
+
data[:target] || {}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.all
|
22
|
+
load.map{|k,v|
|
23
|
+
data = v.slice(*self.members)
|
24
|
+
new(data.merge(name: k.to_s))
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.find(name)
|
29
|
+
infra_target_data = load
|
30
|
+
data = infra_target_data[name.to_sym]
|
31
|
+
return nil unless data
|
32
|
+
data = data.slice(*self.members)
|
33
|
+
new(data.merge({name: name.to_s}))
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'pathname'
|
3
|
+
require 'putpaws/infra_network_config'
|
4
|
+
require 'putpaws/infra_target_config'
|
5
|
+
|
6
|
+
class Putpaws::ScheduleConfig < Struct.new(
|
7
|
+
:name, :region, :network, :target, :command, :args,
|
8
|
+
keyword_init: true)
|
9
|
+
def self.load(path_prefix: '.putpaws')
|
10
|
+
@schedule_data ||= begin
|
11
|
+
path = Pathname.new(path_prefix).join("schedule.json").to_s
|
12
|
+
data = File.exists?(path) ?
|
13
|
+
JSON.parse(File.read(path), symbolize_names: true).to_h :
|
14
|
+
{}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.build_args(name, config_args)
|
19
|
+
region = config_args.delete(:region)
|
20
|
+
network = config_args.delete(:network)
|
21
|
+
target = config_args.delete(:target)
|
22
|
+
command = config_args.delete(:command)
|
23
|
+
{
|
24
|
+
name: name.to_s,
|
25
|
+
region: region,
|
26
|
+
network: network,
|
27
|
+
target: target,
|
28
|
+
command: command,
|
29
|
+
}.merge(args: config_args)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.all
|
33
|
+
load.map{|k,v|
|
34
|
+
new(build_args(k, v))
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.find(name)
|
39
|
+
schedule_data = load
|
40
|
+
data = schedule_data[name.to_sym]
|
41
|
+
return nil unless data
|
42
|
+
new(build_args(name, data))
|
43
|
+
end
|
44
|
+
|
45
|
+
def network
|
46
|
+
return nil unless self[:network]
|
47
|
+
@network ||= Putpaws::InfraNetworkConfig.find(self[:network])
|
48
|
+
end
|
49
|
+
|
50
|
+
def target
|
51
|
+
return nil unless self[:target]
|
52
|
+
@target ||= Putpaws::InfraTargetConfig.find(self[:target])
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'aws-sdk-scheduler'
|
2
|
+
|
3
|
+
module Putpaws::Scheduler
|
4
|
+
class ScheduleCommand
|
5
|
+
def self.config(config)
|
6
|
+
new(config.log_command_params)
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :client
|
10
|
+
attr_reader :config, :network, :target
|
11
|
+
|
12
|
+
def initialize(schedule_config)
|
13
|
+
@config = schedule_config
|
14
|
+
@network = config.network
|
15
|
+
@target = config.target
|
16
|
+
@client = Aws::Scheduler::Client.new({region: config.region})
|
17
|
+
end
|
18
|
+
|
19
|
+
def generated_params
|
20
|
+
{
|
21
|
+
name: config.name,
|
22
|
+
flexible_time_window: {mode: "OFF"},
|
23
|
+
target: {
|
24
|
+
arn: target.cluster,
|
25
|
+
role_arn: target.scheduler_role,
|
26
|
+
retry_policy: {maximum_retry_attempts: 0},
|
27
|
+
input: {
|
28
|
+
containerOverrides: [
|
29
|
+
{
|
30
|
+
name: target.container_name,
|
31
|
+
command: config.command,
|
32
|
+
}
|
33
|
+
]
|
34
|
+
}.to_json,
|
35
|
+
ecs_parameters: {
|
36
|
+
launch_type: "FARGATE",
|
37
|
+
network_configuration: {
|
38
|
+
awsvpc_configuration: {
|
39
|
+
subnets: network.subnets,
|
40
|
+
security_groups: network.security_groups,
|
41
|
+
assign_public_ip: network.assign_public_ip,
|
42
|
+
}
|
43
|
+
},
|
44
|
+
task_definition_arn: target.task_definition,
|
45
|
+
task_count: 1, }
|
46
|
+
}
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def deploy!
|
51
|
+
# TODO: Use deep merge here
|
52
|
+
args = generated_params.merge(config.args)
|
53
|
+
|
54
|
+
begin
|
55
|
+
res = client.get_schedule(name: config.name)
|
56
|
+
client.update_schedule(args)
|
57
|
+
rescue Aws::Scheduler::Errors::ResourceNotFoundException => e
|
58
|
+
client.create_schedule(args)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path("../tasks/scheduler_task.rake", __FILE__)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "putpaws/prompt"
|
2
|
+
require "putpaws/schedule_config"
|
3
|
+
require "putpaws/scheduler/schedule_command"
|
4
|
+
|
5
|
+
namespace :scheduler do
|
6
|
+
desc "Select Schedule to Manage."
|
7
|
+
task :set_schedule_config do
|
8
|
+
app = fetch(:app)
|
9
|
+
schedules = (app.schedules && !app.schedules.empty?) ? app.schedules : []
|
10
|
+
if schedules.empty?
|
11
|
+
schedule_options = Putpaws::ScheduleConfig.all.map(&:name)
|
12
|
+
raise "Please set `schedules` at .putpaws/schedule.json\nFollowing schedules available:\n#{schedule_options.to_json}\n"
|
13
|
+
end
|
14
|
+
|
15
|
+
prompt = Putpaws::Prompt.safe
|
16
|
+
selected = prompt.select("Choose a task you're going to operate", schedules.map(&:name))
|
17
|
+
schedule_config = schedules.find{|x| x.name == selected}
|
18
|
+
|
19
|
+
set :schedule_config, schedule_config
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Deploy schedule."
|
23
|
+
task deploy: :set_schedule_config do
|
24
|
+
schedule_config = fetch(:schedule_config)
|
25
|
+
# pp schedule_config
|
26
|
+
aws = Putpaws::Scheduler::ScheduleCommand.new(schedule_config)
|
27
|
+
aws.deploy!
|
28
|
+
end
|
29
|
+
end
|
data/lib/putpaws/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: putpaws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- metheglin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -28,44 +28,58 @@ dependencies:
|
|
28
28
|
name: tty-prompt
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0
|
33
|
+
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: aws-sdk-ecs
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: aws-sdk-cloudwatchlogs
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: aws-sdk-scheduler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '0'
|
69
83
|
description: aws fargate based infra management
|
70
84
|
email: pigmybank@gmail.com
|
71
85
|
executables:
|
@@ -89,6 +103,13 @@ files:
|
|
89
103
|
- lib/putpaws/ecs/tasks/ecs_task.rake
|
90
104
|
- lib/putpaws/env.rb
|
91
105
|
- lib/putpaws/hello.rb
|
106
|
+
- lib/putpaws/infra_network_config.rb
|
107
|
+
- lib/putpaws/infra_target_config.rb
|
108
|
+
- lib/putpaws/prompt.rb
|
109
|
+
- lib/putpaws/schedule_config.rb
|
110
|
+
- lib/putpaws/scheduler/schedule_command.rb
|
111
|
+
- lib/putpaws/scheduler/scheduler_task.rb
|
112
|
+
- lib/putpaws/scheduler/tasks/scheduler_task.rake
|
92
113
|
- lib/putpaws/setup.rb
|
93
114
|
- lib/putpaws/tasks/hello.rake
|
94
115
|
- lib/putpaws/version.rb
|