rops 1.0.4 → 1.0.8

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: 0cb5a82425bbec9b72446bf0fc951985a6c0fc95b875fbdeac257e5133d021d7
4
- data.tar.gz: d83f7db41bae9b5f4e29b754ce6cfc61fabd32bd8eb6fa5b930361747baaea52
3
+ metadata.gz: 4aaa2c9386c4426ae0e64d6c9136e208683d396af5175436e29105bd53be14f9
4
+ data.tar.gz: 2ca5c4ff6f0ff34ccdadc1a09113a3d5e4ea61d9022bc8476bb37190ccab92ab
5
5
  SHA512:
6
- metadata.gz: 642018bd50292fe94b178dc2b2af86a8b310b876f23149e280492d997fb5a02f2b1532b780ceae53cde1039eec0596dd38410152dd17e19e15a7e2cec035d959
7
- data.tar.gz: 8c665f40bc3a6cb2ac2b29192bd64bff907da8d2285b49a95467ae6bc0e6cd60819cff61c9b084e7a60783769652109725b5d8220164862fb44e9f25f2687897
6
+ metadata.gz: 4764f72f23aaa3c3a7694328cabfcea48b509fa109ae9af4487dc8b965b6c4060bb7a59d501a31eee9377983a6837da118c7fb75d1a1b497008a16678d72f17d
7
+ data.tar.gz: c3249a2060872d2606b4118c8a21b173a5aeec58d19d81d2d38f2d21ce3995280f59e3cf0d23100e470b3facb57a416c343d84cca9f09271a1b768d208ab7828
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rops (1.0.4)
4
+ rops (1.0.8)
5
5
  activesupport (~> 6.1.4)
6
6
  dry-cli (~> 0.7.0)
7
7
  git (~> 1.9.1)
data/bin/rops CHANGED
@@ -28,10 +28,11 @@ module Record360
28
28
  super()
29
29
  end
30
30
 
31
- def call(root: nil, branch: nil, context: nil, **)
31
+ def call(branch: nil, context: nil, root: nil, specs: nil, **)
32
32
  @root = root if root
33
33
  @deployer ||= Deployer.new(@root)
34
34
  deployer.branch = branch if branch
35
+ deployer.spec_dir = specs if specs
35
36
  @context = context || deployer.default_context
36
37
  end
37
38
 
@@ -141,6 +142,7 @@ module Record360
141
142
  class CurrentStatus < Dry::CLI::Command
142
143
  desc "Display status of all running specs"
143
144
  argument :context, desc: "Kubernetes context"
145
+ option :specs, desc: "Kubernetes specification directory"
144
146
  include Common
145
147
 
146
148
  def call(**)
@@ -150,8 +152,8 @@ module Record360
150
152
  end
151
153
 
152
154
  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
155
+ desc "Build the docker image"
156
+ argument :branch, desc: "Branch (or commit) to build"
155
157
  include Common
156
158
 
157
159
  def call(**)
@@ -193,9 +195,10 @@ module Record360
193
195
  desc "Deploy the docker image to the cluster"
194
196
  argument :branch, desc: "Branch (or commit) to build"
195
197
  argument :context, desc: "Kubernetes context"
198
+ option :specs, desc: "Kubernetes specification directory"
196
199
  include Common
197
200
 
198
- def call(**)
201
+ def call(specs: nil, **)
199
202
  super
200
203
  if context == production_context
201
204
  if branch.blank?
@@ -222,10 +225,10 @@ module Record360
222
225
  end
223
226
 
224
227
  if $stdout.tty?
225
- print "Deploy #{branch} (#{image_tag}) to #{context}? (y/N): "
228
+ print "Deploy #{deployer.branch} (#{image_tag}) to #{context}? (y/N): "
226
229
  exit(-1) unless $stdin.gets&.chomp == 'y'
227
230
  else
228
- puts "Deploying #{branch} (#{image_tag}) to #{context}"
231
+ puts "Deploying #{deployer.branch} (#{image_tag}) to #{context}"
229
232
  end
230
233
 
231
234
  deployer.deploy!(context)
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
@@ -68,7 +67,7 @@ class Image
68
67
  if status.success? || stderr.include?('error parsing manifest blob')
69
68
  @remote_exists = true
70
69
  else
71
- puts stderr if stderr.present? && !stderr.include?('manifest unknown')
70
+ puts stderr if stderr.present? && !stderr.include?('manifest unknown') && !stderr.include?('no such manifest')
72
71
  @remote_exists = false
73
72
  end
74
73
  end
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
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.4
4
+ version: 1.0.8
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-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -107,10 +107,12 @@ 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
114
116
  homepage: https://github.com/Record360/rops
115
117
  licenses:
116
118
  - MIT