stax 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stax/base.rb +7 -1
- data/lib/stax/cli.rb +7 -1
- data/lib/stax/docker.rb +4 -28
- data/lib/stax/mixin/codebuild.rb +27 -1
- data/lib/stax/mixin/codepipeline.rb +34 -0
- data/lib/stax/stack/crud.rb +32 -1
- data/lib/stax/staxfile.rb +22 -2
- data/lib/stax/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75641822b021f927037f37d69b733a2a6fd2a894f20da3094ff922b9af846bd5
|
4
|
+
data.tar.gz: ecfa6da9d9b67ce326c199c94e4709e6f3debcf223636d57e0f0e466884e6eef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4ff5cdf4ffeb7bd24f5bcf2df160e725d84b45a13feb40d4886ccb351ae2f3abacff951159855da0aa23fd92025adcc620875c5b07c8ca406139268e3243903
|
7
|
+
data.tar.gz: fb6672ac0878c1bd28266d5a06ce90d9bd477c911ed0755200c9246ba5836be35d9d12add0c8d8015432d94166fc395374c03e457afd401db348b7af691d3b84
|
data/lib/stax/base.rb
CHANGED
data/lib/stax/cli.rb
CHANGED
@@ -9,5 +9,11 @@ module Stax
|
|
9
9
|
class Cli < Base
|
10
10
|
class_option :branch, type: :string, default: Git.branch, desc: 'git branch to use'
|
11
11
|
class_option :app, type: :string, default: File.basename(Git.toplevel), desc: 'application name'
|
12
|
+
## silence deprecation warning
|
13
|
+
## https://github.com/erikhuda/thor/blob/fb625b223465692a9d8a88cc2a483e126f1a8978/CHANGELOG.md#100
|
14
|
+
def self.exit_on_failure?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
12
18
|
end
|
13
|
-
end
|
19
|
+
end
|
data/lib/stax/docker.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'stax/aws/sts'
|
2
1
|
require 'stax/aws/ecr'
|
3
2
|
|
4
3
|
module Stax
|
@@ -7,7 +6,7 @@ module Stax
|
|
7
6
|
no_commands do
|
8
7
|
## default to ECR registry for this account
|
9
8
|
def docker_registry
|
10
|
-
@_docker_registry ||= "#{
|
9
|
+
@_docker_registry ||= "#{aws_account_id}.dkr.ecr.#{aws_region}.amazonaws.com"
|
11
10
|
end
|
12
11
|
|
13
12
|
## name the docker repo after the git repo
|
@@ -21,7 +20,7 @@ module Stax
|
|
21
20
|
end
|
22
21
|
|
23
22
|
## build a docker image locally
|
24
|
-
def
|
23
|
+
def docker_build
|
25
24
|
debug("Docker build #{docker_image}")
|
26
25
|
system "docker build -t #{docker_image} #{Git.toplevel}"
|
27
26
|
end
|
@@ -31,28 +30,6 @@ module Stax
|
|
31
30
|
debug("Docker push #{docker_image}")
|
32
31
|
system "docker push #{docker_image}"
|
33
32
|
end
|
34
|
-
|
35
|
-
## override this for your argus setup
|
36
|
-
def docker_argus_queue
|
37
|
-
@_docker_argus_queue ||= Aws::Sqs.queue_url('argus.fifo')
|
38
|
-
end
|
39
|
-
|
40
|
-
def docker_argus_build
|
41
|
-
debug("Sending to argus #{Git.branch}:#{Git.sha}")
|
42
|
-
org, repo = Git.repo.split('/')
|
43
|
-
Aws::Sqs.send(
|
44
|
-
queue_url: docker_argus_queue,
|
45
|
-
message_group_id: repo,
|
46
|
-
message_body: {
|
47
|
-
org: org,
|
48
|
-
repo: repo,
|
49
|
-
branch: Git.branch,
|
50
|
-
sha: Git.sha,
|
51
|
-
}.to_json
|
52
|
-
).tap do |r|
|
53
|
-
puts r&.message_id
|
54
|
-
end
|
55
|
-
end
|
56
33
|
end
|
57
34
|
|
58
35
|
desc 'registry', 'show registry name'
|
@@ -73,8 +50,7 @@ module Stax
|
|
73
50
|
## override this method with the desired builder
|
74
51
|
desc 'build', 'build docker image'
|
75
52
|
def build
|
76
|
-
|
77
|
-
# docker_argus_build
|
53
|
+
docker_build
|
78
54
|
end
|
79
55
|
|
80
56
|
desc 'login', 'login to registry'
|
@@ -103,4 +79,4 @@ module Stax
|
|
103
79
|
end
|
104
80
|
|
105
81
|
end
|
106
|
-
end
|
82
|
+
end
|
data/lib/stax/mixin/codebuild.rb
CHANGED
@@ -14,6 +14,7 @@ module Stax
|
|
14
14
|
def stack_project_names
|
15
15
|
@_stack_project_names ||= stack_projects.map(&:physical_resource_id)
|
16
16
|
end
|
17
|
+
|
17
18
|
end
|
18
19
|
|
19
20
|
module Cmd
|
@@ -34,6 +35,17 @@ module Stax
|
|
34
35
|
status = p.phase_status || (p.phase_type == 'COMPLETED' ? '' : 'in progress')
|
35
36
|
puts "%-16s %-12s %4s %s" % [p.phase_type, color(status, COLORS), duration, p.end_time]
|
36
37
|
end
|
38
|
+
|
39
|
+
## latest run id for a build project
|
40
|
+
def latest_run(name)
|
41
|
+
Aws::Codebuild.builds_for_project(name, 1).first
|
42
|
+
end
|
43
|
+
|
44
|
+
## aws console link to latest project run
|
45
|
+
def latest_run_link(name)
|
46
|
+
id = latest_run(name)
|
47
|
+
"https://console.aws.amazon.com/codesuite/codebuild/#{aws_account_id}/projects/#{name}/build/#{id}/?region=#{aws_region}"
|
48
|
+
end
|
37
49
|
end
|
38
50
|
|
39
51
|
desc 'projects', 'list projects'
|
@@ -118,6 +130,20 @@ module Stax
|
|
118
130
|
tail build.id
|
119
131
|
end
|
120
132
|
|
133
|
+
desc 'link', 'link to latest run for builds'
|
134
|
+
def link
|
135
|
+
my.stack_project_names.map do |name|
|
136
|
+
puts latest_run_link(name)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
desc 'open', 'open latest run in aws console'
|
141
|
+
def open
|
142
|
+
my.stack_project_names.map do |name|
|
143
|
+
os_open(latest_run_link(name))
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
121
147
|
end
|
122
148
|
end
|
123
|
-
end
|
149
|
+
end
|
@@ -14,6 +14,12 @@ module Stax
|
|
14
14
|
def stack_pipeline_names
|
15
15
|
@_stack_pipeline_names ||= stack_pipelines.map(&:physical_resource_id)
|
16
16
|
end
|
17
|
+
|
18
|
+
## get status string for n-th pipeline
|
19
|
+
def stack_pipeline_status(n = 0)
|
20
|
+
name = stack_pipeline_names[n]
|
21
|
+
Aws::Codepipeline.executions(name, 1)&.first&.status
|
22
|
+
end
|
17
23
|
end
|
18
24
|
|
19
25
|
module Cmd
|
@@ -29,6 +35,12 @@ module Stax
|
|
29
35
|
disabled: :red,
|
30
36
|
}
|
31
37
|
|
38
|
+
no_commands do
|
39
|
+
def pipeline_link(name)
|
40
|
+
"https://console.aws.amazon.com/codesuite/codepipeline/pipelines/#{name}/view?region=#{aws_region}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
32
44
|
desc 'stages', 'list pipeline stages'
|
33
45
|
def stages
|
34
46
|
my.stack_pipeline_names.each do |name|
|
@@ -54,6 +66,14 @@ module Stax
|
|
54
66
|
end
|
55
67
|
end
|
56
68
|
|
69
|
+
## print status as one of InProgress, Stopped, Stopping, Succeeded, Superseded, Failed
|
70
|
+
desc 'status', 'pipeline execution status'
|
71
|
+
def status
|
72
|
+
s = my.stack_pipeline_status
|
73
|
+
puts(s)
|
74
|
+
exit(1) if s == 'Failed'
|
75
|
+
end
|
76
|
+
|
57
77
|
desc 'state', 'pipeline state'
|
58
78
|
def state
|
59
79
|
my.stack_pipeline_names.each do |name|
|
@@ -187,6 +207,20 @@ module Stax
|
|
187
207
|
end
|
188
208
|
end
|
189
209
|
|
210
|
+
desc 'link', 'link to pipelines in aws console'
|
211
|
+
def link
|
212
|
+
my.stack_pipeline_names.each do |name|
|
213
|
+
puts pipeline_link(name)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
desc 'open', 'open pipelines in aws console'
|
218
|
+
def open
|
219
|
+
my.stack_pipeline_names.each do |name|
|
220
|
+
os_open(pipeline_link(name))
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
190
224
|
end
|
191
225
|
end
|
192
226
|
end
|
data/lib/stax/stack/crud.rb
CHANGED
@@ -264,5 +264,36 @@ module Stax
|
|
264
264
|
end
|
265
265
|
end
|
266
266
|
|
267
|
+
desc 'skeleton', 'create json skeleton for cli'
|
268
|
+
method_option :pretty, type: :boolean, default: false, desc: 'pretty generate json'
|
269
|
+
def skeleton
|
270
|
+
skel = {
|
271
|
+
StackName: stack_name,
|
272
|
+
TemplateBody: cfn_template_body,
|
273
|
+
TemplateURL: cfn_template_url,
|
274
|
+
Parameters: cfn_parameters_create,
|
275
|
+
Capabilities: cfn_capabilities,
|
276
|
+
StackPolicyBody: stack_policy,
|
277
|
+
NotificationARNs: cfn_notification_arns,
|
278
|
+
EnableTerminationProtection: cfn_termination_protection,
|
279
|
+
Tags: cfn_tags_array,
|
280
|
+
}.compact
|
281
|
+
method = options[:pretty] ? :pretty_generate : :generate
|
282
|
+
puts JSON.send(method, skel)
|
283
|
+
end
|
284
|
+
|
285
|
+
## install https://github.com/aws-cloudformation/cfn-python-lint
|
286
|
+
desc 'lint', 'run cfn-lint on template'
|
287
|
+
def lint
|
288
|
+
require 'open3'
|
289
|
+
Open3.popen3('cfn-lint -') do |stdin, stdout|
|
290
|
+
stdin.write(cfn_template)
|
291
|
+
stdin.close
|
292
|
+
puts stdout.read
|
293
|
+
end
|
294
|
+
rescue Errno::ENOENT => e
|
295
|
+
fail_task(e.message)
|
296
|
+
end
|
297
|
+
|
267
298
|
end
|
268
|
-
end
|
299
|
+
end
|
data/lib/stax/staxfile.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Stax
|
2
2
|
@@_root_path = nil
|
3
3
|
@@_stack_list = []
|
4
|
+
@@_command_list = []
|
4
5
|
|
5
6
|
## the stax root is defined as location of Staxfile
|
6
7
|
def self.root_path
|
@@ -12,6 +13,11 @@ module Stax
|
|
12
13
|
@@_stack_list
|
13
14
|
end
|
14
15
|
|
16
|
+
## list of commands defined in Staxfile
|
17
|
+
def self.command_list
|
18
|
+
@@_command_list
|
19
|
+
end
|
20
|
+
|
15
21
|
## search up the dir tree for nearest Staxfile
|
16
22
|
def self.find_staxfile
|
17
23
|
Pathname.pwd.ascend do |path|
|
@@ -24,6 +30,7 @@ module Stax
|
|
24
30
|
if root_path
|
25
31
|
load(root_path.join('Staxfile'))
|
26
32
|
require_stacks
|
33
|
+
require_commands
|
27
34
|
end
|
28
35
|
end
|
29
36
|
|
@@ -35,6 +42,14 @@ module Stax
|
|
35
42
|
end
|
36
43
|
end
|
37
44
|
|
45
|
+
## auto-require any command lib files
|
46
|
+
def self.require_commands
|
47
|
+
command_list.each do |command|
|
48
|
+
f = root_path.join('lib', "#{command}.rb")
|
49
|
+
require(f) if File.exist?(f)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
38
53
|
## add a stack by name, creates class as needed
|
39
54
|
def self.add_stack(name, opt = {})
|
40
55
|
@@_stack_list << name
|
@@ -64,9 +79,14 @@ module Stax
|
|
64
79
|
end
|
65
80
|
|
66
81
|
## add a non-stack command at top level
|
67
|
-
def self.add_command(name, klass)
|
82
|
+
def self.add_command(name, klass = nil)
|
83
|
+
@@_command_list << name
|
84
|
+
|
85
|
+
## class defaults to eg Stax::Name::Cmd
|
86
|
+
klass ||= self.const_get(name.to_s.split(/[_-]/).map(&:capitalize).join + '::Cmd')
|
87
|
+
|
68
88
|
Cli.desc(name, "#{name} commands")
|
69
89
|
Cli.subcommand(name, klass)
|
70
90
|
end
|
71
91
|
|
72
|
-
end
|
92
|
+
end
|
data/lib/stax/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Lister
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -609,7 +609,7 @@ homepage: https://github.com/rlister/stax
|
|
609
609
|
licenses:
|
610
610
|
- MIT
|
611
611
|
metadata: {}
|
612
|
-
post_install_message:
|
612
|
+
post_install_message:
|
613
613
|
rdoc_options: []
|
614
614
|
require_paths:
|
615
615
|
- lib
|
@@ -625,7 +625,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
625
625
|
version: '0'
|
626
626
|
requirements: []
|
627
627
|
rubygems_version: 3.1.2
|
628
|
-
signing_key:
|
628
|
+
signing_key:
|
629
629
|
specification_version: 4
|
630
630
|
summary: Control Cloudformation stack and other stuff.
|
631
631
|
test_files: []
|