ops_team 0.2.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffbfe47eb5ac6fd8b908604cb1409e4b90f5e03761d6f111b53dfd93ecb2d9fe
4
- data.tar.gz: ce01d34fcab6f08a8b07a41cf7cfe99d3ed96c6ac9a3353f48ebbb65d2c03694
3
+ metadata.gz: e2d73684ffca5eb14c1ea36dc8ee868a981ad883889598ffb95514f7a4bfc7d1
4
+ data.tar.gz: 63ccdc699d7c1fe55eec5d97a704decac9effd325faf7b2dcd1b18c59e644457
5
5
  SHA512:
6
- metadata.gz: fd14eed08cc7eb9e38e1bc8c995142b197d27ef8789718a0c8daea0af57f45704c5720fed3e15b7a8f6d0a0021d21e098bd02cd234cfde3ba822804a532bbec5
7
- data.tar.gz: 27b74a7306b5577f38b1864be03a13fd3eeababf2447a37f317b0a55c5f59c94d648f957f93b010ce981fbb3b161e1889d1b841509d0cd638e7850d143558939
6
+ metadata.gz: bbcbeb70c8b1d49bb8e7273c0fa32611edb6e977cd3d049c3f51c4ad45855d9680c15bb591b8da7f048c6f7173108b6406df45b01d2014e16298becc8efba95c
7
+ data.tar.gz: 44a9fc21e22dd6e6c33fa9820a390e9d53b64fbdbe9a6b0e356add07e67d88024cefb9f879467b0cea5c623a4e3e90161362fb802de333531dcc29ae410ac05c
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+
3
+ echo $KEY1
4
+ echo $KEY2
@@ -7,5 +7,7 @@ dependencies:
7
7
  actions:
8
8
  start:
9
9
  command: docker-compose up -d
10
+ description: starts the service
10
11
  stop:
11
12
  command: docker-compose down
13
+ description: stops the service
@@ -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
@@ -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: terraform apply --auto-approve
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: terraform destroy --auto-approve
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
@@ -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, options)
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
- load_secrets if load_secrets?
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
@@ -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
@@ -10,11 +10,11 @@ module Builtins
10
10
  class Down < Builtin
11
11
  class << self
12
12
  def description
13
- "Stops dependent services listed in ops.yml"
13
+ "stops dependent services listed in ops.yml"
14
14
  end
15
15
  end
16
16
 
17
- def run
17
+ def run
18
18
  # TODO: return a success/failure status to the caller
19
19
  unmeet_dependencies
20
20
  end
@@ -45,7 +45,7 @@ module Builtins
45
45
  else
46
46
  Output.failed
47
47
  Output.error("Error unmeeting #{dependency.type} dependency '#{dependency.name}':")
48
- puts(dependency.output)
48
+ Output.out(dependency.output)
49
49
  end
50
50
  end
51
51
  end
@@ -7,7 +7,7 @@ module Builtins
7
7
  class Env < Builtin
8
8
  class << self
9
9
  def description
10
- "Prints the current environment, e.g. 'dev', 'production', 'staging', etc."
10
+ "prints the current environment, e.g. 'dev', 'production', 'staging', etc."
11
11
  end
12
12
  end
13
13
 
@@ -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
@@ -8,7 +8,7 @@ module Builtins
8
8
  class Help < Builtin
9
9
  class << self
10
10
  def description
11
- "Displays available builtins and actions"
11
+ "displays available builtins and actions"
12
12
  end
13
13
  end
14
14
 
@@ -14,7 +14,7 @@ module Builtins
14
14
 
15
15
  class << self
16
16
  def description
17
- "Creates an ops.yml file from a template"
17
+ "creates an ops.yml file from a template"
18
18
  end
19
19
  end
20
20
 
@@ -11,7 +11,7 @@ module Builtins
11
11
  class Up < Builtin
12
12
  class << self
13
13
  def description
14
- "Attempts to meet dependencies listed in ops.yml"
14
+ "attempts to meet dependencies listed in ops.yml"
15
15
  end
16
16
  end
17
17
 
@@ -46,7 +46,7 @@ module Builtins
46
46
  else
47
47
  Output.failed
48
48
  Output.error("Error meeting #{dependency.type} dependency '#{dependency.name}':")
49
- puts(dependency.output)
49
+ Output.out(dependency.output)
50
50
  end
51
51
  end
52
52
  end
@@ -10,7 +10,7 @@ module Builtins
10
10
 
11
11
  class << self
12
12
  def description
13
- "Prints the version of ops that is running"
13
+ "prints the version of ops that is running"
14
14
  end
15
15
  end
16
16
 
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, action_options)
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__
@@ -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
- def initialize(filename = "")
9
- @filename = filename.empty? ? default_filename : filename
10
- end
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
- def load
13
- secrets['environment']&.each do |key, value|
14
- ENV[key] = value
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}` : File.open(@filename).read
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ops_team'
5
- s.version = '0.2.2'
5
+ s.version = '0.2.7'
6
6
  s.authors = [
7
7
  'nickthecook@gmail.com'
8
8
  ]
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.2
4
+ version: 0.2.7
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