ops_team 0.2.3 → 0.2.8
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/terraform.template.yml +2 -2
- data/lib/action.rb +2 -11
- data/lib/app_config.rb +38 -0
- data/lib/builtins/down.rb +1 -1
- data/lib/builtins/exec.rb +21 -0
- data/lib/builtins/up.rb +1 -1
- data/lib/ops.rb +10 -5
- data/lib/secrets.rb +12 -19
- data/ops_team.gemspec +1 -1
- metadata +4 -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: 2ed40f82a2c6312381a243ea6ccbfc12ba46f1742af6a8935a2c59d7fcb783f9
|
4
|
+
data.tar.gz: 65ec586f9adb40be64e31f5d581845efc8cc303548b4eea8b7d4b5f6620ae8f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 333c1446f7b2d59f33dda51e29f918d8fe2d54d79f60310d952bbf538dad5ae93c0aa8503fe5af1ed4ba964b336514d21a6d7b6e13948539710bccb259fe2a36
|
7
|
+
data.tar.gz: dac43c177bb4681f3a66a418175c52bd93af2974793400b8db018385fe7abf5743ad89d1ba0398d0ed3cde39b9d68b56dc1919e664621a2366c77e479ef9e100
|
data/bin/print_config
ADDED
data/etc/terraform.template.yml
CHANGED
@@ -11,7 +11,7 @@ actions:
|
|
11
11
|
alias: a
|
12
12
|
description: runs 'terraform apply'
|
13
13
|
apply-auto-approve:
|
14
|
-
command:
|
14
|
+
command: ops apply --auto-approve
|
15
15
|
alias: aa
|
16
16
|
description: runs 'terraform apply' with auto-approve
|
17
17
|
destroy:
|
@@ -19,7 +19,7 @@ actions:
|
|
19
19
|
alias: d
|
20
20
|
description: runs 'terraform destroy'
|
21
21
|
destroy-auto-approve:
|
22
|
-
command:
|
22
|
+
command: ops destroy --auto-approve
|
23
23
|
alias: dd
|
24
24
|
description: runs 'terraform destroy' with auto-approve
|
25
25
|
plan:
|
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
|
@@ -38,12 +37,4 @@ class Action
|
|
38
37
|
def load_secrets?
|
39
38
|
@config["load_secrets"]
|
40
39
|
end
|
41
|
-
|
42
|
-
def load_secrets
|
43
|
-
Secrets.new(secrets_file).load
|
44
|
-
end
|
45
|
-
|
46
|
-
def secrets_file
|
47
|
-
`echo -n #{@options&.dig("secrets", "path")}`
|
48
|
-
end
|
49
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.to_s
|
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/builtins/down.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
|
data/lib/builtins/up.rb
CHANGED
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nickthecook@gmail.com
|
@@ -59,15 +59,18 @@ 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
|
71
74
|
- lib/builtins/help.rb
|
72
75
|
- lib/builtins/helpers/dependency_handler.rb
|
73
76
|
- lib/builtins/init.rb
|
@@ -81,7 +84,6 @@ files:
|
|
81
84
|
- lib/dependencies/dir.rb
|
82
85
|
- lib/dependencies/docker.rb
|
83
86
|
- lib/dependencies/gem.rb
|
84
|
-
- lib/dependencies/terraform.rb
|
85
87
|
- lib/dependency.rb
|
86
88
|
- lib/environment.rb
|
87
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
|