kuby-core 0.6.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/kuby-core.gemspec +7 -3
- data/lib/kuby.rb +9 -7
- data/lib/kuby/definition.rb +0 -8
- data/lib/kuby/docker/cli.rb +32 -0
- data/lib/kuby/docker/errors.rb +1 -0
- data/lib/kuby/docker/layer.rb +4 -4
- data/lib/kuby/docker/metadata.rb +11 -7
- data/lib/kuby/docker/package_phase.rb +2 -2
- data/lib/kuby/docker/spec.rb +11 -11
- data/lib/kuby/docker/timestamp_tag.rb +6 -3
- data/lib/kuby/environment.rb +6 -2
- data/lib/kuby/kubernetes.rb +0 -2
- data/lib/kuby/kubernetes/deploy_task.rb +0 -1
- data/lib/kuby/kubernetes/deployer.rb +7 -7
- data/lib/kuby/kubernetes/minikube_provider.rb +4 -0
- data/lib/kuby/kubernetes/provider.rb +5 -5
- data/lib/kuby/kubernetes/spec.rb +8 -8
- data/lib/kuby/plugin.rb +59 -0
- data/lib/kuby/plugins.rb +6 -0
- data/lib/kuby/plugins/nginx_ingress.rb +71 -0
- data/lib/kuby/plugins/rails_app.rb +18 -0
- data/lib/kuby/plugins/rails_app/asset_copy_task.rb +117 -0
- data/lib/kuby/plugins/rails_app/assets.rb +347 -0
- data/lib/kuby/plugins/rails_app/database.rb +75 -0
- data/lib/kuby/{kubernetes/plugins → plugins}/rails_app/generators/kuby.rb +0 -0
- data/lib/kuby/plugins/rails_app/mysql.rb +155 -0
- data/lib/kuby/plugins/rails_app/plugin.rb +398 -0
- data/lib/kuby/plugins/rails_app/postgres.rb +143 -0
- data/lib/kuby/plugins/rails_app/rewrite_db_config.rb +11 -0
- data/lib/kuby/plugins/rails_app/sqlite.rb +32 -0
- data/lib/kuby/{kubernetes/plugins → plugins}/rails_app/tasks.rake +10 -2
- data/lib/kuby/tasks.rb +28 -9
- data/lib/kuby/tasks/kuby.rake +1 -1
- data/lib/kuby/version.rb +1 -1
- data/spec/docker/timestamp_tag_spec.rb +11 -0
- data/spec/spec_helper.rb +102 -0
- metadata +50 -27
- data/lib/ext/krane/kubernetes_resource.rb +0 -16
- data/lib/kuby/kubernetes/plugin.rb +0 -55
- data/lib/kuby/kubernetes/plugins.rb +0 -8
- data/lib/kuby/kubernetes/plugins/nginx_ingress.rb +0 -73
- data/lib/kuby/kubernetes/plugins/rails_app.rb +0 -16
- data/lib/kuby/kubernetes/plugins/rails_app/database.rb +0 -79
- data/lib/kuby/kubernetes/plugins/rails_app/mysql.rb +0 -154
- data/lib/kuby/kubernetes/plugins/rails_app/plugin.rb +0 -379
- data/lib/kuby/kubernetes/plugins/rails_app/postgres.rb +0 -142
- data/lib/kuby/kubernetes/plugins/rails_app/rewrite_db_config.rb +0 -13
- data/lib/kuby/kubernetes/plugins/rails_app/sqlite.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac73b245f1fb75244ed166e23a6441cc56dabaec66f532f67517b4dd8d412091
|
4
|
+
data.tar.gz: 6418a3fbca89fdc195e277aeb8309caa2b519e1d3df0fccd53f3ae8b2e9f166f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f7bc8616cfdf23805bf9177198f62888b17372ae67b4fb4a77c4d325adbbcf6d734385edb0614094be95bb443d84b28f6d79fe70a8acaecdfb44b547bcf86b0
|
7
|
+
data.tar.gz: 815fd1ae302c35fdd0fb31f43bb1d607073a9cfb1f24d3c849578b0b8a5271bca5cbe49f2747bdf7bb22d1a4b98d1fa455c3a917e7d27f059f5a4778da215f87
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
## 0.8.0
|
2
|
+
* Upgrade to Krane >= 1.1.4, < 2.0.
|
3
|
+
* Remove Krane monkeypatch in ext/.
|
4
|
+
* Implement a Rails static asset server.
|
5
|
+
* Move plugins from `Kuby::Kubernetes` namespace to `Kuby` namespace.
|
6
|
+
- This is to eventually enable plugins to modify the Dockerfile and introduce additional Dockerfiles (i.e. to enable a development mode, etc).
|
7
|
+
* Pass `Environment` instead of `Definition` instances around.
|
8
|
+
- Providers, plugins, etc all take `Definition` instances. `Definition#kubernetes`, for example, returns the Kubernetes spec for the `Environment` specified by `KUBY_ENV` (or the first env defined if `KUBY_ENV` is not set). This is a problem for Kuby configs that specify multiple environments, and causes plugins to make changes to the default environment instead of the one they've been specifically added to. For example, if the `:production` env is defined first, the `:development` env still gets a cluster issuer from cert-manager even though `enable_tls` is set to `false`.
|
9
|
+
|
10
|
+
## 0.7.2
|
11
|
+
* Fix issue causing `Kuby.environment(...)` to raise an `UndefinedEnvironmentError` for existing environments.
|
12
|
+
|
13
|
+
## 0.7.1
|
14
|
+
* Fix timestamp tag parsing regression caused by adding anchor tags to the regex.
|
15
|
+
- Instead, let's rely on `strptime` and return `nil` if it throws an `ArgumentError`.
|
16
|
+
|
17
|
+
## 0.7.0
|
18
|
+
* Automatically perform `docker login` if not already logged into the Docker registry.
|
19
|
+
* Fix timestamp tag parsing issue causing deploy to fail with no available tags.
|
20
|
+
- Issue turned out to be ignoring the month of October in the validation regex.
|
21
|
+
|
22
|
+
## 0.6.1
|
23
|
+
* Fix issue causing database.yml to not be rewritten to point at correct database host.
|
24
|
+
|
1
25
|
## 0.6.0
|
2
26
|
* Don't load the Rails environment when running Kuby's rake tasks.
|
3
27
|
- Kuby's gems are still part of the bundle, but config has been moved out of the initializer and into kuby.rb in the Rails root directory.
|
data/kuby-core.gemspec
CHANGED
@@ -14,14 +14,18 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.add_dependency 'colorize', '~> 0.8'
|
16
16
|
s.add_dependency 'docker-remote', '~> 0.1'
|
17
|
-
|
18
|
-
|
17
|
+
# See: https://github.com/Shopify/krane/pull/720
|
18
|
+
# See: https://github.com/Shopify/krane/blob/master/CHANGELOG.md#114
|
19
|
+
s.add_dependency 'krane', '>= 1.1.4', '< 2.0'
|
20
|
+
s.add_dependency 'kuby-cert-manager', '>= 0.3'
|
19
21
|
s.add_dependency 'kube-dsl', '~> 0.3'
|
20
|
-
s.add_dependency 'kuby-kube-db', '
|
22
|
+
s.add_dependency 'kuby-kube-db', '>= 0.5'
|
21
23
|
s.add_dependency 'kubernetes-cli', '~> 0.2'
|
22
24
|
s.add_dependency 'railties', '>= 5.1'
|
23
25
|
s.add_dependency 'rouge', '~> 3.0'
|
24
26
|
|
27
|
+
s.add_development_dependency 'rspec'
|
28
|
+
|
25
29
|
s.require_path = 'lib'
|
26
30
|
|
27
31
|
s.files = Dir['{lib,spec}/**/*', 'Gemfile', 'LICENSE', 'CHANGELOG.md', 'README.md', 'Rakefile', 'kuby-core.gemspec']
|
data/lib/kuby.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'kuby/railtie'
|
2
2
|
|
3
3
|
begin
|
4
|
-
require 'kuby/
|
4
|
+
require 'kuby/plugins/rails_app/generators/kuby'
|
5
5
|
rescue NameError
|
6
6
|
end
|
7
7
|
|
@@ -13,6 +13,8 @@ module Kuby
|
|
13
13
|
autoload :Environment, 'kuby/environment'
|
14
14
|
autoload :Kubernetes, 'kuby/kubernetes'
|
15
15
|
autoload :Middleware, 'kuby/middleware'
|
16
|
+
autoload :Plugin, 'kuby/plugin'
|
17
|
+
autoload :Plugins, 'kuby/plugins'
|
16
18
|
autoload :Tasks, 'kuby/tasks'
|
17
19
|
autoload :TrailingHash, 'kuby/trailing_hash'
|
18
20
|
|
@@ -38,10 +40,10 @@ module Kuby
|
|
38
40
|
end
|
39
41
|
|
40
42
|
def environment(name = env)
|
41
|
-
definition.environment(name.to_s)
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
definition.environment(name.to_s) || raise(
|
44
|
+
UndefinedEnvironmentError, "couldn't find a Kuby environment named "\
|
45
|
+
"'#{name}'"
|
46
|
+
)
|
45
47
|
end
|
46
48
|
|
47
49
|
def register_provider(provider_name, provider_klass)
|
@@ -107,8 +109,8 @@ end
|
|
107
109
|
Kuby.register_provider(:minikube, Kuby::Kubernetes::MinikubeProvider)
|
108
110
|
|
109
111
|
# plugins
|
110
|
-
Kuby.register_plugin(:rails_app, Kuby::
|
111
|
-
Kuby.register_plugin(:nginx_ingress, Kuby::
|
112
|
+
Kuby.register_plugin(:rails_app, Kuby::Plugins::RailsApp::Plugin)
|
113
|
+
Kuby.register_plugin(:nginx_ingress, Kuby::Plugins::NginxIngress)
|
112
114
|
|
113
115
|
# distros
|
114
116
|
Kuby.register_distro(:debian, Kuby::Docker::Debian)
|
data/lib/kuby/definition.rb
CHANGED
data/lib/kuby/docker/cli.rb
CHANGED
@@ -10,6 +10,38 @@ module Kuby
|
|
10
10
|
@executable = executable || `which docker`.strip
|
11
11
|
end
|
12
12
|
|
13
|
+
def config_file
|
14
|
+
if File.exist?(default_config_file)
|
15
|
+
default_config_file
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def default_config_file
|
20
|
+
File.join(Dir.home, '.docker', 'config.json')
|
21
|
+
end
|
22
|
+
|
23
|
+
def login(url:, username:, password:)
|
24
|
+
cmd = [
|
25
|
+
executable, 'login', url, '--username', username, '--password-stdin'
|
26
|
+
]
|
27
|
+
|
28
|
+
open3_w({}, cmd) do |stdin, _wait_threads|
|
29
|
+
stdin.puts(password)
|
30
|
+
end
|
31
|
+
|
32
|
+
unless last_status.success?
|
33
|
+
raise LoginError, 'build failed: docker command exited with '\
|
34
|
+
"status code #{last_status.exitstatus}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def auths
|
39
|
+
return [] unless config_file
|
40
|
+
|
41
|
+
config = JSON.parse(File.read(config_file))
|
42
|
+
config.fetch('auths', {}).keys
|
43
|
+
end
|
44
|
+
|
13
45
|
def build(dockerfile:, image_url:, tags:)
|
14
46
|
cmd = [
|
15
47
|
executable, 'build',
|
data/lib/kuby/docker/errors.rb
CHANGED
data/lib/kuby/docker/layer.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Kuby
|
2
2
|
module Docker
|
3
3
|
class Layer
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :environment
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@
|
6
|
+
def initialize(environment)
|
7
|
+
@environment = environment
|
8
8
|
end
|
9
9
|
|
10
10
|
def apply_to(dockerfile)
|
@@ -15,7 +15,7 @@ module Kuby
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def metadata
|
18
|
-
|
18
|
+
environment.docker.metadata
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/kuby/docker/metadata.rb
CHANGED
@@ -4,14 +4,14 @@ module Kuby
|
|
4
4
|
module Docker
|
5
5
|
class Metadata
|
6
6
|
DEFAULT_DISTRO = :debian
|
7
|
-
DEFAULT_REGISTRY_HOST = 'https://docker.
|
7
|
+
DEFAULT_REGISTRY_HOST = 'https://www.docker.com'.freeze
|
8
8
|
LATEST_TAG = 'latest'
|
9
9
|
|
10
10
|
attr_accessor :image_url
|
11
|
-
attr_reader :
|
11
|
+
attr_reader :environment
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
@
|
13
|
+
def initialize(environment)
|
14
|
+
@environment = environment
|
15
15
|
@tags = []
|
16
16
|
end
|
17
17
|
|
@@ -28,6 +28,10 @@ module Kuby
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
def image_hostname
|
32
|
+
@image_hostname ||= URI(image_host).host
|
33
|
+
end
|
34
|
+
|
31
35
|
def image_repo
|
32
36
|
@image_repo ||= if image_url.include?('/')
|
33
37
|
parse_url(image_url).path.sub(/\A\//, '')
|
@@ -42,7 +46,7 @@ module Kuby
|
|
42
46
|
|
43
47
|
def tag
|
44
48
|
t = ENV.fetch('KUBY_DOCKER_TAG') do
|
45
|
-
|
49
|
+
environment.docker.tags.latest_timestamp_tag
|
46
50
|
end
|
47
51
|
|
48
52
|
unless t
|
@@ -53,7 +57,7 @@ module Kuby
|
|
53
57
|
end
|
54
58
|
|
55
59
|
def previous_tag(current_tag)
|
56
|
-
t =
|
60
|
+
t = environment.docker.tags.previous_timestamp_tag(current_tag)
|
57
61
|
|
58
62
|
unless t
|
59
63
|
raise MissingTagError, 'could not find previous timestamped tag'
|
@@ -74,7 +78,7 @@ module Kuby
|
|
74
78
|
|
75
79
|
def default_image_url
|
76
80
|
# assuming dockerhub by not specifying full url
|
77
|
-
@default_image_url ||=
|
81
|
+
@default_image_url ||= environment.app_name.downcase
|
78
82
|
end
|
79
83
|
|
80
84
|
def default_tags
|
@@ -40,7 +40,7 @@ module Kuby
|
|
40
40
|
private
|
41
41
|
|
42
42
|
def distro_spec
|
43
|
-
|
43
|
+
environment.docker.distro_spec
|
44
44
|
end
|
45
45
|
|
46
46
|
def get_package(package_name, version)
|
@@ -52,7 +52,7 @@ module Kuby
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def metadata
|
55
|
-
|
55
|
+
environment.docker.metadata
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
data/lib/kuby/docker/spec.rb
CHANGED
@@ -3,10 +3,10 @@ require 'docker/remote'
|
|
3
3
|
module Kuby
|
4
4
|
module Docker
|
5
5
|
class Spec
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :environment
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@
|
8
|
+
def initialize(environment)
|
9
|
+
@environment = environment
|
10
10
|
end
|
11
11
|
|
12
12
|
def base_image(image_url)
|
@@ -75,35 +75,35 @@ module Kuby
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def setup_phase
|
78
|
-
@setup_phase ||= SetupPhase.new(
|
78
|
+
@setup_phase ||= SetupPhase.new(environment)
|
79
79
|
end
|
80
80
|
|
81
81
|
def package_phase
|
82
|
-
@package_phase ||= PackagePhase.new(
|
82
|
+
@package_phase ||= PackagePhase.new(environment)
|
83
83
|
end
|
84
84
|
|
85
85
|
def bundler_phase
|
86
|
-
@bundler_phase ||= BundlerPhase.new(
|
86
|
+
@bundler_phase ||= BundlerPhase.new(environment)
|
87
87
|
end
|
88
88
|
|
89
89
|
def yarn_phase
|
90
|
-
@yarn_phase ||= YarnPhase.new(
|
90
|
+
@yarn_phase ||= YarnPhase.new(environment)
|
91
91
|
end
|
92
92
|
|
93
93
|
def copy_phase
|
94
|
-
@copy_phase ||= CopyPhase.new(
|
94
|
+
@copy_phase ||= CopyPhase.new(environment)
|
95
95
|
end
|
96
96
|
|
97
97
|
def assets_phase
|
98
|
-
@assets_phase ||= AssetsPhase.new(
|
98
|
+
@assets_phase ||= AssetsPhase.new(environment)
|
99
99
|
end
|
100
100
|
|
101
101
|
def webserver_phase
|
102
|
-
@webserver_phase ||= WebserverPhase.new(
|
102
|
+
@webserver_phase ||= WebserverPhase.new(environment)
|
103
103
|
end
|
104
104
|
|
105
105
|
def metadata
|
106
|
-
@metadata ||= Metadata.new(
|
106
|
+
@metadata ||= Metadata.new(environment)
|
107
107
|
end
|
108
108
|
|
109
109
|
def tags
|
@@ -1,13 +1,16 @@
|
|
1
1
|
module Kuby
|
2
2
|
module Docker
|
3
3
|
class TimestampTag
|
4
|
-
RE = /20[\d]{2}(?:0[1-9]|11|12)(?:0[1-9]|1[1-9]|2[1-9]|3[01])/.freeze
|
5
4
|
FORMAT = '%Y%m%d%H%M%S'.freeze
|
6
5
|
|
7
6
|
def self.try_parse(str)
|
8
|
-
|
9
|
-
|
7
|
+
time = begin
|
8
|
+
Time.strptime(str, FORMAT)
|
9
|
+
rescue ArgumentError
|
10
|
+
return nil
|
10
11
|
end
|
12
|
+
|
13
|
+
new(time)
|
11
14
|
end
|
12
15
|
|
13
16
|
attr_reader :time
|
data/lib/kuby/environment.rb
CHANGED
@@ -8,15 +8,19 @@ module Kuby
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def docker(&block)
|
11
|
-
@docker ||= Docker::Spec.new(
|
11
|
+
@docker ||= Docker::Spec.new(self)
|
12
12
|
@docker.instance_eval(&block) if block
|
13
13
|
@docker
|
14
14
|
end
|
15
15
|
|
16
16
|
def kubernetes(&block)
|
17
|
-
@kubernetes ||= Kubernetes::Spec.new(
|
17
|
+
@kubernetes ||= Kubernetes::Spec.new(self)
|
18
18
|
@kubernetes.instance_eval(&block) if block
|
19
19
|
@kubernetes
|
20
20
|
end
|
21
|
+
|
22
|
+
def app_name
|
23
|
+
definition.app_name
|
24
|
+
end
|
21
25
|
end
|
22
26
|
end
|
data/lib/kuby/kubernetes.rb
CHANGED
@@ -7,8 +7,6 @@ module Kuby
|
|
7
7
|
autoload :DeployTask, 'kuby/kubernetes/deploy_task'
|
8
8
|
autoload :DockerConfig, 'kuby/kubernetes/docker_config'
|
9
9
|
autoload :Manifest, 'kuby/kubernetes/manifest'
|
10
|
-
autoload :Monitors, 'kuby/kubernetes/monitors'
|
11
|
-
autoload :Plugin, 'kuby/kubernetes/plugin'
|
12
10
|
autoload :Plugins, 'kuby/kubernetes/plugins'
|
13
11
|
autoload :Provider, 'kuby/kubernetes/provider'
|
14
12
|
autoload :RegistrySecret, 'kuby/kubernetes/registry_secret'
|
@@ -5,10 +5,10 @@ require 'yaml'
|
|
5
5
|
module Kuby
|
6
6
|
module Kubernetes
|
7
7
|
class Deployer
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :environment
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
@
|
10
|
+
def initialize(environment)
|
11
|
+
@environment = environment
|
12
12
|
end
|
13
13
|
|
14
14
|
def deploy
|
@@ -42,7 +42,7 @@ module Kuby
|
|
42
42
|
|
43
43
|
cli.apply(res)
|
44
44
|
end
|
45
|
-
rescue InvalidResourceError => e
|
45
|
+
rescue KubernetesCLI::InvalidResourceError => e
|
46
46
|
Kuby.logger.fatal(e.message)
|
47
47
|
Kuby.logger.fatal(e.resource.to_resource.to_yaml)
|
48
48
|
end
|
@@ -74,15 +74,15 @@ module Kuby
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def provider
|
77
|
-
|
77
|
+
environment.kubernetes.provider
|
78
78
|
end
|
79
79
|
|
80
80
|
def namespace
|
81
|
-
|
81
|
+
environment.kubernetes.namespace
|
82
82
|
end
|
83
83
|
|
84
84
|
def all_resources
|
85
|
-
|
85
|
+
environment.kubernetes.resources
|
86
86
|
end
|
87
87
|
|
88
88
|
def cli
|
@@ -3,10 +3,10 @@ require 'kubernetes-cli'
|
|
3
3
|
module Kuby
|
4
4
|
module Kubernetes
|
5
5
|
class Provider
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :environment
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@
|
8
|
+
def initialize(environment)
|
9
|
+
@environment = environment
|
10
10
|
after_initialize
|
11
11
|
end
|
12
12
|
|
@@ -66,11 +66,11 @@ module Kuby
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def deployer
|
69
|
-
@deployer ||= Kuby::Kubernetes::Deployer.new(
|
69
|
+
@deployer ||= Kuby::Kubernetes::Deployer.new(environment)
|
70
70
|
end
|
71
71
|
|
72
72
|
def spec
|
73
|
-
|
73
|
+
environment.kubernetes
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|