kybus-cli 0.1.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/kybus/aws/code_packager.rb +36 -34
- data/lib/kybus/aws/lambda.rb +63 -106
- data/lib/kybus/aws/lambda_trigger.rb +71 -0
- data/lib/kybus/aws/layer_manager.rb +58 -0
- data/lib/kybus/aws/queue.rb +98 -0
- data/lib/kybus/aws/resource.rb +2 -0
- data/lib/kybus/aws/zip_creator.rb +71 -0
- data/lib/kybus/aws.rb +1 -0
- data/lib/kybus/cli/bot/deployer.rb +4 -1
- data/lib/kybus/cli/bot/deployers/aws_bot_deployer.rb +110 -64
- data/lib/kybus/cli/bot/deployers/aws_bot_job_runner_deployer.rb +30 -0
- data/lib/kybus/cli/bot/deployers/telegram_configurator.rb +6 -1
- data/lib/kybus/cli/bot/file_providers/composefile_generator.rb +26 -23
- data/lib/kybus/cli/bot/file_providers/config_default_generator.rb +20 -14
- data/lib/kybus/cli/bot/file_providers/config_generator.rb +22 -16
- data/lib/kybus/cli/bot/file_providers/db_generator.rb +32 -33
- data/lib/kybus/cli/bot/project_generator.rb +11 -1
- data/lib/kybus/cli/ssl.rb +65 -0
- data/lib/kybus/cli/version.rb +3 -0
- data/lib/kybus/cli.rb +13 -0
- metadata +31 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3103d3aeaedc50e8bd321cd103bd2f1b2aa42ddddda7dcceba146aa016ea687c
|
4
|
+
data.tar.gz: f1c1f730b4ed14b631e5b8773bfa506859fc60e121c3588bbe835e84dc8a861a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2901d1d9f717a1838ed670f0eacf24c4d3c0dd96a160ea7f082ae28506d1d399df3de8af5a0b4d41fc7fe3f8a53774a061e54bc53208650134f1efc1eab11b4
|
7
|
+
data.tar.gz: b83a368aa834d44fcd1175756ee147047ed16bedd8d894ab5f39edb42074f5988ab917edf4bacf00b63e9be059a6f75272072936fd73d2d3c4f0fe82c4911aaf
|
@@ -1,47 +1,49 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'digest'
|
4
|
+
require_relative 'zip_creator'
|
5
|
+
|
3
6
|
module Kybus
|
4
7
|
module AWS
|
5
8
|
class CodePackager < Resource
|
6
9
|
def create_or_update!
|
7
|
-
ruby_version =
|
8
|
-
|
9
|
-
|
10
|
-
'test', 'Gemfile*', 'Rakefile', '.gitignore', '.bundle', '.git', '.deps.zip', '.kybuscode.zip', 'kybusbot.yaml', 'vendor', '.ruby-version'
|
11
|
-
], extra_files: { '.bundle/config' => 'BUNDLE_PATH: "/opt/vendor/bundle"' }, zip_root: '.')
|
10
|
+
ruby_version = fetch_ruby_version
|
11
|
+
create_deps_zip(ruby_version)
|
12
|
+
create_code_zip(ruby_version)
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
extra_files.each do |entry, contents|
|
21
|
-
zipfile.get_output_stream(entry) { |f| f.puts(contents) }
|
22
|
-
end
|
23
|
-
|
24
|
-
entries.each do |entry|
|
25
|
-
entry_path = File.join(directory, entry)
|
26
|
-
next if exclude_files.any? { |pattern| File.fnmatch(pattern, entry) || File.fnmatch(pattern, entry_path) }
|
27
|
-
|
28
|
-
puts "Adding #{entry} to #{zip_name}"
|
29
|
-
|
30
|
-
if File.directory?(entry_path)
|
31
|
-
zipfile.mkdir("#{zip_root}#{entry_path.sub(directory, '')}")
|
32
|
-
Dir[File.join(entry_path, '**', '**')].each do |file|
|
33
|
-
next if exclude_files.any? { |pattern| File.fnmatch(pattern, file) }
|
34
|
-
|
35
|
-
zipfile.add("#{zip_root}#{file.sub(directory, '')}", file)
|
36
|
-
end
|
37
|
-
else
|
38
|
-
zipfile.add("#{zip_root}#{entry_path.sub(directory, '')}", entry_path)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
15
|
+
def destroy!; end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def fetch_ruby_version
|
20
|
+
"#{RUBY_VERSION.split('.')[0..1].join('.')}.0"
|
42
21
|
end
|
43
22
|
|
44
|
-
def
|
23
|
+
def create_deps_zip(ruby_version)
|
24
|
+
ZipCreator.new(
|
25
|
+
'.deps.zip',
|
26
|
+
"vendor/bundle/ruby/#{ruby_version}",
|
27
|
+
zip_root: "ruby/gems/#{ruby_version}"
|
28
|
+
).create_zip
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_code_zip(_ruby_version)
|
32
|
+
ZipCreator.new(
|
33
|
+
'.kybuscode.zip',
|
34
|
+
@config['repo_path'],
|
35
|
+
exclude_files: excluded_files,
|
36
|
+
extra_files: { '.bundle/config' => 'BUNDLE_PATH: "/opt/vendor/bundle"' },
|
37
|
+
zip_root: '.'
|
38
|
+
).create_zip
|
39
|
+
end
|
40
|
+
|
41
|
+
def excluded_files
|
42
|
+
[
|
43
|
+
'test', 'Gemfile*', 'Rakefile', '.gitignore', '.bundle', '.git', '.deps.zip',
|
44
|
+
'.kybuscode.zip', 'kybusbot.yaml', 'vendor', '.ruby-version'
|
45
|
+
]
|
46
|
+
end
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
data/lib/kybus/aws/lambda.rb
CHANGED
@@ -1,158 +1,115 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'digest'
|
4
|
-
|
5
|
-
|
6
|
-
md5 = Digest::MD5.new
|
7
|
-
File.open(file_path, 'rb') do |file|
|
8
|
-
buffer = String.new
|
9
|
-
md5.update(buffer) while file.read(4096, buffer)
|
10
|
-
end
|
11
|
-
md5.hexdigest
|
12
|
-
end
|
4
|
+
require_relative 'layer_manager'
|
5
|
+
require_relative 'lambda_trigger'
|
13
6
|
|
14
7
|
module Kybus
|
15
8
|
module AWS
|
16
9
|
class Lambda < Resource
|
17
|
-
attr_reader :
|
10
|
+
attr_reader :name
|
18
11
|
|
19
12
|
def initialize(configs, name)
|
20
13
|
super(configs)
|
21
14
|
@name = name
|
15
|
+
@layers = configs['layers']
|
16
|
+
@triggers = configs['triggers']
|
17
|
+
@layer_manager = LayerManager.new(lambda_client, function_name)
|
18
|
+
@trigger_manager = LambdaTrigger.new(lambda_client, function_name, @triggers)
|
22
19
|
end
|
23
20
|
|
24
21
|
def lambda_client
|
25
22
|
@lambda_client ||= Aws::Lambda::Client.new(region: @region)
|
26
23
|
end
|
27
24
|
|
25
|
+
def url
|
26
|
+
@trigger_manager.url
|
27
|
+
end
|
28
|
+
|
28
29
|
def function_name
|
29
30
|
@name
|
30
31
|
end
|
31
32
|
|
32
33
|
def deploy_lambda!
|
33
|
-
|
34
|
+
layer_arns = @layers.map { |layer| handle_layer(layer) }
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
rescue StandardError
|
38
|
-
false
|
39
|
-
end
|
40
|
-
|
41
|
-
if function_exists
|
42
|
-
update_lambda!(layer_arn_deps)
|
36
|
+
if lambda_function_exists?
|
37
|
+
update_lambda!(layer_arns)
|
43
38
|
else
|
44
|
-
create_lambda!(
|
39
|
+
create_lambda!(layer_arns)
|
45
40
|
end
|
46
41
|
end
|
47
42
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
},
|
54
|
-
description: zipfile_hash,
|
55
|
-
compatible_runtimes: ["ruby3.3"]
|
56
|
-
})
|
57
|
-
puts "Layer '#{layer_name}' created: #{response.layer_version_arn}"
|
58
|
-
response.layer_version_arn
|
59
|
-
end
|
43
|
+
def handle_layer(layer)
|
44
|
+
puts "Processing layer:\n#{layer.to_yaml}"
|
45
|
+
case layer['type']
|
46
|
+
when 'codezip'
|
47
|
+
raise 'Checksum file required for codezip layer' unless layer['checksumfile']
|
60
48
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
max_items: 1
|
66
|
-
})
|
67
|
-
|
68
|
-
response.layer_versions.first
|
69
|
-
end
|
49
|
+
@layer_manager.create_or_update_layer(layer['zipfile'], layer['name'], layer['checksumfile'])
|
50
|
+
when 'existing'
|
51
|
+
layer_arn = @layer_manager.get_layer_arn(layer['name'])
|
52
|
+
raise "Layer #{layer['name']} not found" unless layer_arn
|
70
53
|
|
71
|
-
|
72
|
-
|
73
|
-
if !layer_exists || layer_exists.description != zipfile_hash
|
74
|
-
create_layer(zip_file, layer_name, zipfile_hash)
|
54
|
+
layer_arn
|
75
55
|
else
|
76
|
-
|
77
|
-
layer_exists.layer_version_arn
|
56
|
+
raise "Unknown layer type: #{layer['type']}"
|
78
57
|
end
|
79
58
|
end
|
80
59
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
environment: {
|
88
|
-
variables: {
|
89
|
-
'SECRET_TOKEN' => @config['secret_token']
|
90
|
-
}
|
91
|
-
}
|
92
|
-
})
|
93
|
-
end
|
60
|
+
def lambda_function_exists?
|
61
|
+
lambda_client.get_function(function_name:)
|
62
|
+
true
|
63
|
+
rescue Aws::Lambda::Errors::ResourceNotFoundException
|
64
|
+
false
|
65
|
+
end
|
94
66
|
|
95
|
-
|
96
|
-
|
97
|
-
|
67
|
+
def update_lambda!(layer_arns)
|
68
|
+
update_function_configuration(layer_arns)
|
69
|
+
update_function_code
|
98
70
|
puts "Lambda function '#{function_name}' updated."
|
99
71
|
end
|
100
72
|
|
101
|
-
def
|
73
|
+
def update_function_configuration(layer_arns)
|
102
74
|
with_retries(Aws::Lambda::Errors::ResourceConflictException) do
|
103
|
-
lambda_client.
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
code: {
|
110
|
-
zip_file: File.read('.kybuscode.zip')
|
111
|
-
},
|
112
|
-
timeout: @config['timeout'] || 3,
|
113
|
-
environment: {
|
114
|
-
variables: {
|
115
|
-
'SECRET_TOKEN' => @config['secret_token']
|
116
|
-
}
|
117
|
-
}
|
118
|
-
})
|
119
|
-
puts "Lambda function '#{function_name}' created."
|
75
|
+
lambda_client.update_function_configuration(
|
76
|
+
function_name:,
|
77
|
+
layers: layer_arns,
|
78
|
+
timeout: @config['timeout'] || 3,
|
79
|
+
environment: { variables: { 'SECRET_TOKEN' => @config['secret_token'] } }
|
80
|
+
)
|
120
81
|
end
|
121
82
|
end
|
122
83
|
|
123
|
-
def
|
84
|
+
def update_function_code
|
124
85
|
with_retries(Aws::Lambda::Errors::ResourceConflictException) do
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
puts "Function URL created: #{response.function_url}"
|
130
|
-
@url = response.function_url
|
131
|
-
rescue Aws::Lambda::Errors::ResourceConflictException
|
132
|
-
response = lambda_client.get_function_url_config({
|
133
|
-
function_name:
|
134
|
-
})
|
135
|
-
puts "Function URL exists: #{response.function_url}"
|
136
|
-
@url = response.function_url
|
86
|
+
lambda_client.update_function_code(
|
87
|
+
function_name:,
|
88
|
+
zip_file: File.read('.kybuscode.zip')
|
89
|
+
)
|
137
90
|
end
|
91
|
+
end
|
138
92
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
93
|
+
def create_lambda!(layer_arns)
|
94
|
+
with_retries(Aws::Lambda::Errors::ResourceConflictException) do
|
95
|
+
puts "Creating function #{function_name} with role: #{"arn:aws:iam::#{account_id}:role/#{function_name}"}"
|
96
|
+
lambda_client.create_function(
|
97
|
+
function_name:,
|
98
|
+
runtime: 'ruby3.3',
|
99
|
+
role: "arn:aws:iam::#{account_id}:role/#{function_name}",
|
100
|
+
handler: @config['handler'] || 'handler.lambda_handler',
|
101
|
+
layers: layer_arns,
|
102
|
+
code: { zip_file: File.read('.kybuscode.zip') },
|
103
|
+
timeout: @config['timeout'] || 3,
|
104
|
+
environment: { variables: { 'SECRET_TOKEN' => @config['secret_token'] } }
|
105
|
+
)
|
106
|
+
puts "Lambda function '#{function_name}' created."
|
150
107
|
end
|
151
108
|
end
|
152
109
|
|
153
110
|
def create_or_update!
|
154
111
|
deploy_lambda!
|
155
|
-
|
112
|
+
@trigger_manager.add_triggers
|
156
113
|
end
|
157
114
|
|
158
115
|
def destroy!
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kybus
|
4
|
+
module AWS
|
5
|
+
class LambdaTrigger
|
6
|
+
attr_reader :url
|
7
|
+
|
8
|
+
def initialize(lambda_client, function_name, triggers)
|
9
|
+
@lambda_client = lambda_client
|
10
|
+
@function_name = function_name
|
11
|
+
@triggers = triggers
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_triggers
|
15
|
+
@triggers.each do |trigger|
|
16
|
+
case trigger['type']
|
17
|
+
when 'url'
|
18
|
+
create_function_url(trigger['public'])
|
19
|
+
when 'sqs'
|
20
|
+
add_sqs_trigger(trigger['queue_arn'])
|
21
|
+
else
|
22
|
+
raise "Unknown trigger type: #{trigger['type']}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def create_function_url(is_public)
|
30
|
+
@url = begin
|
31
|
+
@lambda_client.create_function_url_config(function_name: @function_name, auth_type: 'NONE')
|
32
|
+
rescue Aws::Lambda::Errors::ResourceConflictException
|
33
|
+
@lambda_client.get_function_url_config(function_name: @function_name)
|
34
|
+
end.function_url
|
35
|
+
puts "Function URL created: #{@url}"
|
36
|
+
|
37
|
+
return unless is_public
|
38
|
+
|
39
|
+
add_public_permission
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_public_permission
|
43
|
+
response = @lambda_client.add_permission(
|
44
|
+
function_name: @function_name,
|
45
|
+
statement_id: 'AllowPublicInvoke',
|
46
|
+
action: 'lambda:InvokeFunctionUrl',
|
47
|
+
principal: '*',
|
48
|
+
function_url_auth_type: 'NONE'
|
49
|
+
)
|
50
|
+
puts "Permission added successfully: #{response}"
|
51
|
+
rescue Aws::Lambda::Errors::ServiceError => e
|
52
|
+
puts "Error adding permission: #{e.message}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_sqs_trigger(queue_arn)
|
56
|
+
raise("Invalid ARN for queue: #{queue_arn}") if queue_arn.nil?
|
57
|
+
|
58
|
+
puts "Adding trigger for lambda: #{@function_name} with sqs #{queue_arn}"
|
59
|
+
@lambda_client.create_event_source_mapping({
|
60
|
+
event_source_arn: queue_arn,
|
61
|
+
function_name: @function_name,
|
62
|
+
enabled: true,
|
63
|
+
batch_size: 1
|
64
|
+
})
|
65
|
+
puts "SQS trigger added to Lambda function '#{@function_name}' for queue '#{queue_arn}'."
|
66
|
+
rescue Aws::Lambda::Errors::ResourceConflictException
|
67
|
+
puts 'SQS Trigger already exists'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'digest'
|
4
|
+
|
5
|
+
def calculate_md5(file_path)
|
6
|
+
md5 = Digest::MD5.new
|
7
|
+
File.open(file_path, 'rb') do |file|
|
8
|
+
buffer = String.new
|
9
|
+
md5.update(buffer) while file.read(4096, buffer)
|
10
|
+
end
|
11
|
+
md5.hexdigest
|
12
|
+
end
|
13
|
+
|
14
|
+
module Kybus
|
15
|
+
module AWS
|
16
|
+
class LayerManager
|
17
|
+
def initialize(lambda_client, function_name)
|
18
|
+
@lambda_client = lambda_client
|
19
|
+
@function_name = function_name
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_or_update_layer(zip_file, layer_name, checksum_file)
|
23
|
+
layer_exists = layer_version_exists?(layer_name)
|
24
|
+
zipfile_hash = calculate_md5(checksum_file)
|
25
|
+
|
26
|
+
if !layer_exists || layer_exists.description != zipfile_hash
|
27
|
+
create_layer(zip_file, layer_name, zipfile_hash)
|
28
|
+
else
|
29
|
+
puts "Layer unmodified: #{layer_name}"
|
30
|
+
layer_exists.layer_version_arn
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_layer(zip_file, layer_name, zipfile_hash)
|
35
|
+
response = @lambda_client.publish_layer_version(
|
36
|
+
layer_name:,
|
37
|
+
content: { zip_file: File.read(zip_file) },
|
38
|
+
description: zipfile_hash,
|
39
|
+
compatible_runtimes: ['ruby3.3']
|
40
|
+
)
|
41
|
+
puts "Layer '#{layer_name}' created: #{response.layer_version_arn}"
|
42
|
+
response.layer_version_arn
|
43
|
+
end
|
44
|
+
|
45
|
+
def layer_version_exists?(layer_name)
|
46
|
+
response = @lambda_client.list_layer_versions(layer_name:, max_items: 1)
|
47
|
+
response.layer_versions.first
|
48
|
+
rescue Aws::Lambda::Errors::ResourceNotFoundException
|
49
|
+
nil
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_layer_arn(layer_name)
|
53
|
+
layer_version = layer_version_exists?(layer_name)
|
54
|
+
layer_version&.layer_version_arn
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kybus
|
4
|
+
module AWS
|
5
|
+
class Queue < Resource
|
6
|
+
attr_reader :queue_url, :name
|
7
|
+
|
8
|
+
def initialize(configs, name)
|
9
|
+
require 'aws-sdk-sqs'
|
10
|
+
super(configs)
|
11
|
+
@name = name
|
12
|
+
end
|
13
|
+
|
14
|
+
def sqs_client
|
15
|
+
@sqs_client ||= Aws::SQS::Client.new(region: @region)
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_or_update!
|
19
|
+
create_queue!
|
20
|
+
make_write_policy.create_or_update!
|
21
|
+
make_processor_policy.create_or_update!
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_queue!
|
25
|
+
response = sqs_client.create_queue({
|
26
|
+
queue_name: name,
|
27
|
+
attributes: {
|
28
|
+
'DelaySeconds' => '0',
|
29
|
+
'MessageRetentionPeriod' => '86400'
|
30
|
+
}
|
31
|
+
})
|
32
|
+
@queue_url = response.queue_url
|
33
|
+
puts "Queue '#{name}' created with URL #{@queue_url}"
|
34
|
+
@queue_url
|
35
|
+
rescue Aws::SQS::Errors::QueueNameExists
|
36
|
+
@queue_url = sqs_client.get_queue_url(name:).queue_url
|
37
|
+
puts "Queue '#{name}' already exists with URL #{@queue_url}"
|
38
|
+
@queue_url
|
39
|
+
end
|
40
|
+
|
41
|
+
def destroy!
|
42
|
+
sqs_client.delete_queue(queue_url: @queue_url)
|
43
|
+
puts "Queue '#{name}' deleted."
|
44
|
+
rescue Aws::SQS::Errors::NonExistentQueue
|
45
|
+
puts "Queue '#{name}' not found."
|
46
|
+
end
|
47
|
+
|
48
|
+
def arn
|
49
|
+
"arn:aws:sqs:#{region}:#{account_id}:#{name}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def queue_write_policy_document
|
53
|
+
{
|
54
|
+
Version: '2012-10-17',
|
55
|
+
Statement: [
|
56
|
+
{
|
57
|
+
Effect: 'Allow',
|
58
|
+
Action: [
|
59
|
+
'sqs:Get*',
|
60
|
+
'sqs:SendMessage'
|
61
|
+
],
|
62
|
+
Resource: [
|
63
|
+
arn
|
64
|
+
]
|
65
|
+
}
|
66
|
+
]
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def queue_processor_policy_document
|
71
|
+
{
|
72
|
+
Version: '2012-10-17',
|
73
|
+
Statement: [{
|
74
|
+
Effect: 'Allow',
|
75
|
+
Action: [
|
76
|
+
'sqs:ReceiveMessage',
|
77
|
+
'sqs:SendMessage',
|
78
|
+
'sqs:Get*',
|
79
|
+
'sqs:DeleteMEssage',
|
80
|
+
'sqs:ChangeMessageVisibility'
|
81
|
+
],
|
82
|
+
Resource: [arn]
|
83
|
+
}]
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def make_write_policy
|
88
|
+
policy_name = "#{name}_queue_publisher"
|
89
|
+
@make_write_policy ||= Policy.new(@config, policy_name, queue_write_policy_document)
|
90
|
+
end
|
91
|
+
|
92
|
+
def make_processor_policy
|
93
|
+
policy_name = "#{name}_queue_processor"
|
94
|
+
@make_processor_policy ||= Policy.new(@config, policy_name, queue_processor_policy_document)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/kybus/aws/resource.rb
CHANGED
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'zip'
|
4
|
+
require 'fileutils'
|
5
|
+
module Kybus
|
6
|
+
module AWS
|
7
|
+
class ZipCreator
|
8
|
+
def initialize(zip_name, directory, exclude_files: [], extra_files: {}, zip_root: '')
|
9
|
+
@zip_name = zip_name
|
10
|
+
@directory = directory
|
11
|
+
@exclude_files = exclude_files
|
12
|
+
@extra_files = extra_files
|
13
|
+
@zip_root = zip_root
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_zip
|
17
|
+
FileUtils.rm(@zip_name, force: true)
|
18
|
+
entries = fetch_entries
|
19
|
+
|
20
|
+
Zip::File.open(@zip_name, Zip::File::CREATE) do |zipfile|
|
21
|
+
add_extra_files(zipfile)
|
22
|
+
add_entries(zipfile, entries)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def fetch_entries
|
29
|
+
Dir.entries(@directory) - %w[. ..]
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_extra_files(zipfile)
|
33
|
+
@extra_files.each do |entry, contents|
|
34
|
+
zipfile.get_output_stream(entry) { |f| f.puts(contents) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def add_entries(zipfile, entries)
|
39
|
+
entries.each do |entry|
|
40
|
+
entry_path = File.join(@directory, entry)
|
41
|
+
next if should_exclude?(entry, entry_path)
|
42
|
+
|
43
|
+
puts "Adding #{entry} to #{@zip_name}"
|
44
|
+
|
45
|
+
if File.directory?(entry_path)
|
46
|
+
add_directory(zipfile, entry_path)
|
47
|
+
else
|
48
|
+
add_file(zipfile, entry_path)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def should_exclude?(entry, entry_path)
|
54
|
+
@exclude_files.any? { |pattern| File.fnmatch(pattern, entry) || File.fnmatch(pattern, entry_path) }
|
55
|
+
end
|
56
|
+
|
57
|
+
def add_directory(zipfile, entry_path)
|
58
|
+
zipfile.mkdir("#{@zip_root}#{entry_path.sub(@directory, '')}")
|
59
|
+
Dir[File.join(entry_path, '**', '**')].each do |file|
|
60
|
+
next if should_exclude?(file, file)
|
61
|
+
|
62
|
+
zipfile.add("#{@zip_root}#{file.sub(@directory, '')}", file)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def add_file(zipfile, entry_path)
|
67
|
+
zipfile.add("#{@zip_root}#{entry_path.sub(@directory, '')}", entry_path)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/kybus/aws.rb
CHANGED
@@ -15,6 +15,7 @@ require 'zip'
|
|
15
15
|
require 'kybus/aws'
|
16
16
|
require_relative 'deployers/telegram_configurator'
|
17
17
|
require_relative 'deployers/aws_bot_deployer'
|
18
|
+
require_relative 'deployers/aws_bot_job_runner_deployer'
|
18
19
|
|
19
20
|
module Kybus
|
20
21
|
class CLI < Thor
|
@@ -27,8 +28,9 @@ module Kybus
|
|
27
28
|
def initialize(options)
|
28
29
|
@params = options
|
29
30
|
load_kybusdeploy_file!
|
30
|
-
@telegram = ::Kybus::CLI::BotDeployerTelegramConfigurator.new(
|
31
|
+
@telegram = ::Kybus::CLI::BotDeployerTelegramConfigurator.new(nil, config_with_options)
|
31
32
|
@lambda = ::Kybus::CLI::AWSBotDeployer.new(config_with_options)
|
33
|
+
@job_executor = ::Kybus::CLI::AWSBotJobRunnerDeployer.new(config_with_options)
|
32
34
|
end
|
33
35
|
|
34
36
|
def run_migrations!
|
@@ -52,6 +54,7 @@ module Kybus
|
|
52
54
|
|
53
55
|
def deploy_lambda!
|
54
56
|
@lambda.create_or_update!
|
57
|
+
@job_executor.create_or_update!
|
55
58
|
@telegram.url = @lambda.url
|
56
59
|
end
|
57
60
|
|