cpl 0.7.0 → 1.0.0

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: 976c390927b51f67afe7a161b7185242261afb4c24db893026457b205fe61b12
4
- data.tar.gz: b55bec82c485eb413c9a8787d34172e2c7e89212c15e319f3f626c652c3ac6e7
3
+ metadata.gz: 410e8bfdc923cabc36b900bb6cc3bb98e586cc2789579ec01cc33fe9c9c39fe1
4
+ data.tar.gz: a7428c35cff0dabcd1c68469561b82e2c3f24282b92dba9b1eeeb94c51d9d654
5
5
  SHA512:
6
- metadata.gz: 678825b452c56d5c481639de70904ab087f29e362c4b8ced34d3c2131f15a176f78c0c928b02449ebc96a0e69bd1e5c2cd1982577e06a0b62000aa0993bd4f91
7
- data.tar.gz: a40e2ea6bfb43122c919d9126d6fffdb6a9722396bed1c4b22b5874d06f9b2126ee4f14e6df37047bb417bcb0788b3b19869d03b34801030b6e8e373f47950c2
6
+ metadata.gz: 9c09fb9477e7dd638220e4ad711161a176daab7e82ed7224d584b6617989e3dd789ae5f66eb75e0086bdcd9690d680e2de668b5698ce322184ecdd23522835a3
7
+ data.tar.gz: 82f3a8aaf6b465850f9b577c5f7aed1b8b4313bf0224d52f058fc94e17f334a9cb9f51bb2638600c150184714fb254c2edeea1bb1f77b40a976fe20d0db11b54
@@ -0,0 +1,24 @@
1
+ name: Command Docs
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+
9
+ jobs:
10
+ rspec:
11
+ runs-on: ubuntu-latest
12
+ name: Command Docs
13
+ steps:
14
+ - name: Checkout code
15
+ uses: actions/checkout@v3
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: "3.0"
20
+ bundler-cache: true
21
+ - name: Install dependencies
22
+ run: bundle install
23
+ - name: Check if command docs are up to date
24
+ run: bundle exec rake check_command_docs
@@ -8,15 +8,18 @@ on:
8
8
 
9
9
  jobs:
10
10
  rspec:
11
- runs-on: ubuntu-latest
12
- name: RSpec
13
- env:
14
- RAILS_ENV: test
15
11
  strategy:
16
12
  matrix:
13
+ os:
14
+ - ubuntu-latest
15
+ - macos-latest
17
16
  ruby:
18
17
  - "2.7"
19
18
  - "3.0"
19
+ runs-on: ${{ matrix.os }}
20
+ name: RSpec
21
+ env:
22
+ RAILS_ENV: test
20
23
  steps:
21
24
  - name: Checkout code
22
25
  uses: actions/checkout@v3
@@ -28,7 +31,7 @@ jobs:
28
31
  - name: Install dependencies
29
32
  run: bundle install
30
33
  - name: Run tests
31
- run: bundle exec rspec spec
34
+ run: bundle exec rspec
32
35
  - name: Upload coverage results
33
36
  uses: actions/upload-artifact@master
34
37
  if: always()
@@ -8,13 +8,16 @@ on:
8
8
 
9
9
  jobs:
10
10
  rubocop:
11
- runs-on: ubuntu-latest
12
- name: Rubocop
13
11
  strategy:
14
12
  matrix:
13
+ os:
14
+ - ubuntu-latest
15
+ - macos-latest
15
16
  ruby:
16
17
  - "2.7"
17
18
  - "3.0"
19
+ runs-on: ${{ matrix.os }}
20
+ name: Rubocop
18
21
  steps:
19
22
  - name: Checkout code
20
23
  uses: actions/checkout@v3
data/.overcommit.yml CHANGED
@@ -1,4 +1,7 @@
1
1
  PreCommit:
2
+ CommandDocs:
3
+ enabled: true
4
+ command: ["bundle", "exec", "rake", "check_command_docs"]
2
5
  RuboCop:
3
6
  enabled: true
4
7
  on_warn: fail
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cpl (0.7.0)
4
+ cpl (1.0.0)
5
5
  debug (~> 1.7.1)
6
6
  dotenv (~> 2.8.1)
7
7
  psych (~> 5.1.0)
@@ -41,7 +41,7 @@ GEM
41
41
  rainbow (3.1.1)
42
42
  rake (13.0.6)
43
43
  regexp_parser (2.6.2)
44
- reline (0.3.3)
44
+ reline (0.3.4)
45
45
  io-console (~> 0.5)
46
46
  rexml (3.2.5)
47
47
  rspec (3.12.0)
data/Rakefile CHANGED
@@ -10,7 +10,12 @@ RuboCop::RakeTask.new
10
10
 
11
11
  task default: %i[rspec rubocop]
12
12
 
13
+ desc "Checks if commands.md file is up to date"
14
+ task :check_command_docs do
15
+ sh "./script/check_command_docs"
16
+ end
17
+
13
18
  desc "Updates commands.md file"
14
- task :command_docs do
15
- sh "./script/generate_commands_docs"
19
+ task :update_command_docs do
20
+ sh "./script/update_command_docs"
16
21
  end
data/lib/command/base.rb CHANGED
@@ -187,28 +187,22 @@ module Command
187
187
  end
188
188
  end
189
189
 
190
- def wait_for(title)
191
- progress.print "- Waiting for #{title}"
192
- until yield
193
- progress.print(".")
194
- sleep(1)
195
- end
196
- progress.puts
197
- end
198
-
199
190
  def wait_for_workload(workload)
200
- wait_for("workload to start") { cp.fetch_workload(workload) }
191
+ step("Waiting for workload", retry_on_failure: true) do
192
+ cp.fetch_workload(workload)
193
+ end
201
194
  end
202
195
 
203
196
  def wait_for_replica(workload, location)
204
- wait_for("replica") do
197
+ step("Waiting for replica", retry_on_failure: true) do
205
198
  cp.workload_get_replicas_safely(workload, location: location)&.dig("items", 0)
206
199
  end
207
200
  end
208
201
 
209
202
  def ensure_workload_deleted(workload)
210
- progress.puts "- Ensure workload is deleted"
211
- cp.delete_workload(workload)
203
+ step("Deleting workload") do
204
+ cp.delete_workload(workload)
205
+ end
212
206
  end
213
207
 
214
208
  def latest_image_from(items, app_name: config.app, name_only: true)
data/lib/command/run.rb CHANGED
@@ -56,24 +56,26 @@ module Command
56
56
 
57
57
  attr_reader :location, :workload, :one_off, :container
58
58
 
59
- def call
59
+ def call # rubocop:disable Metrics/MethodLength
60
60
  @location = config[:default_location]
61
61
  @workload = config.options["workload"] || config[:one_off_workload]
62
62
  @one_off = "#{workload}-run-#{rand(1000..9999)}"
63
63
 
64
- clone_workload
64
+ step("Cloning workload '#{workload}' on app '#{config.options[:app]}' to '#{one_off}'") do
65
+ clone_workload
66
+ end
67
+
65
68
  wait_for_workload(one_off)
66
69
  wait_for_replica(one_off, location)
67
70
  run_in_replica
68
71
  ensure
72
+ progress.puts
69
73
  ensure_workload_deleted(one_off)
70
74
  end
71
75
 
72
76
  private
73
77
 
74
78
  def clone_workload # rubocop:disable Metrics/MethodLength
75
- progress.puts "- Cloning workload '#{workload}' on '#{config.options[:app]}' to '#{one_off}'"
76
-
77
79
  # Create a base copy of workload props
78
80
  spec = cp.fetch_workload!(workload).fetch("spec")
79
81
  container_spec = spec["containers"].detect { _1["name"] == workload } || spec["containers"].first
@@ -127,7 +129,7 @@ module Command
127
129
  if config.options[:terminal_size]
128
130
  rows, cols = config.options[:terminal_size].split(",")
129
131
  else
130
- rows, cols = `stty -a`.match(/(\d+)\s*rows;\s*(\d+)\s*columns/).captures
132
+ rows, cols = `stty size`.split(/\s+/)
131
133
  end
132
134
  script += "stty rows #{rows}\nstty cols #{cols}\n" if rows && cols
133
135
  end
@@ -137,7 +139,7 @@ module Command
137
139
  end
138
140
 
139
141
  def run_in_replica
140
- progress.puts "- Connecting"
142
+ progress.puts("Connecting...\n\n")
141
143
  command = %(bash -c 'eval "$CONTROLPLANE_RUNNER"')
142
144
  cp.workload_exec(one_off, location: location, container: container, command: command)
143
145
  end
@@ -47,24 +47,28 @@ module Command
47
47
 
48
48
  attr_reader :location, :workload, :one_off, :container
49
49
 
50
- def call
50
+ def call # rubocop:disable Metrics/MethodLength
51
51
  @location = config[:default_location]
52
52
  @workload = config.options["workload"] || config[:one_off_workload]
53
53
  @one_off = "#{workload}-runner-#{rand(1000..9999)}"
54
54
 
55
- clone_workload
55
+ step("Cloning workload '#{workload}' on app '#{config.options[:app]}' to '#{one_off}'") do
56
+ clone_workload
57
+ end
58
+
56
59
  wait_for_workload(one_off)
57
60
  show_logs_waiting
58
61
  ensure
59
- ensure_workload_deleted(one_off)
62
+ if cp.fetch_workload(one_off)
63
+ progress.puts
64
+ ensure_workload_deleted(one_off)
65
+ end
60
66
  exit(1) if @crashed
61
67
  end
62
68
 
63
69
  private
64
70
 
65
71
  def clone_workload # rubocop:disable Metrics/MethodLength
66
- progress.puts "- Cloning workload '#{workload}' on '#{config.options[:app]}' to '#{one_off}'"
67
-
68
72
  # Get base specs of workload
69
73
  spec = cp.fetch_workload!(workload).fetch("spec")
70
74
  container_spec = spec["containers"].detect { _1["name"] == workload } || spec["containers"].first
@@ -121,17 +125,17 @@ module Command
121
125
  end
122
126
 
123
127
  def show_logs_waiting # rubocop:disable Metrics/MethodLength
124
- progress.puts "- Scheduled, fetching logs (it is cron job, so it may take up to a minute to start)"
128
+ progress.puts("Scheduled, fetching logs (it's a cron job, so it may take up to a minute to start)...\n\n")
125
129
  begin
126
130
  while cp.fetch_workload(one_off)
127
131
  sleep(WORKLOAD_SLEEP_CHECK)
128
132
  print_uniq_logs
129
133
  end
130
134
  rescue RuntimeError => e
131
- progress.puts "ERROR: #{e}"
135
+ progress.puts(Shell.color("ERROR: #{e}", :red))
132
136
  retry
133
137
  end
134
- progress.puts "- Finished workload and logger"
138
+ progress.puts("\nFinished workload and logger.")
135
139
  end
136
140
 
137
141
  def print_uniq_logs
data/lib/core/scripts.rb CHANGED
@@ -10,7 +10,7 @@ module Scripts
10
10
  -H "Authorization: ${CONTROLPLANE_TOKEN}" -s | grep -o '"replicas":[0-9]*' | grep -o '[0-9]*')
11
11
 
12
12
  if [ "$REPLICAS_QTY" -gt 0 ]; then
13
- echo "-- MULTIPLE REPLICAS ATTEMPT !!!! replicas: $REPLICAS_QTY"
13
+ echo "-- MULTIPLE REPLICAS ATTEMPT: $REPLICAS_QTY --"
14
14
  exit -1
15
15
  fi
16
16
  SHELL
@@ -24,7 +24,7 @@ module Scripts
24
24
 
25
25
  # NOTE: please escape all '/' as '//' (as it is ruby interpolation here as well)
26
26
  def http_dummy_server_ruby
27
- 'require "socket";s=TCPServer.new(ENV["PORT"]);' \
27
+ 'require "socket";s=TCPServer.new(ENV["PORT"] || 80);' \
28
28
  'loop do c=s.accept;c.puts("HTTP/1.1 200 OK\\nContent-Length: 2\\n\\nOk");c.close end'
29
29
  end
30
30
 
data/lib/cpl/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cpl
4
- VERSION = "0.7.0"
4
+ VERSION = "1.0.0"
5
5
  end
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+ bundle exec rake update_command_docs
3
+ git diff --exit-code || exit 1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-05-19 00:00:00.000000000 Z
12
+ date: 2023-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: debug
@@ -202,6 +202,7 @@ executables:
202
202
  extensions: []
203
203
  extra_rdoc_files: []
204
204
  files:
205
+ - ".github/workflows/command_docs.yml"
205
206
  - ".github/workflows/rspec.yml"
206
207
  - ".github/workflows/rubocop.yml"
207
208
  - ".gitignore"
@@ -269,8 +270,9 @@ files:
269
270
  - lib/main.rb
270
271
  - rakelib/create_release.rake
271
272
  - script/add_command
272
- - script/generate_commands_docs
273
+ - script/check_command_docs
273
274
  - script/rename_command
275
+ - script/update_command_docs
274
276
  - templates/daily-task.yml
275
277
  - templates/gvc.yml
276
278
  - templates/identity.yml