kuby-core 0.11.11 → 0.11.16

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: 78bc9ff66849f7b55046753a84be77fd64af68d28c1746245a463f5f240d0e9e
4
- data.tar.gz: '079e0ccccc1ae12a18a2cb459e7a6b1f2b3ef05149d5bf347fed5ba1e6abbb2b'
3
+ metadata.gz: 01cc5428a8bc4bfc44143f4aa2c2e949405d3c7231831da50f33efa5a314fc29
4
+ data.tar.gz: c4e440506c9ad072449f3382bcfa7dd1f80c757e64426b5c49f1e20540c57ae8
5
5
  SHA512:
6
- metadata.gz: f27a9bd4698e6cdcb4c0308c91a78e5c86ac6eccd6dcd8f9ff1b28a73e8c1aa50f79512dc9ad3b5fdb43c024ba5054c1df1844bd74473c5bd9dd3c3cf034c7c4
7
- data.tar.gz: fca6952c0bfe4cb5d2e6e9b0f4f50d46483bb43ad32d601dbdfcc14eeccb4070706043e786d18ade2730b9521443f55fb317620334f212fb88cfb92ab8672cb1
6
+ metadata.gz: 5db95c1958618d58354ba4c87411a0cd52894ede6ba0fbd622479e66e327397967314979c7496806577115d6b22571582e17f76c720a8472c9568cb009682555
7
+ data.tar.gz: 2c1c1bd58fcbc7d29380e5e2ef2cf71b68f7073dbff26ca5d73333734b326dccc42243a559b3272502b4a6628db0c7513ea9b6586b5475e44108ba4a490734f5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## 0.11.16
2
+ * Fix yarn phase
3
+ - Apparently you have to copy at least one file, TIL.
4
+
5
+ ## 0.11.15
6
+ * Copy over .npmrc and .yarnrc before running yarn install.
7
+
8
+ ## 0.11.14
9
+ * Don't include port in image host for registry secrets (no idea why)
10
+
11
+ ## 0.11.13
12
+ * Include port in image host.
13
+
14
+ ## 0.11.12
15
+ * Revamp Docker URL parsing
16
+ - Docker URLs shouldn't have a scheme.
17
+
1
18
  ## 0.11.11
2
19
  * Add support for a Docker registry running on localhost.
3
20
  - Correctly parse and handle URLs with specific ports.
data/Gemfile CHANGED
@@ -5,7 +5,8 @@ gemspec
5
5
  group :development, :test do
6
6
  gem 'pry-byebug'
7
7
  gem 'rake'
8
- gem 'sorbet', '~> 0.5'
8
+ # lock to a specific version to prevent breaking CI when new versions come out
9
+ gem 'sorbet', '= 0.5.6397'
9
10
  end
10
11
 
11
12
  group :test do
data/bin/kuby CHANGED
@@ -1,4 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
+ $stdout.sync = true
4
+
3
5
  require 'kuby'
4
6
  exit Kuby::Commands.run(ARGV)
data/kuby-core.gemspec CHANGED
@@ -1,4 +1,4 @@
1
- $:.unshift File.join(File.dirname(__FILE__), 'lib')
1
+ $:.unshift File.expand_path('lib', __dir__)
2
2
  require 'kuby/version'
3
3
 
4
4
  Gem::Specification.new do |s|
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.platform = Gem::Platform::RUBY
14
14
 
15
15
  s.add_dependency 'colorize', '~> 0.8'
16
- s.add_dependency 'docker-remote', '~> 0.1'
16
+ s.add_dependency 'docker-remote', '~> 0.5'
17
17
  s.add_dependency 'gli', '~> 2.0'
18
18
  s.add_dependency 'helm-cli', '~> 0.3'
19
19
  # See: https://github.com/Shopify/krane/pull/720
data/lib/kuby.rb CHANGED
@@ -153,6 +153,7 @@ end
153
153
 
154
154
  # providers
155
155
  Kuby.register_provider(:docker_desktop, Kuby::Kubernetes::DockerDesktopProvider)
156
+ Kuby.register_provider(:bare_metal, Kuby::Kubernetes::BareMetalProvider)
156
157
 
157
158
  # plugins
158
159
  Kuby.register_plugin(:rails_app, Kuby::Plugins::RailsApp::Plugin)
@@ -52,7 +52,7 @@ module Kuby
52
52
  block: T.nilable(T.proc.returns(T.untyped))
53
53
  ).void
54
54
  }
55
- def fatal(progname_or_msg, &block)
55
+ def fatal(progname_or_msg = nil, &block)
56
56
  if block
57
57
  super(progname_or_msg) { ColorizedString[block.call].red }
58
58
  else
data/lib/kuby/cli_base.rb CHANGED
@@ -7,21 +7,26 @@ module Kuby
7
7
  class CLIBase
8
8
  extend T::Sig
9
9
 
10
+ BeforeCallback = T.type_alias { T.proc.params(cmd: T::Array[String]).void }
11
+ AfterCallback = T.type_alias do
12
+ T.proc.params(cmd: T::Array[String], last_status: T.nilable(Process::Status)).void
13
+ end
14
+
10
15
  sig { returns(T.nilable(Process::Status)) }
11
16
  def last_status
12
17
  Thread.current[status_key]
13
18
  end
14
19
 
15
- sig { params(block: T.proc.params(cmd: String).void).void }
20
+ sig { params(block: BeforeCallback).void }
16
21
  def before_execute(&block)
17
- @before_execute = T.let(@before_execute, T.nilable(T::Array[T.proc.params(cmd: String).void]))
22
+ @before_execute = T.let(@before_execute, T.nilable(T::Array[BeforeCallback]))
18
23
  @before_execute ||= []
19
24
  @before_execute << block
20
25
  end
21
26
 
22
- sig { params(block: T.proc.params(cmd: String).void).void }
27
+ sig { params(block: AfterCallback).void }
23
28
  def after_execute(&block)
24
- @after_execute = T.let(@after_execute, T.nilable(T::Array[T.proc.params(cmd: String).void]))
29
+ @after_execute = T.let(@after_execute, T.nilable(T::Array[AfterCallback]))
25
30
  @after_execute ||= []
26
31
  @after_execute << block
27
32
  end
data/lib/kuby/docker.rb CHANGED
@@ -14,6 +14,7 @@ module Kuby
14
14
  autoload :DevSpec, 'kuby/docker/dev_spec'
15
15
  autoload :Distro, 'kuby/docker/distro'
16
16
  autoload :Dockerfile, 'kuby/docker/dockerfile'
17
+ autoload :DockerURI, 'kuby/docker/docker_uri'
17
18
  autoload :InlineLayer, 'kuby/docker/inline_layer'
18
19
  autoload :Layer, 'kuby/docker/layer'
19
20
  autoload :LayerStack, 'kuby/docker/layer_stack'
@@ -51,10 +51,6 @@ module Kuby
51
51
  dockerfile.copy(gf, '.')
52
52
  dockerfile.copy(lf, '.')
53
53
 
54
- # set bundle path so docker will cache the bundle
55
- dockerfile.run('mkdir', './bundle')
56
- dockerfile.env('BUNDLE_PATH=./bundle')
57
-
58
54
  unless wo.empty?
59
55
  dockerfile.env("BUNDLE_WITHOUT='#{wo.join(' ')}'")
60
56
  end
@@ -0,0 +1,34 @@
1
+ # typed: false
2
+
3
+ module Kuby
4
+ module Docker
5
+ class DockerURI
6
+ DEFAULT_REGISTRY_HOST = 'index.docker.io'.freeze
7
+ DEFAULT_REGISTRY_PORT = 443
8
+
9
+ def self.parse(url)
10
+ if idx = url.index('://')
11
+ url = url[(idx + 3)..-1] || ''
12
+ end
13
+
14
+ host_port, *path = url.split('/')
15
+ host, port, *path = if host_port =~ /[.:]/
16
+ hst, prt = host_port.split(':')
17
+ [hst, prt || DEFAULT_REGISTRY_PORT, *path]
18
+ else
19
+ [DEFAULT_REGISTRY_HOST, DEFAULT_REGISTRY_PORT, host_port, *path]
20
+ end
21
+
22
+ new(host, port.to_i, path.join('/'))
23
+ end
24
+
25
+ attr_reader :host, :port, :path
26
+
27
+ def initialize(host, port, path)
28
+ @host = host
29
+ @port = port
30
+ @path = path
31
+ end
32
+ end
33
+ end
34
+ end
@@ -8,8 +8,6 @@ module Kuby
8
8
  extend T::Sig
9
9
 
10
10
  DEFAULT_DISTRO = :debian
11
- DEFAULT_REGISTRY_HOST = T.let('https://index.docker.io'.freeze, String)
12
- DEFAULT_REGISTRY_SCHEME = T.let('https', String)
13
11
  LATEST_TAG = T.let('latest'.freeze, String)
14
12
 
15
13
  sig { params(image_url: String).void }
@@ -28,7 +26,7 @@ module Kuby
28
26
  @image_hostname = T.let(@image_hostname, T.nilable(String))
29
27
  @image_repo = T.let(@image_repo, T.nilable(String))
30
28
  @distro = T.let(@distro, T.nilable(Symbol))
31
- @full_image_uri = T.let(@full_image_uri, T.nilable(URI::Generic))
29
+ @full_image_uri = T.let(@full_image_uri, T.nilable(DockerURI))
32
30
  @default_image_url = T.let(@default_image_url, T.nilable(String))
33
31
  @default_tags = T.let(@default_tags, T.nilable(T::Array[String]))
34
32
  end
@@ -40,18 +38,17 @@ module Kuby
40
38
 
41
39
  sig { returns(String) }
42
40
  def image_host
43
- uri = full_image_uri
44
- @image_host ||= "#{uri.scheme}://#{uri.host}:#{uri.port}"
41
+ @image_host ||= "#{full_image_uri.host}:#{full_image_uri.port}"
45
42
  end
46
43
 
47
44
  sig { returns(String) }
48
45
  def image_hostname
49
- @image_hostname ||= T.must(URI(image_host).host)
46
+ @image_hostname ||= full_image_uri.host
50
47
  end
51
48
 
52
49
  sig { returns(String) }
53
50
  def image_repo
54
- @image_repo ||= T.must(full_image_uri.path).sub(/\A[\/]+/, '')
51
+ @image_repo ||= full_image_uri.path
55
52
  end
56
53
 
57
54
  sig { returns(T::Array[String]) }
@@ -71,15 +68,9 @@ module Kuby
71
68
 
72
69
  private
73
70
 
74
- sig { returns(URI::Generic) }
71
+ sig { returns(DockerURI) }
75
72
  def full_image_uri
76
- @full_image_uri ||= if image_url.include?('://')
77
- URI.parse(image_url)
78
- elsif image_url =~ /\A[^.:]+[\.:][^\/]+\//
79
- URI.parse("#{DEFAULT_REGISTRY_SCHEME}://#{image_url}")
80
- else
81
- URI.parse("#{DEFAULT_REGISTRY_HOST}/#{image_url.sub(/\A[\/]+/, '')}")
82
- end
73
+ @full_image_uri ||= DockerURI.parse(image_url)
83
74
  end
84
75
 
85
76
  sig { returns(String) }
@@ -94,15 +85,6 @@ module Kuby
94
85
  TimestampTag.new(Time.now).to_s, LATEST_TAG
95
86
  ]
96
87
  end
97
-
98
- sig { params(url: String).returns(URI::Generic) }
99
- def parse_url(url)
100
- uri = URI.parse(url)
101
- return uri if uri.scheme
102
-
103
- # force a scheme because URI.parse won't work properly without one
104
- URI.parse("#{DEFAULT_REGISTRY_SCHEME}://#{url}")
105
- end
106
88
  end
107
89
  end
108
90
  end
@@ -7,8 +7,8 @@ module Kuby
7
7
 
8
8
  sig { params(dockerfile: Dockerfile).void }
9
9
  def apply_to(dockerfile)
10
- dockerfile.copy('package.json', '.')
11
- dockerfile.copy('yarn.lock*', '.')
10
+ # use character classes as a hack to only copy the files if they exist
11
+ dockerfile.copy('package.json yarn.loc[k] .npmr[c] .yarnr[c]', './')
12
12
  dockerfile.run('yarn', 'install')
13
13
  end
14
14
  end
@@ -3,6 +3,7 @@ require 'kuby/kubernetes/errors'
3
3
 
4
4
  module Kuby
5
5
  module Kubernetes
6
+ autoload :BareMetalProvider, 'kuby/kubernetes/bare_metal_provider'
6
7
  autoload :Deployer, 'kuby/kubernetes/deployer'
7
8
  autoload :DeployTask, 'kuby/kubernetes/deploy_task'
8
9
  autoload :DockerConfig, 'kuby/kubernetes/docker_config'
@@ -0,0 +1,41 @@
1
+ # typed: false
2
+ require 'kube-dsl'
3
+
4
+ module Kuby
5
+ module Kubernetes
6
+ class BareMetalProvider < Provider
7
+ STORAGE_CLASS_NAME = 'hostpath'.freeze
8
+
9
+ class Config
10
+ extend ::KubeDSL::ValueFields
11
+
12
+ value_fields :kubeconfig
13
+ end
14
+
15
+ attr_reader :config
16
+
17
+ def configure(&block)
18
+ config.instance_eval(&block) if block
19
+ end
20
+
21
+ def kubeconfig_path
22
+ config.kubeconfig
23
+ end
24
+
25
+ def storage_class_name
26
+ STORAGE_CLASS_NAME
27
+ end
28
+
29
+ private
30
+
31
+ def after_initialize
32
+ @config = Config.new
33
+
34
+ configure do
35
+ # default kubeconfig path
36
+ kubeconfig File.join(ENV['HOME'], '.kube', 'config')
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'fileutils'
4
4
  require 'securerandom'
5
+ require 'tmpdir'
5
6
  require 'yaml'
6
7
 
7
8
  module Kuby
@@ -152,7 +152,7 @@ module Kuby
152
152
  end
153
153
 
154
154
  docker_config do
155
- registry_host spec.docker.metadata.image_host
155
+ registry_host spec.docker.metadata.image_hostname
156
156
  username spec.docker.credentials.username
157
157
  password spec.docker.credentials.password
158
158
  email spec.docker.credentials.email
@@ -380,11 +380,35 @@ module Kuby
380
380
  init_container(:create_db) do
381
381
  name "#{kube_spec.selector_app}-create-db"
382
382
  command %w(bundle exec rake kuby:rails_app:db:create_unless_exists)
383
+
384
+ env_from do
385
+ config_map_ref do
386
+ name kube_spec.config_map.metadata.name
387
+ end
388
+ end
389
+
390
+ env_from do
391
+ secret_ref do
392
+ name kube_spec.app_secrets.metadata.name
393
+ end
394
+ end
383
395
  end
384
396
 
385
397
  init_container(:migrate_db) do
386
398
  name "#{kube_spec.selector_app}-migrate-db"
387
399
  command %w(bundle exec rake db:migrate)
400
+
401
+ env_from do
402
+ config_map_ref do
403
+ name kube_spec.config_map.metadata.name
404
+ end
405
+ end
406
+
407
+ env_from do
408
+ secret_ref do
409
+ name kube_spec.app_secrets.metadata.name
410
+ end
411
+ end
388
412
  end
389
413
 
390
414
  image_pull_secret do
data/lib/kuby/tasks.rb CHANGED
@@ -41,10 +41,10 @@ module Kuby
41
41
  fail 'Cannot push Docker images built for the development environment'
42
42
  end
43
43
 
44
- hostname = docker.metadata.image_hostname
44
+ host = docker.metadata.image_host
45
45
 
46
- if docker.credentials.username && !docker.cli.auths.include?(hostname)
47
- Kuby.logger.info("Attempting to log in to registry at #{hostname}")
46
+ if docker.credentials.username && !docker.cli.auths.include?(host)
47
+ Kuby.logger.info("Attempting to log in to registry at #{host}")
48
48
 
49
49
  begin
50
50
  docker.cli.login(
@@ -53,7 +53,7 @@ module Kuby
53
53
  password: docker.credentials.password
54
54
  )
55
55
  rescue Kuby::Docker::LoginError => e
56
- Kuby.logger.fatal("Couldn't log in to the registry at #{hostname}")
56
+ Kuby.logger.fatal("Couldn't log in to the registry at #{host}")
57
57
  Kuby.logger.fatal(e.message)
58
58
  return
59
59
  end
data/lib/kuby/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # typed: true
2
2
 
3
3
  module Kuby
4
- VERSION = '0.11.11'.freeze
4
+ VERSION = '0.11.16'.freeze
5
5
  end
@@ -19,18 +19,18 @@ describe Kuby::Docker::Metadata do
19
19
  describe '#image_host' do
20
20
  subject { metadata.image_host }
21
21
 
22
- it { is_expected.to eq("#{described_class::DEFAULT_REGISTRY_HOST}:443") }
22
+ it { is_expected.to eq("#{Kuby::Docker::DockerURI::DEFAULT_REGISTRY_HOST}:443") }
23
23
 
24
24
  context 'when the image URL contains an explicit host' do
25
25
  let(:docker_image_url) { 'registry.foo.com/foo/testapp' }
26
26
 
27
- it { is_expected.to eq('https://registry.foo.com:443') }
27
+ it { is_expected.to eq('registry.foo.com:443') }
28
28
  end
29
29
 
30
- context 'when the image URL contains an explicit host with scheme' do
30
+ context 'when the image URL contains an explicit host' do
31
31
  let(:docker_image_url) { 'http://registry.foo.com/foo/testapp' }
32
32
 
33
- it { is_expected.to eq('http://registry.foo.com:80') }
33
+ it { is_expected.to eq('registry.foo.com:443') }
34
34
  end
35
35
  end
36
36
 
@@ -46,18 +46,6 @@ describe Kuby::Docker::Metadata do
46
46
  end
47
47
  end
48
48
 
49
- describe '#image_hostname' do
50
- subject { metadata.image_hostname }
51
-
52
- it { is_expected.to eq('index.docker.io') }
53
-
54
- context 'when the image URL contains an explicit host' do
55
- let(:docker_image_url) { 'registry.foo.com/foo/testapp' }
56
-
57
- it { is_expected.to eq('registry.foo.com') }
58
- end
59
- end
60
-
61
49
  describe '#tags' do
62
50
  subject { metadata.tags }
63
51
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kuby-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.11
4
+ version: 0.11.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-02 00:00:00.000000000 Z
11
+ date: 2021-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.1'
33
+ version: '0.5'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.1'
40
+ version: '0.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: gli
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -230,6 +230,7 @@ files:
230
230
  - lib/kuby/docker/debian.rb
231
231
  - lib/kuby/docker/dev_spec.rb
232
232
  - lib/kuby/docker/distro.rb
233
+ - lib/kuby/docker/docker_uri.rb
233
234
  - lib/kuby/docker/dockerfile.rb
234
235
  - lib/kuby/docker/errors.rb
235
236
  - lib/kuby/docker/inline_layer.rb
@@ -254,6 +255,7 @@ files:
254
255
  - lib/kuby/docker/yarn_phase.rb
255
256
  - lib/kuby/environment.rb
256
257
  - lib/kuby/kubernetes.rb
258
+ - lib/kuby/kubernetes/bare_metal_provider.rb
257
259
  - lib/kuby/kubernetes/deploy_task.rb
258
260
  - lib/kuby/kubernetes/deployer.rb
259
261
  - lib/kuby/kubernetes/docker_config.rb