ops_team 0.2.1 → 0.2.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/bin/print_config +4 -0
- data/etc/ops.template.yml +2 -0
- data/etc/ruby.template.yml +8 -0
- data/etc/terraform.template.yml +9 -2
- data/lib/action.rb +7 -10
- data/lib/app_config.rb +38 -0
- data/lib/builtin.rb +6 -0
- data/lib/builtins/down.rb +7 -1
- data/lib/builtins/env.rb +6 -0
- data/lib/builtins/exec.rb +21 -0
- data/lib/builtins/help.rb +42 -0
- data/lib/builtins/init.rb +6 -0
- data/lib/builtins/up.rb +7 -1
- data/lib/builtins/version.rb +7 -1
- data/lib/ops.rb +10 -5
- data/lib/secrets.rb +12 -19
- data/ops_team.gemspec +1 -1
- metadata +5 -2
- data/lib/dependencies/terraform.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 164882aa877bcf1e7026038b7a5af80466f6d93bdde7004746b023d27c209201
|
4
|
+
data.tar.gz: e829f092558ea07bc81758a00a4551cd707d6c2c15fa4bada88bf30638abdb9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e643d7c06f4eb3afd4837502a23d383a66c1dec472aff0e4bf0471c45240094db510a26d9d2c24c8688723108c92514dba2af6f25c0dddc25f4c34ec6d9bc3b
|
7
|
+
data.tar.gz: 6ffbd12aa5626f08ecde1d88d011a7318644624c27bbccd06ef15eca3016cedf26f228306eedc314234f92548b83fb5470acf3e06c6f5470514ac693bc9314b3
|
data/bin/print_config
ADDED
data/etc/ops.template.yml
CHANGED
data/etc/ruby.template.yml
CHANGED
@@ -7,23 +7,31 @@ dependencies:
|
|
7
7
|
actions:
|
8
8
|
start:
|
9
9
|
command: echo update me
|
10
|
+
description: starts the app
|
10
11
|
stop:
|
11
12
|
command: echo update me too
|
13
|
+
description: stops the app
|
12
14
|
test:
|
13
15
|
command: rspec
|
14
16
|
alias: t
|
17
|
+
description: runs unit tests
|
15
18
|
test-watch:
|
16
19
|
command: rerun -x ops test
|
17
20
|
alias: tw
|
21
|
+
description: runs unit tests every time a file changes
|
18
22
|
lint:
|
19
23
|
command: bundle exec rubocop --safe-auto-correct
|
20
24
|
alias: l
|
25
|
+
description: runs rubocop with safe autocorrect
|
21
26
|
build:
|
22
27
|
command: gem build *.gemspec
|
23
28
|
alias: b
|
29
|
+
description: builds the gem
|
24
30
|
install:
|
25
31
|
command: gem install `ls -t *.gem | head -n1`
|
26
32
|
alias: i
|
33
|
+
description: installs the gem
|
27
34
|
build-and-install:
|
28
35
|
command: ops build && ops install
|
29
36
|
alias: bi
|
37
|
+
description: builds and installs the gem
|
data/etc/terraform.template.yml
CHANGED
@@ -9,21 +9,28 @@ actions:
|
|
9
9
|
apply:
|
10
10
|
command: terraform apply
|
11
11
|
alias: a
|
12
|
+
description: runs 'terraform apply'
|
12
13
|
apply-auto-approve:
|
13
|
-
command:
|
14
|
+
command: ops apply --auto-approve
|
14
15
|
alias: aa
|
16
|
+
description: runs 'terraform apply' with auto-approve
|
15
17
|
destroy:
|
16
18
|
command: terraform destroy
|
17
19
|
alias: d
|
20
|
+
description: runs 'terraform destroy'
|
18
21
|
destroy-auto-approve:
|
19
|
-
command:
|
22
|
+
command: ops destroy --auto-approve
|
20
23
|
alias: dd
|
24
|
+
description: runs 'terraform destroy' with auto-approve
|
21
25
|
plan:
|
22
26
|
command: terraform plan
|
23
27
|
alias: p
|
28
|
+
description: runs 'terraform plan'
|
24
29
|
graph:
|
25
30
|
command: terraform graph | dot -T pdf -o resource_graph.pdf
|
26
31
|
alias: g
|
32
|
+
description: runs 'terraform graph'
|
27
33
|
open-graph:
|
28
34
|
command: ops graph && open resource_graph.pdf
|
29
35
|
alias: og
|
36
|
+
description: opens the terraform graph with the OS 'open' command
|
data/lib/action.rb
CHANGED
@@ -5,14 +5,13 @@ require 'secrets'
|
|
5
5
|
# represents one action to be performed in the shell
|
6
6
|
# can assemble a command line from a command and args
|
7
7
|
class Action
|
8
|
-
def initialize(config, args
|
8
|
+
def initialize(config, args)
|
9
9
|
@config = config
|
10
10
|
@args = args
|
11
|
-
@options = options
|
12
11
|
end
|
13
12
|
|
14
13
|
def run
|
15
|
-
|
14
|
+
Secrets.load if load_secrets?
|
16
15
|
|
17
16
|
Kernel.exec(to_s)
|
18
17
|
end
|
@@ -29,15 +28,13 @@ class Action
|
|
29
28
|
@config["command"]
|
30
29
|
end
|
31
30
|
|
32
|
-
def
|
33
|
-
@config["
|
31
|
+
def description
|
32
|
+
@config["description"]
|
34
33
|
end
|
35
34
|
|
36
|
-
|
37
|
-
Secrets.new(secrets_file).load
|
38
|
-
end
|
35
|
+
private
|
39
36
|
|
40
|
-
def
|
41
|
-
|
37
|
+
def load_secrets?
|
38
|
+
@config["load_secrets"]
|
42
39
|
end
|
43
40
|
end
|
data/lib/app_config.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AppConfig
|
4
|
+
def initialize(filename = "")
|
5
|
+
@filename = filename.empty? ? default_filename : filename
|
6
|
+
end
|
7
|
+
|
8
|
+
def load
|
9
|
+
config['environment']&.each do |key, value|
|
10
|
+
ENV[key] = value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def default_filename
|
17
|
+
"config/#{environment}/config.json"
|
18
|
+
end
|
19
|
+
|
20
|
+
def config
|
21
|
+
@config ||= file_contents ? JSON.parse(file_contents) : {}
|
22
|
+
rescue JSON::ParserError => e
|
23
|
+
Output.error("Error parsing config data: #{e}")
|
24
|
+
{}
|
25
|
+
end
|
26
|
+
|
27
|
+
def file_contents
|
28
|
+
@file_contents ||= begin
|
29
|
+
File.open(@filename).read
|
30
|
+
rescue Errno::ENOENT
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def environment
|
36
|
+
ENV['environment']
|
37
|
+
end
|
38
|
+
end
|
data/lib/builtin.rb
CHANGED
data/lib/builtins/down.rb
CHANGED
@@ -8,6 +8,12 @@ require 'builtins/helpers/dependency_handler'
|
|
8
8
|
|
9
9
|
module Builtins
|
10
10
|
class Down < Builtin
|
11
|
+
class << self
|
12
|
+
def description
|
13
|
+
"stops dependent services listed in ops.yml"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
11
17
|
def run
|
12
18
|
# TODO: return a success/failure status to the caller
|
13
19
|
unmeet_dependencies
|
@@ -39,7 +45,7 @@ module Builtins
|
|
39
45
|
else
|
40
46
|
Output.failed
|
41
47
|
Output.error("Error unmeeting #{dependency.type} dependency '#{dependency.name}':")
|
42
|
-
|
48
|
+
Output.out(dependency.output)
|
43
49
|
end
|
44
50
|
end
|
45
51
|
end
|
data/lib/builtins/env.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'builtin'
|
4
|
+
require 'output'
|
5
|
+
require 'secrets'
|
6
|
+
require 'options'
|
7
|
+
|
8
|
+
module Builtins
|
9
|
+
class Exec < Builtin
|
10
|
+
class << self
|
11
|
+
def description
|
12
|
+
"executes the given command in the `ops` environment, i.e. with environment variables set"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
Secrets.load if Options.get("exec.load_secrets")
|
18
|
+
Kernel.exec(@args.join(" "))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'colorize'
|
4
|
+
|
5
|
+
require 'builtin'
|
6
|
+
|
7
|
+
module Builtins
|
8
|
+
class Help < Builtin
|
9
|
+
class << self
|
10
|
+
def description
|
11
|
+
"displays available builtins and actions"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
Output.out("Builtins:")
|
17
|
+
Output.out(" #{builtins.join("\n ")}")
|
18
|
+
Output.out("")
|
19
|
+
Output.out("Actions:")
|
20
|
+
Output.out(" #{actions.join("\n ")}")
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def builtins
|
26
|
+
builtin_class_names.map do |class_name|
|
27
|
+
description = Builtins.const_get(class_name).description
|
28
|
+
format("%<name>-35s %<desc>s", name: class_name.downcase.to_s.yellow, desc: description)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def builtin_class_names
|
33
|
+
Builtins.constants.select { |c| Builtins.const_get(c).is_a? Class }
|
34
|
+
end
|
35
|
+
|
36
|
+
def actions
|
37
|
+
@config["actions"].map do |name, value|
|
38
|
+
format("%<name>-35s %<desc>s", name: name.yellow, desc: value["description"] || value["command"])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/builtins/init.rb
CHANGED
@@ -12,6 +12,12 @@ module Builtins
|
|
12
12
|
OPS_YML_TEMPLATE = File.join(TEMPLATE_DIR, "%<template_name>s.template.yml")
|
13
13
|
DEFAULT_TEMPLATE_NAME = "ops"
|
14
14
|
|
15
|
+
class << self
|
16
|
+
def description
|
17
|
+
"creates an ops.yml file from a template"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
15
21
|
def run
|
16
22
|
if File.exist?(OPS_YML)
|
17
23
|
Output.error("File '#{OPS_YML} exists; not initializing.")
|
data/lib/builtins/up.rb
CHANGED
@@ -9,6 +9,12 @@ require 'output'
|
|
9
9
|
|
10
10
|
module Builtins
|
11
11
|
class Up < Builtin
|
12
|
+
class << self
|
13
|
+
def description
|
14
|
+
"attempts to meet dependencies listed in ops.yml"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
12
18
|
def run
|
13
19
|
# TODO: return a success/failure status to the caller
|
14
20
|
meet_dependencies
|
@@ -40,7 +46,7 @@ module Builtins
|
|
40
46
|
else
|
41
47
|
Output.failed
|
42
48
|
Output.error("Error meeting #{dependency.type} dependency '#{dependency.name}':")
|
43
|
-
|
49
|
+
Output.out(dependency.output)
|
44
50
|
end
|
45
51
|
end
|
46
52
|
end
|
data/lib/builtins/version.rb
CHANGED
@@ -8,7 +8,13 @@ module Builtins
|
|
8
8
|
class Version < Builtin
|
9
9
|
GEMSPEC_FILE = "#{__dir__}/../../ops_team.gemspec"
|
10
10
|
|
11
|
-
|
11
|
+
class << self
|
12
|
+
def description
|
13
|
+
"prints the version of ops that is running"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
12
18
|
unless gemspec
|
13
19
|
Output.error("Unable to load gemspec at '#{GEMSPEC_FILE}")
|
14
20
|
return false
|
data/lib/ops.rb
CHANGED
@@ -29,6 +29,7 @@ class Ops
|
|
29
29
|
exit(INVALID_SYNTAX_EXIT_CODE) unless syntax_valid?
|
30
30
|
|
31
31
|
environment.set_variables
|
32
|
+
app_config.load
|
32
33
|
|
33
34
|
return builtin.run if builtin
|
34
35
|
|
@@ -70,7 +71,7 @@ class Ops
|
|
70
71
|
|
71
72
|
def actions
|
72
73
|
config["actions"].transform_values do |config|
|
73
|
-
Action.new(config, @args
|
74
|
+
Action.new(config, @args)
|
74
75
|
end
|
75
76
|
end
|
76
77
|
|
@@ -91,10 +92,6 @@ class Ops
|
|
91
92
|
end
|
92
93
|
end
|
93
94
|
|
94
|
-
def action_options
|
95
|
-
@action_options ||= @config.dig("options", "actions")
|
96
|
-
end
|
97
|
-
|
98
95
|
def env_vars
|
99
96
|
@config.dig("options", "environment") || {}
|
100
97
|
end
|
@@ -102,6 +99,14 @@ class Ops
|
|
102
99
|
def environment
|
103
100
|
@environment ||= Environment.new(env_vars)
|
104
101
|
end
|
102
|
+
|
103
|
+
def app_config_file
|
104
|
+
`echo #{Options.get("config.path")}`.chomp
|
105
|
+
end
|
106
|
+
|
107
|
+
def app_config
|
108
|
+
@app_config ||= AppConfig.new(app_config_file)
|
109
|
+
end
|
105
110
|
end
|
106
111
|
|
107
112
|
Ops.new(ARGV).run if $PROGRAM_NAME == __FILE__
|
data/lib/secrets.rb
CHANGED
@@ -3,15 +3,19 @@
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
require 'output'
|
6
|
+
require 'app_config'
|
7
|
+
require 'Options'
|
6
8
|
|
7
|
-
class Secrets
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
class Secrets < AppConfig
|
10
|
+
class << self
|
11
|
+
def load
|
12
|
+
Secrets.new(expand_path(Options.get("secrets.path"))).load
|
13
|
+
end
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
+
private
|
16
|
+
|
17
|
+
def expand_path(path)
|
18
|
+
`echo #{path}`.chomp
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
@@ -31,18 +35,7 @@ class Secrets
|
|
31
35
|
"config/#{environment}/secrets.json"
|
32
36
|
end
|
33
37
|
|
34
|
-
def secrets
|
35
|
-
@secrets ||= JSON.parse(file_contents)
|
36
|
-
rescue JSON::ParserError => e
|
37
|
-
Output.error("Error parsing secrets data: #{e}")
|
38
|
-
{}
|
39
|
-
end
|
40
|
-
|
41
38
|
def file_contents
|
42
|
-
@filename.match(/\.ejson$/) ? `ejson decrypt #{@filename}` :
|
43
|
-
end
|
44
|
-
|
45
|
-
def environment
|
46
|
-
ENV['environment']
|
39
|
+
@file_contents ||= @filename.match(/\.ejson$/) ? `ejson decrypt #{@filename}` : super
|
47
40
|
end
|
48
41
|
end
|
data/ops_team.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ops_team
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nickthecook@gmail.com
|
@@ -59,15 +59,19 @@ extra_rdoc_files: []
|
|
59
59
|
files:
|
60
60
|
- Gemfile
|
61
61
|
- bin/ops
|
62
|
+
- bin/print_config
|
62
63
|
- bin/print_secrets
|
63
64
|
- bin/tag
|
64
65
|
- etc/ops.template.yml
|
65
66
|
- etc/ruby.template.yml
|
66
67
|
- etc/terraform.template.yml
|
67
68
|
- lib/action.rb
|
69
|
+
- lib/app_config.rb
|
68
70
|
- lib/builtin.rb
|
69
71
|
- lib/builtins/down.rb
|
70
72
|
- lib/builtins/env.rb
|
73
|
+
- lib/builtins/exec.rb
|
74
|
+
- lib/builtins/help.rb
|
71
75
|
- lib/builtins/helpers/dependency_handler.rb
|
72
76
|
- lib/builtins/init.rb
|
73
77
|
- lib/builtins/up.rb
|
@@ -80,7 +84,6 @@ files:
|
|
80
84
|
- lib/dependencies/dir.rb
|
81
85
|
- lib/dependencies/docker.rb
|
82
86
|
- lib/dependencies/gem.rb
|
83
|
-
- lib/dependencies/terraform.rb
|
84
87
|
- lib/dependency.rb
|
85
88
|
- lib/environment.rb
|
86
89
|
- lib/ops.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'dependency'
|
4
|
-
|
5
|
-
module Dependencies
|
6
|
-
class Terraform < Dependency
|
7
|
-
def met?
|
8
|
-
false
|
9
|
-
end
|
10
|
-
|
11
|
-
def always_act?
|
12
|
-
true
|
13
|
-
end
|
14
|
-
|
15
|
-
def meet
|
16
|
-
execute("cd #{name} && terraform init && terraform apply -input=false --auto-approve")
|
17
|
-
end
|
18
|
-
|
19
|
-
def unmeet
|
20
|
-
execute("cd #{name} && terraform destroy -input=false --auto-approve")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|