stax 0.1.1 → 0.1.6
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/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/changeset.rb +7 -3
- data/lib/stax/stack/crud.rb +34 -18
- data/lib/stax/staxfile.rb +22 -2
- data/lib/stax/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6819a13cc82ff1ec46bda042281f0e69c2da19733f560c1d199e9865a6920f39
|
4
|
+
data.tar.gz: 6438ee3245b0d5b60e9dbff9e1d329c88767942d2af02587844b5c95243c71e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ff0dd2db8d1c8cad1479b43e761777f5630d1ba80591f65f6f8980f6cc740fcfa485eb93e0c85c01762077e5657b0c18d8e21c4ed9fad6dc8ef5544a0381232
|
7
|
+
data.tar.gz: 30f0f7ed35a116b44c72fd3510b5ca9bcaae12270fca6186f0253e727e251aabc22dbdb09db04010b33dc9d87cd2f03bf8b11c1c3c6b4cb3ede2251e4f691e92
|
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/changeset.rb
CHANGED
@@ -71,11 +71,15 @@ module Stax
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def change_set_unlock
|
74
|
-
|
74
|
+
unless stack_policy_during_update.nil?
|
75
|
+
Aws::Cfn.set_policy(stack_name: stack_name, stack_policy_body: stack_policy_during_update)
|
76
|
+
end
|
75
77
|
end
|
76
78
|
|
77
79
|
def change_set_lock
|
78
|
-
|
80
|
+
unless stack_policy.nil?
|
81
|
+
Aws::Cfn.set_policy(stack_name: stack_name, stack_policy_body: stack_policy)
|
82
|
+
end
|
79
83
|
end
|
80
84
|
end
|
81
85
|
|
@@ -91,4 +95,4 @@ module Stax
|
|
91
95
|
end
|
92
96
|
|
93
97
|
end
|
94
|
-
end
|
98
|
+
end
|
data/lib/stax/stack/crud.rb
CHANGED
@@ -24,28 +24,31 @@ module Stax
|
|
24
24
|
}
|
25
25
|
end
|
26
26
|
|
27
|
-
## policy to lock the stack to all updates
|
27
|
+
## policy to lock the stack to all updates, for example:
|
28
|
+
## {
|
29
|
+
## Statement: [
|
30
|
+
## Effect: 'Deny',
|
31
|
+
## Action: 'Update:*',
|
32
|
+
## Principal: '*',
|
33
|
+
## Resource: '*'
|
34
|
+
## ]
|
35
|
+
## }.to_json
|
28
36
|
def stack_policy
|
29
|
-
|
30
|
-
Statement: [
|
31
|
-
Effect: 'Deny',
|
32
|
-
Action: 'Update:*',
|
33
|
-
Principal: '*',
|
34
|
-
Resource: '*'
|
35
|
-
]
|
36
|
-
}.to_json
|
37
|
+
nil
|
37
38
|
end
|
38
39
|
|
39
|
-
##
|
40
|
+
## tmp policy during updates, in case a deny was set in stack_policy()
|
41
|
+
## for example:
|
42
|
+
## {
|
43
|
+
## Statement: [
|
44
|
+
## Effect: 'Allow',
|
45
|
+
## Action: 'Update:*',
|
46
|
+
## Principal: '*',
|
47
|
+
## Resource: '*'
|
48
|
+
## ]
|
49
|
+
## }.to_json
|
40
50
|
def stack_policy_during_update
|
41
|
-
|
42
|
-
Statement: [
|
43
|
-
Effect: 'Allow',
|
44
|
-
Action: 'Update:*',
|
45
|
-
Principal: '*',
|
46
|
-
Resource: '*'
|
47
|
-
]
|
48
|
-
}.to_json
|
51
|
+
nil
|
49
52
|
end
|
50
53
|
|
51
54
|
## cleanup sometimes needs to wait
|
@@ -282,5 +285,18 @@ module Stax
|
|
282
285
|
puts JSON.send(method, skel)
|
283
286
|
end
|
284
287
|
|
288
|
+
## install https://github.com/aws-cloudformation/cfn-python-lint
|
289
|
+
desc 'lint', 'run cfn-lint on template'
|
290
|
+
def lint
|
291
|
+
require 'open3'
|
292
|
+
Open3.popen3('cfn-lint -') do |stdin, stdout|
|
293
|
+
stdin.write(cfn_template)
|
294
|
+
stdin.close
|
295
|
+
puts stdout.read
|
296
|
+
end
|
297
|
+
rescue Errno::ENOENT => e
|
298
|
+
fail_task(e.message)
|
299
|
+
end
|
300
|
+
|
285
301
|
end
|
286
302
|
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.6
|
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-10-07 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
|
@@ -624,8 +624,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
624
624
|
- !ruby/object:Gem::Version
|
625
625
|
version: '0'
|
626
626
|
requirements: []
|
627
|
-
rubygems_version: 3.
|
628
|
-
signing_key:
|
627
|
+
rubygems_version: 3.0.3
|
628
|
+
signing_key:
|
629
629
|
specification_version: 4
|
630
630
|
summary: Control Cloudformation stack and other stuff.
|
631
631
|
test_files: []
|