ops_team 1.0.1 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf2a309a88bc396994795bca23a308043e8e8ec6c16a5e7b85baf0b66e15ed83
4
- data.tar.gz: 526857c4d776fddf9d20d96c81cf4ab6905a364601d32fb5989467439f366aea
3
+ metadata.gz: 87d7f989252a5d65c3700079656d9067f638168efb95e42e6c65f8f45e782c6b
4
+ data.tar.gz: 73b1e94053e65c3c49d3cf6160d1efa83102d55d96e80c12a9c77599cee7889f
5
5
  SHA512:
6
- metadata.gz: 815571122a732fcc85046f386ae9918c961033dc1c6141ad8d32334b2beb09ee9775b83640dad88d100d67a463468667a9dd9bbc5875e2b8612dc64fcc0d53e0
7
- data.tar.gz: 6c4146afc51d45f1f80f91c57093750160589d0d6bf89cd6df2c2f79f6d58e30525edee2a122e3b0059d7bfd2a2f0f2a1b0e3f4ceefe4f1373ad0c1892fead77
6
+ metadata.gz: fabbbf8dcf87a66a5e949f7c1adc8c6ca4557616c221dd0f2213a14046cd0a484c38e2fdc0a1c974bb3803d58b07addccd788f34d21f8d39f784c7080780ab59
7
+ data.tar.gz: 0b515c670bc053ca122b31006ed7c32494e15bbc2c1302df0ad3c8b867eec827022d5efe466a3c860e172e8b27303a517f6e52637aa228f5fa035d5986f0eda2
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
 
7
7
  gem "bcrypt_pbkdf"
8
8
  gem "colorize"
9
+ gem 'concurrent-ruby', require: 'concurrent'
9
10
  gem "e2mmap"
10
11
  gem "ed25519"
11
12
  gem "ejson"
data/bin/ops CHANGED
@@ -1,8 +1,31 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative "../loader"
4
+ require 'optparse'
5
+
6
+
7
+ def usage
8
+ puts "Usage: ops [-f|--file <ops_yml>] action [<action args>"
9
+ puts " ops_yml: the config file to load instead of './ops.yml'"
10
+ puts " action_args: arguments to the action loaded from the config file; depends on the action"
11
+
12
+ exit(1)
13
+ end
5
14
 
15
+ options = {}
16
+ while ARGV[0]&.match(/^-/)
17
+ opt = ARGV.shift
18
+ case opt
19
+ when '-f', '--file'
20
+ usage unless ARGV.length >= 1
21
+
22
+ options[:file] = ARGV.shift
23
+ else
24
+ usage
25
+ end
26
+ end
27
+
28
+ require_relative "../loader"
6
29
  require 'ops'
7
30
 
8
- Ops.new(ARGV).run
31
+ Ops.new(ARGV, config_file: options[:file]).run
data/lib/action.rb CHANGED
@@ -17,7 +17,11 @@ class Action
17
17
  raise NotAllowedInEnvError, "Action not allowed in #{Environment.environment} environment."
18
18
  end
19
19
 
20
- Kernel.exec(to_s)
20
+ if perform_shell_expansion?
21
+ Kernel.exec(to_s)
22
+ else
23
+ Kernel.exec(*to_a)
24
+ end
21
25
  end
22
26
 
23
27
  def to_s
@@ -60,6 +64,10 @@ class Action
60
64
 
61
65
  private
62
66
 
67
+ def to_a
68
+ command.split(" ").reject(&:nil?) | @args
69
+ end
70
+
63
71
  def not_in_envs
64
72
  @config["not_in_envs"] || []
65
73
  end
@@ -75,4 +83,8 @@ class Action
75
83
 
76
84
  true
77
85
  end
86
+
87
+ def perform_shell_expansion?
88
+ @config["shell_expansion"].nil? ? true : @config["shell_expansion"]
89
+ end
78
90
  end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'concurrent'
4
+
5
+ require 'builtin'
6
+ require 'output'
7
+
8
+ module Builtins
9
+ class Countdown < Builtin
10
+ USAGE_STRING = "Usage: ops countdown <seconds>"
11
+
12
+ class << self
13
+ def description
14
+ "Like `sleep`, but displays time remaining in terminal."
15
+ end
16
+ end
17
+
18
+ def run
19
+ check_args
20
+
21
+ timer_task.execute
22
+
23
+ while timer_task.running?
24
+ sleep(1)
25
+ timer_task.shutdown if task_complete?
26
+ end
27
+ Output.out("\rCountdown complete after #{sleep_seconds}s.")
28
+ end
29
+
30
+ private
31
+
32
+ def check_args
33
+ check_arg_count
34
+ check_arg_is_positive_int
35
+ end
36
+
37
+ def check_arg_count
38
+ raise Builtin::ArgumentError, USAGE_STRING unless args.length == 1
39
+ end
40
+
41
+ def check_arg_is_positive_int
42
+ raise Builtin::ArgumentError, USAGE_STRING unless sleep_seconds.positive?
43
+ # raised when the arg is not an int
44
+ rescue ::ArgumentError
45
+ raise Builtin::ArgumentError, USAGE_STRING
46
+ end
47
+
48
+ def timer_task
49
+ @timer_task ||= Concurrent::TimerTask.new(run_now: true, execution_interval: 1) do
50
+ Output.print("\r#{seconds_left}")
51
+ end
52
+ end
53
+
54
+ def sleep_seconds
55
+ Integer(args.first)
56
+ end
57
+
58
+ def task_start_time
59
+ @task_start_time ||= Time.now
60
+ end
61
+
62
+ def task_end_time
63
+ @task_end_time ||= task_start_time + sleep_seconds
64
+ end
65
+
66
+ def task_complete?
67
+ Time.now > task_end_time
68
+ end
69
+
70
+ def seconds_left
71
+ Integer(task_end_time - Time.now + 1)
72
+ end
73
+ end
74
+ end
@@ -5,11 +5,11 @@ require 'dependencies/brew'
5
5
  module Dependencies
6
6
  class Cask < Brew
7
7
  def met?
8
- execute("brew cask list #{name}")
8
+ execute("brew list --cask #{name}")
9
9
  end
10
10
 
11
11
  def meet
12
- execute("brew cask install #{name}")
12
+ execute("brew install --cask #{name}")
13
13
  end
14
14
  end
15
15
  end
data/lib/environment.rb CHANGED
@@ -13,8 +13,9 @@ class Environment
13
13
  end
14
14
  end
15
15
 
16
- def initialize(env_hash)
16
+ def initialize(env_hash, config_path)
17
17
  @env_hash = env_hash
18
+ @config_path = config_path
18
19
  end
19
20
 
20
21
  def set_variables
@@ -26,7 +27,7 @@ class Environment
26
27
  private
27
28
 
28
29
  def set_ops_variables
29
- ENV["OPS_YML_DIR"] = Dir.pwd
30
+ ENV["OPS_YML_DIR"] = File.dirname(@config_path)
30
31
  ENV["OPS_VERSION"] = Version.version.to_s
31
32
  ENV["OPS_SECRETS_FILE"] = Secrets.config_path_for(Environment.environment)
32
33
  ENV["OPS_CONFIG_FILE"] = AppConfig.config_path_for(Environment.environment)
data/lib/ops.rb CHANGED
@@ -14,8 +14,6 @@ require_rel "builtins"
14
14
 
15
15
  # executes commands based on local `ops.yml`
16
16
  class Ops
17
- CONFIG_FILE = "ops.yml"
18
-
19
17
  INVALID_SYNTAX_EXIT_CODE = 64
20
18
  UNKNOWN_ACTION_EXIT_CODE = 65
21
19
  ERROR_LOADING_APP_CONFIG_EXIT_CODE = 66
@@ -32,9 +30,10 @@ class Ops
32
30
  end
33
31
  end
34
32
 
35
- def initialize(argv)
33
+ def initialize(argv, config_file: nil)
36
34
  @action_name = argv[0]
37
35
  @args = argv[1..-1]
36
+ @config_file = config_file || "ops.yml"
38
37
 
39
38
  Options.set(config["options"] || {})
40
39
  end
@@ -98,7 +97,7 @@ class Ops
98
97
  end
99
98
 
100
99
  def runner
101
- @runner ||= Runner.new(@action_name, @args, config)
100
+ @runner ||= Runner.new(@action_name, @args, config, config_file_absolute_path)
102
101
  end
103
102
 
104
103
  def config
@@ -106,21 +105,25 @@ class Ops
106
105
  if config_file_exists?
107
106
  parsed_config_contents
108
107
  else
109
- Output.warn("File '#{CONFIG_FILE}' does not exist.") unless @action_name == "init"
108
+ Output.warn("File '#{@config_file}' does not exist.") unless @action_name == "init"
110
109
  {}
111
110
  end
112
111
  end
113
112
  end
114
113
 
115
114
  def parsed_config_contents
116
- YAML.load_file(CONFIG_FILE)
115
+ YAML.load_file(@config_file)
117
116
  rescue StandardError => e
118
- Output.warn("Error parsing '#{CONFIG_FILE}': #{e}")
117
+ Output.warn("Error parsing '#{@config_file}': #{e}")
119
118
  {}
120
119
  end
121
120
 
122
121
  def config_file_exists?
123
- File.exist?(CONFIG_FILE)
122
+ File.exist?(@config_file)
123
+ end
124
+
125
+ def config_file_absolute_path
126
+ File.expand_path(@config_file)
124
127
  end
125
128
  end
126
129
 
data/lib/runner.rb CHANGED
@@ -11,10 +11,11 @@ class Runner
11
11
  class UnknownActionError < StandardError; end
12
12
  class ActionConfigError < StandardError; end
13
13
 
14
- def initialize(action_name, args, config)
14
+ def initialize(action_name, args, config, config_path)
15
15
  @action_name = action_name
16
16
  @args = args
17
17
  @config = config
18
+ @config_path = config_path
18
19
  end
19
20
 
20
21
  def run
@@ -89,6 +90,6 @@ class Runner
89
90
  end
90
91
 
91
92
  def environment
92
- @environment ||= Environment.new(env_vars)
93
+ @environment ||= Environment.new(env_vars, @config_path)
93
94
  end
94
95
  end
data/ops_team.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ops_team'
5
- s.version = '1.0.1'
5
+ s.version = '1.3.1'
6
6
  s.authors = [
7
7
  'nickthecook@gmail.com'
8
8
  ]
@@ -29,5 +29,6 @@ Gem::Specification.new do |s|
29
29
  s.add_runtime_dependency 'ejson', '~> 1.2', '>= 1.2.1'
30
30
  s.add_runtime_dependency 'net-ssh', '~> 6.1', '>= 6.1.0'
31
31
  s.add_runtime_dependency 'require_all', '~> 1.1', '>= 1.1.6'
32
+ s.add_runtime_dependency 'concurrent-ruby', '~> 1.1', '>= 1.1.7'
32
33
  s.license = 'GPL-3.0-only'
33
34
  end
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: 1.0.1
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nickthecook@gmail.com
@@ -94,22 +94,22 @@ dependencies:
94
94
  name: net-ssh
95
95
  requirement: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- version: 6.1.0
100
97
  - - "~>"
101
98
  - !ruby/object:Gem::Version
102
99
  version: '6.1'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 6.1.0
103
103
  type: :runtime
104
104
  prerelease: false
105
105
  version_requirements: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- version: 6.1.0
110
107
  - - "~>"
111
108
  - !ruby/object:Gem::Version
112
109
  version: '6.1'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 6.1.0
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: require_all
115
115
  requirement: !ruby/object:Gem::Requirement
@@ -130,6 +130,26 @@ dependencies:
130
130
  - - ">="
131
131
  - !ruby/object:Gem::Version
132
132
  version: 1.1.6
133
+ - !ruby/object:Gem::Dependency
134
+ name: concurrent-ruby
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '1.1'
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 1.1.7
143
+ type: :runtime
144
+ prerelease: false
145
+ version_requirements: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '1.1'
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 1.1.7
133
153
  description:
134
154
  email:
135
155
  executables:
@@ -152,6 +172,7 @@ files:
152
172
  - lib/builtin.rb
153
173
  - lib/builtins/background.rb
154
174
  - lib/builtins/background_log.rb
175
+ - lib/builtins/countdown.rb
155
176
  - lib/builtins/down.rb
156
177
  - lib/builtins/env.rb
157
178
  - lib/builtins/envdiff.rb
@@ -205,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
226
  - !ruby/object:Gem::Version
206
227
  version: '0'
207
228
  requirements: []
208
- rubygems_version: 3.0.3
229
+ rubygems_version: 3.1.2
209
230
  signing_key:
210
231
  specification_version: 4
211
232
  summary: ops_team handles basic operations tasks for your project, driven by YAML