rops 1.0.6 → 1.2.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: 0b842710deb5849c4ee8342b766505a55c8e6778db4afbb79c6fa20768d6e43c
4
- data.tar.gz: fe1df084466ab6019f9f85ba958ecda306f44757ff505ede0b8867f639e86706
3
+ metadata.gz: 35e79d0ac5ba9b1b390e4764445c2d7ea0baefbb6f87546f951b350b56845f4a
4
+ data.tar.gz: 50b2360868d759353b36cf1fc0e27439762fe973eb6b57c14240a1b747d6a992
5
5
  SHA512:
6
- metadata.gz: 5039b8251bb501bd3ac8c4006ae82f23d998e2dc57c6a7c0e579c55d62140a2e9f517a3a3c61d373b30c5ed3211c90f035d86b91fca5d65fd765d883095d2ba0
7
- data.tar.gz: 88fc34f86355c4c2917c916712ca1e3bbd7077c736e66a56081b4b9517d6ef646f022143732374d1fe1540110935f7fd8e7e6ff79f3c01d82dfc9d5ca57fed7f
6
+ metadata.gz: 9481dce3e2fd292a47ea25ad00df8b230f47061f060b3fd65514b9f8e063c8645808a30a807f6a85055751948783b2f7dfd46891c632e7934cd874bd5359cca5
7
+ data.tar.gz: 05b384626c27d7d0582c6000259acfa2f118734a8e25e30b1041bf481fedbb4bf23fc2d980b3d8da6ba46f0939dfdfab95561a0c8810b1d7f2cf9b69b3c5fc4b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rops (1.0.6)
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')
@@ -42,11 +43,7 @@ class Deployer
42
43
  @branch.delete_prefix!('g') if @branch.match(/^g\h{8}$/)
43
44
  @commit = git.object(@branch).sha
44
45
 
45
- short_id = @commit[0, 8]
46
- @image_tag = "g#{short_id}"
47
- if branch.present? && (branch != default_branch) && !branch.start_with?(short_id)
48
- @image_tag += "-#{branch}"
49
- end
46
+ @image_tag = @commit[0, 8]
50
47
  images.each do |image|
51
48
  image.commit = commit
52
49
  image.tag = image_tag
@@ -54,8 +51,7 @@ class Deployer
54
51
  end
55
52
 
56
53
  def specs_running(context = nil)
57
- context ||= default_context
58
- context = context.to_s
54
+ context = (context || default_context).to_s
59
55
  specs = deploy_specs(context)
60
56
 
61
57
  cmd = String.new "--output=json"
@@ -93,8 +89,7 @@ class Deployer
93
89
  end
94
90
 
95
91
  def deploy!(context)
96
- context ||= default_context
97
- context = context.to_s
92
+ context = (context || default_context).to_s
98
93
  specs = deploy_specs(context).presence or raise "No kubernetes specs to deploy"
99
94
  stdout, stderr, _success = kubectl(context, 'apply -f -', YAML.dump_stream(*specs))
100
95
  puts stdout if stdout.present?
@@ -122,11 +117,11 @@ class Deployer
122
117
  end
123
118
 
124
119
  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?
120
+ spec_dir = self.spec_dir.presence || (context || default_context).to_s
121
+ @specs[spec_dir] ||= begin
122
+ spec_dir = "platform/#{spec_dir}/"
123
+ paths = git.ls_tree(commit, spec_dir)['blob'].keys
124
+ raise "No specs found in #{spec_dir}" unless paths.present?
130
125
  paths.map { |path| YAML.load_stream( git.show(commit, path) ) }.flatten.compact
131
126
  end
132
127
  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
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.2.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.6
4
+ version: 1.2.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-28 00:00:00.000000000 Z
11
+ date: 2021-11-11 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