stax 0.0.6 → 0.0.7
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/README.md +48 -0
- data/lib/stax.rb +1 -5
- data/lib/stax/aws/apigw.rb +12 -0
- data/lib/stax/aws/cfn.rb +2 -0
- data/lib/stax/base.rb +1 -0
- data/lib/stax/cli.rb +6 -16
- data/lib/stax/{meta.rb → cli/crud.rb} +0 -0
- data/lib/stax/cli/generate.rb +23 -0
- data/lib/stax/cli/info.rb +23 -0
- data/lib/stax/cli/ls.rb +46 -0
- data/lib/stax/cli/new.rb +11 -0
- data/lib/stax/cli/version.rb +12 -0
- data/lib/stax/generators.rb +16 -4
- data/lib/stax/generators/base.rb +8 -3
- data/lib/stax/generators/generator/generator_generator.rb +6 -2
- data/lib/stax/generators/new/new_generator.rb +42 -0
- data/lib/stax/generators/new/templates/Gemfile +16 -0
- data/lib/stax/generators/new/templates/Staxfile +5 -0
- data/lib/stax/generators/new/templates/lib/stack.rb +38 -0
- data/lib/stax/generators/stack/stack_generator.rb +1 -1
- data/lib/stax/mixin/alb.rb +2 -1
- data/lib/stax/mixin/apigw.rb +25 -0
- data/lib/stax/mixin/asg.rb +2 -0
- data/lib/stax/mixin/codebuild.rb +2 -0
- data/lib/stax/mixin/codepipeline.rb +2 -0
- data/lib/stax/mixin/dynamodb.rb +3 -1
- data/lib/stax/mixin/ecs.rb +3 -1
- data/lib/stax/mixin/elb.rb +1 -0
- data/lib/stax/mixin/lambda.rb +3 -2
- data/lib/stax/mixin/logs.rb +1 -1
- data/lib/stax/staxfile.rb +25 -15
- data/lib/stax/subcommand.rb +24 -1
- data/lib/stax/version.rb +1 -1
- metadata +12 -4
- data/lib/stax/generate.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16b886170228e97d41cc2294002b13db11b77cc363c838181043418891cbc2b6
|
4
|
+
data.tar.gz: fc5d8071c9e5537af036509de4fcaebab03973297bab62421552bcd029de5abd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df070637f695680a7e4474a4b734973ec063b4049ac00a4630fda0d192411aaa87a8146c156addbec21c8b708ddeed97d5c74130f7a80f4862ff4f65a6469258
|
7
|
+
data.tar.gz: 3f0fac8e4f16a786accca5e2f7661be3031caf21c3134156e7e489de49207373293320e22ebb8abf84a8b2371a38e93e11c18b288d8c092d19242592c4470a82
|
data/README.md
CHANGED
@@ -10,6 +10,54 @@ Stax can read template files written in `yaml`, `json` or the
|
|
10
10
|
[cfer](https://github.com/seanedwards/cfer) ruby wrapper. It will
|
11
11
|
choose which to use based on file extensions found.
|
12
12
|
|
13
|
+
## Getting Started
|
14
|
+
|
15
|
+
Install `stax`:
|
16
|
+
|
17
|
+
```sh
|
18
|
+
# gem install stax
|
19
|
+
```
|
20
|
+
|
21
|
+
Create a new `stax` application. You can choose to do this in an
|
22
|
+
ops-specific subdirectory of your application code (thus delivering
|
23
|
+
infrastructure to run an app with the app itself), or create an
|
24
|
+
infrastructure-specific repo. It's up to you.
|
25
|
+
|
26
|
+
```sh
|
27
|
+
$ stax new ops
|
28
|
+
```
|
29
|
+
|
30
|
+
Change to your stax directory and install bundle:
|
31
|
+
|
32
|
+
```sh
|
33
|
+
$ cd ops
|
34
|
+
$ bundle install
|
35
|
+
```
|
36
|
+
|
37
|
+
Create an example stack, and add a resource:
|
38
|
+
|
39
|
+
```sh
|
40
|
+
$ stax g stack example
|
41
|
+
$ cat >> cf/example.rb
|
42
|
+
resource :s3, 'AWS::S3::Bucket'
|
43
|
+
^D
|
44
|
+
$ stax example create
|
45
|
+
```
|
46
|
+
|
47
|
+
Your new stack should create, and you should now be able to list it,
|
48
|
+
inspect resource, etc:
|
49
|
+
|
50
|
+
```sh
|
51
|
+
$ stax ls
|
52
|
+
$ stax example resources
|
53
|
+
```
|
54
|
+
|
55
|
+
Delete your example stack:
|
56
|
+
|
57
|
+
```sh
|
58
|
+
$ stax example delete
|
59
|
+
```
|
60
|
+
|
13
61
|
## Concepts
|
14
62
|
|
15
63
|
### Application
|
data/lib/stax.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'thor'
|
2
|
-
|
3
1
|
require 'stax/aws/sdk'
|
4
2
|
require 'stax/aws/cfn'
|
5
3
|
|
@@ -8,9 +6,9 @@ require 'stax/staxfile'
|
|
8
6
|
require 'stax/base'
|
9
7
|
require 'stax/git'
|
10
8
|
require 'stax/cli'
|
11
|
-
require 'stax/meta'
|
12
9
|
require 'stax/subcommand'
|
13
10
|
require 'stax/cfer'
|
11
|
+
|
14
12
|
require 'stax/stack'
|
15
13
|
require 'stax/stack/cfn'
|
16
14
|
require 'stax/stack/crud'
|
@@ -20,8 +18,6 @@ require 'stax/stack/outputs'
|
|
20
18
|
require 'stax/stack/imports'
|
21
19
|
require 'stax/stack/resources'
|
22
20
|
|
23
|
-
require 'stax/generators'
|
24
|
-
require 'stax/generate'
|
25
21
|
require 'stax/mixin/ec2'
|
26
22
|
require 'stax/mixin/alb'
|
27
23
|
require 'stax/mixin/elb'
|
data/lib/stax/aws/apigw.rb
CHANGED
@@ -17,6 +17,18 @@ module Stax
|
|
17
17
|
client.get_stages(rest_api_id: id, deployment_id: deployment).item
|
18
18
|
end
|
19
19
|
|
20
|
+
def resources(id)
|
21
|
+
position = nil
|
22
|
+
items = []
|
23
|
+
loop do
|
24
|
+
resp = client.get_resources(rest_api_id: id, position: position)
|
25
|
+
items += resp.items
|
26
|
+
position = resp.position
|
27
|
+
break unless position
|
28
|
+
end
|
29
|
+
items
|
30
|
+
end
|
31
|
+
|
20
32
|
end
|
21
33
|
|
22
34
|
end
|
data/lib/stax/aws/cfn.rb
CHANGED
data/lib/stax/base.rb
CHANGED
data/lib/stax/cli.rb
CHANGED
@@ -1,23 +1,13 @@
|
|
1
|
-
require 'stax/
|
1
|
+
require 'stax/cli/version'
|
2
|
+
require 'stax/cli/ls'
|
3
|
+
require 'stax/cli/new'
|
4
|
+
require 'stax/cli/generate'
|
5
|
+
require 'stax/cli/crud'
|
6
|
+
require 'stax/cli/info'
|
2
7
|
|
3
8
|
module Stax
|
4
9
|
class Cli < Base
|
5
10
|
class_option :branch, type: :string, default: Git.branch, desc: 'git branch to use'
|
6
11
|
class_option :app, type: :string, default: File.basename(Git.toplevel), desc: 'application name'
|
7
|
-
|
8
|
-
desc 'version', 'show version'
|
9
|
-
def version
|
10
|
-
puts VERSION
|
11
|
-
end
|
12
|
-
|
13
|
-
desc 'ls', 'list stacks for this branch'
|
14
|
-
def ls
|
15
|
-
print_table Aws::Cfn.stacks.select { |s|
|
16
|
-
s.stack_name.start_with?(stack_prefix)
|
17
|
-
}.map { |s|
|
18
|
-
[s.stack_name, s.creation_time, color(s.stack_status, Aws::Cfn::COLORS), s.template_description]
|
19
|
-
}.sort
|
20
|
-
end
|
21
|
-
|
22
12
|
end
|
23
13
|
end
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'stax/generators'
|
2
|
+
|
3
|
+
module Stax
|
4
|
+
class Cli < Base
|
5
|
+
|
6
|
+
desc 'generate NAME [ARGS]', 'run code generators'
|
7
|
+
def generate(name = nil, *args)
|
8
|
+
Stax::Generators.load_builtin_generators
|
9
|
+
Stax::Generators.load_local_generators
|
10
|
+
|
11
|
+
if name.nil?
|
12
|
+
Stax::Generators::Base.subclasses.each do |g|
|
13
|
+
say_status(g.command_name, g.desc, :bold)
|
14
|
+
end
|
15
|
+
else
|
16
|
+
klass = Stax::Generators.find(name)
|
17
|
+
fail_task("Unknown generator #{name}") unless klass
|
18
|
+
klass.start(args)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Stax
|
2
|
+
class Stack < Base
|
3
|
+
|
4
|
+
# no_commands do
|
5
|
+
# def self.info(cmds)
|
6
|
+
# puts "info: #{cmds}"
|
7
|
+
# end
|
8
|
+
# end
|
9
|
+
|
10
|
+
desc 'info', 'service-specific info'
|
11
|
+
def info
|
12
|
+
## get mixins in the order we declared them
|
13
|
+
self.class.subcommands.reverse.each do |cmd|
|
14
|
+
begin
|
15
|
+
invoke cmd, [:info]
|
16
|
+
rescue Thor::UndefinedCommandError => e
|
17
|
+
# no info no problem
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/stax/cli/ls.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module Stax
|
2
|
+
class Cli < Base
|
3
|
+
|
4
|
+
no_commands do
|
5
|
+
def ls_staxfile_stacks
|
6
|
+
print_table Stax.stack_list.map { |id|
|
7
|
+
name = stack(id).stack_name
|
8
|
+
if (s = Aws::Cfn.describe(name))
|
9
|
+
[s.stack_name, s.creation_time, color(s.stack_status, Aws::Cfn::COLORS), s.description]
|
10
|
+
else
|
11
|
+
options[:existing] ? nil : [name, '-']
|
12
|
+
end
|
13
|
+
}.compact
|
14
|
+
end
|
15
|
+
|
16
|
+
def ls_stacks_with_prefix(prefix)
|
17
|
+
print_table Aws::Cfn.stacks.select { |s|
|
18
|
+
s.stack_name.start_with?(prefix || stack_prefix)
|
19
|
+
}.map { |s|
|
20
|
+
[s.stack_name, s.creation_time, color(s.stack_status, Aws::Cfn::COLORS), s.template_description]
|
21
|
+
}.sort
|
22
|
+
end
|
23
|
+
|
24
|
+
def ls_account_stacks
|
25
|
+
print_table Aws::Cfn.stacks.map { |s|
|
26
|
+
[s.stack_name, s.creation_time, color(s.stack_status, Aws::Cfn::COLORS), s.template_description]
|
27
|
+
}.sort
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'ls [PREFIX]', 'list stacks'
|
32
|
+
method_option :existing, aliases: '-e', type: :boolean, default: false, desc: 'list just existing stacks'
|
33
|
+
method_option :all, aliases: '-a', type: :boolean, default: false, desc: 'list all running stacks with our prefix'
|
34
|
+
method_option :account, aliases: '-A', type: :boolean, default: false, desc: 'list all running stacks in account'
|
35
|
+
def ls(prefix = nil)
|
36
|
+
if options[:account]
|
37
|
+
ls_account_stacks
|
38
|
+
elsif options[:all]
|
39
|
+
ls_stacks_with_prefix(prefix)
|
40
|
+
else
|
41
|
+
ls_staxfile_stacks
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/stax/cli/new.rb
ADDED
data/lib/stax/generators.rb
CHANGED
@@ -1,12 +1,24 @@
|
|
1
1
|
require 'stax/generators/base'
|
2
|
-
require 'stax/generators/stack/stack_generator'
|
3
|
-
require 'stax/generators/generator/generator_generator'
|
4
2
|
|
5
3
|
module Stax
|
6
4
|
module Generators
|
7
5
|
|
8
|
-
def self.
|
9
|
-
|
6
|
+
def self.load_builtin_generators
|
7
|
+
Dir[File.join(__dir__, 'generators', '**', '*_generator.rb')].map(&method(:require))
|
8
|
+
end
|
9
|
+
|
10
|
+
## load any generators in project lib/generators/
|
11
|
+
def self.load_local_generators
|
12
|
+
if Stax.root_path
|
13
|
+
Dir[Stax.root_path.join('lib', 'generators', '**', '*_generator.rb')].map(&method(:require))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
## find subclass that matches command name
|
18
|
+
def self.find(name)
|
19
|
+
Base.subclasses.find do |g|
|
20
|
+
g.command_name == name
|
21
|
+
end
|
10
22
|
end
|
11
23
|
|
12
24
|
end
|
data/lib/stax/generators/base.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'thor/group'
|
2
|
+
|
1
3
|
module Stax
|
2
4
|
module Generators
|
3
5
|
class Base < Thor::Group
|
@@ -5,6 +7,12 @@ module Stax
|
|
5
7
|
|
6
8
|
protected
|
7
9
|
|
10
|
+
## show usage and exit
|
11
|
+
def usage!
|
12
|
+
self.class.help(self)
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
|
8
16
|
def self.subclasses
|
9
17
|
ObjectSpace.each_object(singleton_class).map do |klass|
|
10
18
|
klass == self ? nil : klass
|
@@ -16,9 +24,6 @@ module Stax
|
|
16
24
|
self.to_s.split('::').last.delete_suffix('Generator').downcase
|
17
25
|
end
|
18
26
|
|
19
|
-
def self.invoke(name, args = ARGV)
|
20
|
-
end
|
21
|
-
|
22
27
|
## override help banner to make sense for generators
|
23
28
|
def self.banner(*args)
|
24
29
|
"#{basename} generate #{command_name} ARGS"
|
@@ -6,7 +6,7 @@ module Stax
|
|
6
6
|
source_root File.expand_path('templates', __dir__)
|
7
7
|
|
8
8
|
def check_args
|
9
|
-
|
9
|
+
usage! if args.size != 1
|
10
10
|
end
|
11
11
|
|
12
12
|
def create_generator_file
|
@@ -19,6 +19,10 @@ module Stax
|
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
+
def self.banner(*args)
|
23
|
+
"#{basename} generate #{command_name} NAME"
|
24
|
+
end
|
25
|
+
|
22
26
|
def generator_name
|
23
27
|
@_generator_name ||= args.first.underscore
|
24
28
|
end
|
@@ -28,7 +32,7 @@ module Stax
|
|
28
32
|
end
|
29
33
|
|
30
34
|
def generator_path
|
31
|
-
@_generator_path ||= File.join('lib', 'generators', args.first.underscore)
|
35
|
+
@_generator_path ||= File.join([Stax.root_path, 'lib', 'generators', args.first.underscore].compact)
|
32
36
|
end
|
33
37
|
|
34
38
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Stax
|
2
|
+
module Generators
|
3
|
+
class NewGenerator < Base
|
4
|
+
desc 'Create new stax project in give dir.'
|
5
|
+
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
7
|
+
|
8
|
+
def check_args
|
9
|
+
usage! if args.size != 1
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_stax_dir
|
13
|
+
empty_directory(args.first)
|
14
|
+
self.destination_root = args.first
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_staxfile
|
18
|
+
template('Staxfile')
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_gemfile
|
22
|
+
template('Gemfile')
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_dirs
|
26
|
+
empty_directory(File.join('lib', 'stack'))
|
27
|
+
empty_directory('cf')
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_lib_stack
|
31
|
+
template(File.join('lib', 'stack.rb'))
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def self.banner(*args)
|
37
|
+
"#{basename} generate #{command_name} DIR"
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'stax'
|
4
|
+
# gem 'stax', git: 'https://github.com/rlister/stax'
|
5
|
+
|
6
|
+
gem 'stax-nag'
|
7
|
+
# gem 'stax-nag', git: 'https://github.com/rlister/stax-nag'
|
8
|
+
|
9
|
+
gem 'stax-examples'
|
10
|
+
# gem 'stax-examples', git: 'https://github.com/rlister/stax-examples'
|
11
|
+
|
12
|
+
## this is a hack until this fixed: https://github.com/seanedwards/cfer/issues/50
|
13
|
+
gem 'docile', '~> 1.2.0'
|
14
|
+
|
15
|
+
## for ruby template wrappers
|
16
|
+
gem 'cfer', '>= 0.6.0'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
## Monkey-patches you may make to change stack behavior.
|
2
|
+
## Changing these here will affect all stacks.
|
3
|
+
## You may also define these per-stack in the sub-class for each stack in lib/stacks/.
|
4
|
+
|
5
|
+
module Stax
|
6
|
+
class Stack < Base
|
7
|
+
|
8
|
+
no_commands do
|
9
|
+
|
10
|
+
## your application name, will start all stack names
|
11
|
+
# def app_name
|
12
|
+
# @_app_name ||= options[:app].empty? ? nil : cfn_safe(options[:app])
|
13
|
+
# end
|
14
|
+
|
15
|
+
## git branch to insert in stack names
|
16
|
+
# def branch_name
|
17
|
+
# @_branch_name ||= cfn_safe(options[:branch])
|
18
|
+
# end
|
19
|
+
|
20
|
+
## format of stack names like $app-$branch-$stack
|
21
|
+
# def stack_prefix
|
22
|
+
# @_stack_prefix ||= [app_name, branch_name].compact.join('-') + '-'
|
23
|
+
# end
|
24
|
+
|
25
|
+
## turn on stack protection when creating stack
|
26
|
+
# def cfn_termination_protection
|
27
|
+
# false
|
28
|
+
# end
|
29
|
+
|
30
|
+
## enforce changesets for stack update
|
31
|
+
# def stack_force_changeset
|
32
|
+
# false
|
33
|
+
# end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/lib/stax/mixin/alb.rb
CHANGED
@@ -3,13 +3,14 @@ require 'stax/aws/alb'
|
|
3
3
|
module Stax
|
4
4
|
module Alb
|
5
5
|
def self.included(thor)
|
6
|
-
thor.desc(
|
6
|
+
thor.desc('alb COMMAND', 'ALB subcommands')
|
7
7
|
thor.subcommand(:alb, Cmd::Alb)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
module Cmd
|
12
12
|
class Alb < SubCommand
|
13
|
+
stax_info :status
|
13
14
|
|
14
15
|
COLORS = {
|
15
16
|
healthy: :green,
|
data/lib/stax/mixin/apigw.rb
CHANGED
@@ -10,6 +10,7 @@ module Stax
|
|
10
10
|
|
11
11
|
module Cmd
|
12
12
|
class Apigw < SubCommand
|
13
|
+
stax_info :endpoints, :resources
|
13
14
|
|
14
15
|
no_commands do
|
15
16
|
def stack_apis
|
@@ -36,6 +37,30 @@ module Stax
|
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
40
|
+
desc 'resources', 'list resources'
|
41
|
+
def resources
|
42
|
+
stack_apis.each do |r|
|
43
|
+
api = Aws::APIGateway.api(r.physical_resource_id)
|
44
|
+
debug("Resources for API #{api.name} #{api.id}")
|
45
|
+
print_table Aws::APIGateway.resources(api.id).map { |r|
|
46
|
+
methods = r.resource_methods&.keys&.join(',')
|
47
|
+
[r.path, r.id, methods]
|
48
|
+
}.sort
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
desc 'endpoints', 'guess endpoint URIs'
|
53
|
+
def endpoints
|
54
|
+
stack_apis.each do |r|
|
55
|
+
api = Aws::APIGateway.api(r.physical_resource_id)
|
56
|
+
debug("Endpoints for API #{api.name} #{api.id}")
|
57
|
+
print_table Aws::APIGateway.stages(api.id).map { |s|
|
58
|
+
url = "https://#{api.id}.execute-api.#{aws_region}.amazonaws.com/#{s.stage_name}/"
|
59
|
+
[s.stage_name, url]
|
60
|
+
}.sort
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
39
64
|
end
|
40
65
|
end
|
41
66
|
end
|
data/lib/stax/mixin/asg.rb
CHANGED
data/lib/stax/mixin/codebuild.rb
CHANGED
data/lib/stax/mixin/dynamodb.rb
CHANGED
@@ -6,13 +6,14 @@ require_relative 'dynamodb/backup'
|
|
6
6
|
module Stax
|
7
7
|
module DynamoDB
|
8
8
|
def self.included(thor)
|
9
|
-
thor.desc(
|
9
|
+
thor.desc('dynamodb COMMAND', 'Dynamo subcommands')
|
10
10
|
thor.subcommand(:dynamodb, Cmd::DynamoDB)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
module Cmd
|
15
15
|
class DynamoDB < SubCommand
|
16
|
+
stax_info :tables
|
16
17
|
|
17
18
|
COLORS = {
|
18
19
|
CREATING: :yellow,
|
@@ -38,6 +39,7 @@ module Stax
|
|
38
39
|
|
39
40
|
desc 'tables', 'list tables for stack'
|
40
41
|
def tables
|
42
|
+
debug("Dynamo tables for stack #{my.stack_name}")
|
41
43
|
print_table stack_tables.map { |r|
|
42
44
|
t = Aws::DynamoDB.table(r.physical_resource_id)
|
43
45
|
g = Aws::DynamoDB.global_table(r.physical_resource_id)
|
data/lib/stax/mixin/ecs.rb
CHANGED
@@ -4,7 +4,7 @@ require_relative 'ecs/deploy'
|
|
4
4
|
module Stax
|
5
5
|
module Ecs
|
6
6
|
def self.included(thor)
|
7
|
-
thor.desc(
|
7
|
+
thor.desc('ecs COMMAND', 'ECS subcommands')
|
8
8
|
thor.subcommand(:ecs, Cmd::Ecs)
|
9
9
|
end
|
10
10
|
|
@@ -63,6 +63,8 @@ module Stax
|
|
63
63
|
|
64
64
|
module Cmd
|
65
65
|
class Ecs < SubCommand
|
66
|
+
stax_info :tasks
|
67
|
+
|
66
68
|
COLORS = {
|
67
69
|
ACTIVE: :green,
|
68
70
|
INACTIVE: :red,
|
data/lib/stax/mixin/elb.rb
CHANGED
data/lib/stax/mixin/lambda.rb
CHANGED
@@ -6,13 +6,14 @@ require 'stax/aws/lambda'
|
|
6
6
|
module Stax
|
7
7
|
module Lambda
|
8
8
|
def self.included(thor)
|
9
|
-
thor.desc(
|
9
|
+
thor.desc('lambda COMMAND', 'Lambda subcommands')
|
10
10
|
thor.subcommand(:lambda, Cmd::Lambda)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
module Cmd
|
15
15
|
class Lambda < SubCommand
|
16
|
+
stax_info :ls
|
16
17
|
|
17
18
|
no_commands do
|
18
19
|
def stack_lambdas
|
@@ -37,6 +38,7 @@ module Stax
|
|
37
38
|
|
38
39
|
desc 'ls', 'list lambdas for stack'
|
39
40
|
def ls
|
41
|
+
debug("Lambda functions for stack #{my.stack_name}")
|
40
42
|
names = stack_lambdas.map(&:physical_resource_id)
|
41
43
|
print_table Aws::Lambda.list.select { |l|
|
42
44
|
names.include?(l.function_name)
|
@@ -99,5 +101,4 @@ module Stax
|
|
99
101
|
|
100
102
|
end
|
101
103
|
end
|
102
|
-
|
103
104
|
end
|
data/lib/stax/mixin/logs.rb
CHANGED
data/lib/stax/staxfile.rb
CHANGED
@@ -1,27 +1,37 @@
|
|
1
1
|
module Stax
|
2
|
+
@@_root_path = nil
|
2
3
|
@@_stack_list = []
|
3
4
|
|
5
|
+
## the stax root is defined as location of Staxfile
|
6
|
+
def self.root_path
|
7
|
+
@@_root_path
|
8
|
+
end
|
9
|
+
|
4
10
|
## list of stacks defined in Staxfile
|
5
11
|
def self.stack_list
|
6
12
|
@@_stack_list
|
7
13
|
end
|
8
14
|
|
9
|
-
##
|
10
|
-
def self.
|
11
|
-
|
12
|
-
|
13
|
-
require(f) if File.exist?(f)
|
15
|
+
## search up the dir tree for nearest Staxfile
|
16
|
+
def self.find_staxfile
|
17
|
+
Pathname.pwd.ascend do |path|
|
18
|
+
return path if File.exist?(file = path.join('Staxfile'))
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
17
|
-
## search up the dir tree for nearest Staxfile
|
18
22
|
def self.load_staxfile
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
@@_root_path = find_staxfile
|
24
|
+
if root_path
|
25
|
+
load(root_path.join('Staxfile'))
|
26
|
+
require_stacks
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
## auto-require any stack lib files
|
31
|
+
def self.require_stacks
|
32
|
+
stack_list.each do |stack|
|
33
|
+
f = root_path.join('lib', 'stack', "#{stack}.rb")
|
34
|
+
require(f) if File.exist?(f)
|
25
35
|
end
|
26
36
|
end
|
27
37
|
|
@@ -36,11 +46,11 @@ module Stax
|
|
36
46
|
else
|
37
47
|
self.const_set(c, Class.new(Stack))
|
38
48
|
end.tap do |klass|
|
39
|
-
Cli.desc(name, "#{name} stack")
|
49
|
+
Cli.desc("#{name} COMMAND", "#{name} stack commands")
|
40
50
|
Cli.subcommand(name, klass)
|
41
51
|
|
42
|
-
##
|
43
|
-
opt.fetch(:include, []).each do |i|
|
52
|
+
## syntax to include mixins, reverse to give predictable include order
|
53
|
+
opt.fetch(:include, []).reverse.each do |i|
|
44
54
|
klass.include(self.const_get(i))
|
45
55
|
end
|
46
56
|
|
data/lib/stax/subcommand.rb
CHANGED
@@ -1,12 +1,35 @@
|
|
1
1
|
module Stax
|
2
2
|
class SubCommand < Base
|
3
|
-
no_commands do
|
4
3
|
|
4
|
+
class << self
|
5
|
+
def stax_info(*tasks)
|
6
|
+
@stax_info_tasks ||= []
|
7
|
+
@stax_info_tasks += tasks
|
8
|
+
end
|
9
|
+
|
10
|
+
def stax_info_tasks
|
11
|
+
@stax_info_tasks&.uniq
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
no_commands do
|
5
16
|
## return the Stack instance that called this subcommand
|
6
17
|
def my
|
7
18
|
@_my ||= stack(current_command_chain.first)
|
8
19
|
end
|
20
|
+
end
|
9
21
|
|
22
|
+
desc 'info', 'stax info task', hide: true
|
23
|
+
def info
|
24
|
+
self.class.stax_info_tasks&.each do |task|
|
25
|
+
begin
|
26
|
+
invoke task
|
27
|
+
puts "\n"
|
28
|
+
rescue NoMethodError => e
|
29
|
+
warn(e.message)
|
30
|
+
end
|
31
|
+
end
|
10
32
|
end
|
33
|
+
|
11
34
|
end
|
12
35
|
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.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Lister
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -157,19 +157,27 @@ files:
|
|
157
157
|
- lib/stax/base.rb
|
158
158
|
- lib/stax/cfer.rb
|
159
159
|
- lib/stax/cli.rb
|
160
|
+
- lib/stax/cli/crud.rb
|
161
|
+
- lib/stax/cli/generate.rb
|
162
|
+
- lib/stax/cli/info.rb
|
163
|
+
- lib/stax/cli/ls.rb
|
164
|
+
- lib/stax/cli/new.rb
|
165
|
+
- lib/stax/cli/version.rb
|
160
166
|
- lib/stax/docker.rb
|
161
167
|
- lib/stax/dsl.rb
|
162
|
-
- lib/stax/generate.rb
|
163
168
|
- lib/stax/generators.rb
|
164
169
|
- lib/stax/generators/base.rb
|
165
170
|
- lib/stax/generators/generator/generator_generator.rb
|
166
171
|
- lib/stax/generators/generator/templates/generator.rb.erb
|
172
|
+
- lib/stax/generators/new/new_generator.rb
|
173
|
+
- lib/stax/generators/new/templates/Gemfile
|
174
|
+
- lib/stax/generators/new/templates/Staxfile
|
175
|
+
- lib/stax/generators/new/templates/lib/stack.rb
|
167
176
|
- lib/stax/generators/stack/stack_generator.rb
|
168
177
|
- lib/stax/git.rb
|
169
178
|
- lib/stax/github.rb
|
170
179
|
- lib/stax/iam.rb
|
171
180
|
- lib/stax/keypair.rb
|
172
|
-
- lib/stax/meta.rb
|
173
181
|
- lib/stax/mixin/alb.rb
|
174
182
|
- lib/stax/mixin/apigw.rb
|
175
183
|
- lib/stax/mixin/asg.rb
|
data/lib/stax/generate.rb
DELETED