rops 1.0.5 → 1.1.0

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: 251592c08814310a14cc0530cb79be6d18510b28393211810690495c559c4632
4
- data.tar.gz: 0a4aee08e4858051f0f555b1ca322a661673231ccd0da4c6258f604ed87eb5d7
3
+ metadata.gz: 6c165439c24766bf43fb4cbf561e8fefdd0bb8b4cb50534577289edd54fbca89
4
+ data.tar.gz: 7e62f623efbe2f6335030a42482cb0768bb61af1bb93e562ba385314e78bd57a
5
5
  SHA512:
6
- metadata.gz: ff89c2f68f4a214da8d451f95719c512f816913a5bc40cc5c8e04e1440d99a0f9d53f7dc70228637dc61ebbc311eb7f8987b4e0f86deb4abc10954d1a7c5de79
7
- data.tar.gz: de710e909b10d21e70a6f7386ee79d94311cd84a7cfe0f0d67b966cb92251463911890dd1ae0ea2ac7cc2b4d57c62e9ddd92badc29e9e0571a6acbe356a822ab
6
+ metadata.gz: 573db01279424e05de52740d435eadf998fe6f79248908c3dbd4a33864cce8c9cae2cb7a3dcf328af6c1e1b60e2a4511663ffb63a4273a8cd53eaa65dd4f74b0
7
+ data.tar.gz: 40dbd0654aca609a450588c4eb2f5d59d8715db4664d626aa9148b0fc46d180e1bbf473d859409af4dccf3354cdfc36d016b6b72b1f9180d9d3202e9f58d17a3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rops (1.0.5)
4
+ rops (1.1.0)
5
5
  activesupport (~> 6.1.4)
6
6
  dry-cli (~> 0.7.0)
7
7
  git (~> 1.9.1)
data/bin/rops CHANGED
@@ -9,6 +9,7 @@ require 'hashdiff'
9
9
 
10
10
  require 'core_ext'
11
11
  require 'deployer'
12
+ require 'version'
12
13
 
13
14
  module Record360
14
15
  module Operations
@@ -28,10 +29,11 @@ module Record360
28
29
  super()
29
30
  end
30
31
 
31
- def call(root: nil, branch: nil, context: nil, **)
32
+ def call(branch: nil, context: nil, root: nil, specs: nil, **)
32
33
  @root = root if root
33
34
  @deployer ||= Deployer.new(@root)
34
35
  deployer.branch = branch if branch
36
+ deployer.spec_dir = specs if specs
35
37
  @context = context || deployer.default_context
36
38
  end
37
39
 
@@ -141,6 +143,7 @@ module Record360
141
143
  class CurrentStatus < Dry::CLI::Command
142
144
  desc "Display status of all running specs"
143
145
  argument :context, desc: "Kubernetes context"
146
+ option :specs, desc: "Kubernetes specification directory"
144
147
  include Common
145
148
 
146
149
  def call(**)
@@ -150,8 +153,8 @@ module Record360
150
153
  end
151
154
 
152
155
  class BuildImage < Dry::CLI::Command
153
- desc "Build the docker image" #" (COMMIT=#{DEFAULT_COMMIT})"
154
- argument :branch, desc: "Branch (or commit) to build" #, default: DEFAULT_COMMIT
156
+ desc "Build the docker image"
157
+ argument :branch, desc: "Branch (or commit) to build"
155
158
  include Common
156
159
 
157
160
  def call(**)
@@ -193,9 +196,10 @@ module Record360
193
196
  desc "Deploy the docker image to the cluster"
194
197
  argument :branch, desc: "Branch (or commit) to build"
195
198
  argument :context, desc: "Kubernetes context"
199
+ option :specs, desc: "Kubernetes specification directory"
196
200
  include Common
197
201
 
198
- def call(**)
202
+ def call(specs: nil, **)
199
203
  super
200
204
  if context == production_context
201
205
  if branch.blank?
@@ -222,20 +226,28 @@ module Record360
222
226
  end
223
227
 
224
228
  if $stdout.tty?
225
- print "Deploy #{branch} (#{image_tag}) to #{context}? (y/N): "
229
+ print "Deploy #{deployer.branch} (#{image_tag}) to #{context}? (y/N): "
226
230
  exit(-1) unless $stdin.gets&.chomp == 'y'
227
231
  else
228
- puts "Deploying #{branch} (#{image_tag}) to #{context}"
232
+ puts "Deploying #{deployer.branch} (#{image_tag}) to #{context}"
229
233
  end
230
234
 
231
235
  deployer.deploy!(context)
232
236
  end
233
237
  end
234
238
 
239
+ class Version < Dry::CLI::Command
240
+ desc "output version information and exit"
241
+ def call
242
+ puts VERSION
243
+ end
244
+ end
245
+
235
246
  register 'status', CurrentStatus
236
247
  register 'build', BuildImage
237
248
  register 'push', PushImage
238
249
  register 'deploy', DeployImage
250
+ register 'version', Version
239
251
  end
240
252
  end
241
253
 
data/lib/buildable.rb ADDED
@@ -0,0 +1,17 @@
1
+ class Buildable
2
+ attr_reader :name, :repository, :commit
3
+ attr_writer :commit
4
+
5
+ def initialize(name:, repository:, commit:)
6
+ @name = name.downcase
7
+ @repository = repository
8
+ @commit = commit
9
+ end
10
+
11
+ def checkout # :yields: source directory
12
+ Dir.mktmpdir("#{name}-build") do |dir|
13
+ system("git -C #{repository} archive #{commit} | tar -x -C #{dir}") or raise "Git error"
14
+ yield dir
15
+ end
16
+ end
17
+ end
data/lib/deployer.rb CHANGED
@@ -18,6 +18,7 @@ class Deployer
18
18
  attr_reader :root, :repository, :registry, :ssh_host, :images
19
19
  attr_reader :default_branch, :default_context, :production_context
20
20
  attr_reader :branch, :commit, :image_tag
21
+ attr_accessor :spec_dir
21
22
 
22
23
  def self.docker
23
24
  @docker_path ||= File.which('docker') || File.which('podman')
@@ -44,8 +45,8 @@ class Deployer
44
45
 
45
46
  short_id = @commit[0, 8]
46
47
  @image_tag = "g#{short_id}"
47
- if branch.present? && (branch != default_branch) && !branch.start_with?(short_id)
48
- @image_tag += "-#{branch}"
48
+ if (@branch != default_branch) && !@branch.start_with?(short_id)
49
+ @image_tag += "-#{@branch}"
49
50
  end
50
51
  images.each do |image|
51
52
  image.commit = commit
@@ -54,8 +55,7 @@ class Deployer
54
55
  end
55
56
 
56
57
  def specs_running(context = nil)
57
- context ||= default_context
58
- context = context.to_s
58
+ context = (context || default_context).to_s
59
59
  specs = deploy_specs(context)
60
60
 
61
61
  cmd = String.new "--output=json"
@@ -68,7 +68,7 @@ class Deployer
68
68
  end
69
69
 
70
70
  statuses, stderr, success = kubectl(context, cmd)
71
- unless success || stderr.match(/not found/)
71
+ unless (success || stderr.match(/not found/)) && statuses.present?
72
72
  puts stderr if stderr.present?
73
73
  return nil
74
74
  end
@@ -93,8 +93,7 @@ class Deployer
93
93
  end
94
94
 
95
95
  def deploy!(context)
96
- context ||= default_context
97
- context = context.to_s
96
+ context = (context || default_context).to_s
98
97
  specs = deploy_specs(context).presence or raise "No kubernetes specs to deploy"
99
98
  stdout, stderr, _success = kubectl(context, 'apply -f -', YAML.dump_stream(*specs))
100
99
  puts stdout if stdout.present?
@@ -122,11 +121,11 @@ class Deployer
122
121
  end
123
122
 
124
123
  def specs(context = nil)
125
- context ||= default_context
126
- context = context.to_s
127
- @specs[context] ||= begin
128
- paths = git.ls_tree(commit, "platform/#{context}/")['blob'].keys
129
- raise "No specs found for context #{context}" unless paths.present?
124
+ spec_dir = self.spec_dir.presence || (context || default_context).to_s
125
+ @specs[spec_dir] ||= begin
126
+ spec_dir = "platform/#{spec_dir}/"
127
+ paths = git.ls_tree(commit, spec_dir)['blob'].keys
128
+ raise "No specs found in #{spec_dir}" unless paths.present?
130
129
  paths.map { |path| YAML.load_stream( git.show(commit, path) ) }.flatten.compact
131
130
  end
132
131
  end
data/lib/image.rb CHANGED
@@ -1,16 +1,15 @@
1
- class Image
1
+ require 'buildable'
2
+
3
+ class Image < Buildable
2
4
  def self.build_cores
3
5
  @build_cores ||= ENV.fetch('R360_BUILD_CORES', [ 1, Concurrent::Utility::ProcessorCounter.new.processor_count - 1 ].max).to_i
4
6
  end
5
7
 
6
- attr_reader :name, :repository, :dockerfile, :commit, :tag, :registry
7
- attr_writer :commit
8
+ attr_reader :dockerfile, :tag, :registry
8
9
 
9
- def initialize(name:, repository:, dockerfile:, commit:, tag:, registry:)
10
- @name = name.downcase
11
- @repository = repository
10
+ def initialize(name:, repository:, commit:, dockerfile:, tag:, registry:)
11
+ super(name: name, repository: repository, commit: commit)
12
12
  @dockerfile = dockerfile
13
- @commit = commit
14
13
  @tag = tag
15
14
  @registry = registry
16
15
  end
@@ -22,9 +21,7 @@ class Image
22
21
 
23
22
  def build!
24
23
  return if local_exists?
25
-
26
- Dir.mktmpdir("#{name}-build") do |dir|
27
- system("git -C #{repository} archive #{commit} | tar -x -C #{dir}") and
24
+ checkout do |dir|
28
25
  system("#{Deployer.docker} build -f #{dockerfile} -t #{local_image} --build-arg JOBS=#{Image.build_cores} --build-arg GIT_VERSION=#{commit} #{dir}")
29
26
  end
30
27
  end
@@ -54,7 +51,9 @@ class Image
54
51
  end
55
52
 
56
53
  def local_exists?
57
- system("#{Deployer.docker} image exists #{local_image}")
54
+ if @local_exists.nil?
55
+ @local_exists = system("#{Deployer.docker} image exists #{local_image}")
56
+ end
58
57
  end
59
58
 
60
59
  def remote_image
data/lib/site.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'buildable'
2
+
3
+ class Site < Buildable
4
+ attr_reader :script # NPM build script
5
+ attr_reader :bucket # S3 bucket
6
+ attr_reader :distribution # CloudFront distribution
7
+
8
+ def initialize(name:, repository:, commit:, script:, bucket:, distribution:)
9
+ super(name: name, repository: repository, commit: commit)
10
+ @script = script
11
+ @bucket = bucket
12
+ @distribution = distribution
13
+ end
14
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Record360
2
+ module Operations
3
+ VERSION = '1.1.0'
4
+ end
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rops
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Sloan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-27 00:00:00.000000000 Z
11
+ date: 2021-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -107,10 +107,13 @@ files:
107
107
  - LICENSE
108
108
  - README.md
109
109
  - bin/rops
110
+ - lib/buildable.rb
110
111
  - lib/core_ext.rb
111
112
  - lib/deployer.rb
112
113
  - lib/git_ext.rb
113
114
  - lib/image.rb
115
+ - lib/site.rb
116
+ - lib/version.rb
114
117
  homepage: https://github.com/Record360/rops
115
118
  licenses:
116
119
  - MIT