kuby-core 0.17.0 → 0.18.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 +44 -0
- data/Gemfile +6 -2
- data/Rakefile +5 -3
- data/bin/tapioca +29 -0
- data/kuby-core.gemspec +9 -11
- data/lib/kuby/basic_logger.rb +34 -34
- data/lib/kuby/cli_base.rb +43 -43
- data/lib/kuby/commands.rb +94 -11
- data/lib/kuby/definition.rb +12 -12
- data/lib/kuby/dependable.rb +20 -0
- data/lib/kuby/dependency.rb +14 -0
- data/lib/kuby/docker/alpine.rb +10 -10
- data/lib/kuby/docker/app_image.rb +11 -11
- data/lib/kuby/docker/app_phase.rb +36 -0
- data/lib/kuby/docker/assets_phase.rb +2 -2
- data/lib/kuby/docker/bundler_phase.rb +42 -40
- data/lib/kuby/docker/cli.rb +71 -43
- data/lib/kuby/docker/copy_phase.rb +7 -7
- data/lib/kuby/docker/credentials.rb +1 -0
- data/lib/kuby/docker/debian.rb +10 -10
- data/lib/kuby/docker/distro.rb +13 -13
- data/lib/kuby/docker/docker_uri.rb +20 -20
- data/lib/kuby/docker/dockerfile.rb +48 -39
- data/lib/kuby/docker/image.rb +66 -54
- data/lib/kuby/docker/inline_layer.rb +4 -4
- data/lib/kuby/docker/layer.rb +6 -6
- data/lib/kuby/docker/layer_stack.rb +35 -35
- data/lib/kuby/docker/local_tags.rb +16 -16
- data/lib/kuby/docker/package_list.rb +16 -16
- data/lib/kuby/docker/package_phase.rb +16 -16
- data/lib/kuby/docker/packages/managed_package.rb +13 -13
- data/lib/kuby/docker/packages/nodejs.rb +5 -5
- data/lib/kuby/docker/packages/package.rb +8 -8
- data/lib/kuby/docker/packages/simple_managed_package.rb +7 -7
- data/lib/kuby/docker/packages/yarn.rb +6 -6
- data/lib/kuby/docker/remote_tags.rb +16 -16
- data/lib/kuby/docker/setup_phase.rb +18 -20
- data/lib/kuby/docker/spec.rb +93 -72
- data/lib/kuby/docker/timestamp_tag.rb +16 -11
- data/lib/kuby/docker/timestamped_image.rb +59 -40
- data/lib/kuby/docker/webserver_phase.rb +20 -20
- data/lib/kuby/docker/yarn_phase.rb +29 -5
- data/lib/kuby/docker.rb +2 -1
- data/lib/kuby/kubernetes/bare_metal_provider.rb +9 -9
- data/lib/kuby/kubernetes/deployer.rb +22 -10
- data/lib/kuby/kubernetes/docker_config.rb +1 -0
- data/lib/kuby/kubernetes/provider.rb +1 -0
- data/lib/kuby/kubernetes/spec.rb +47 -7
- data/lib/kuby/plugin.rb +22 -1
- data/lib/kuby/plugins/nginx_ingress.rb +8 -6
- data/lib/kuby/plugins/rails_app/assets.rb +16 -4
- data/lib/kuby/plugins/rails_app/assets_image.rb +17 -8
- data/lib/kuby/plugins/rails_app/crdb/plugin.rb +473 -0
- data/lib/kuby/plugins/rails_app/crdb.rb +9 -0
- data/lib/kuby/plugins/rails_app/database.rb +12 -8
- data/lib/kuby/plugins/rails_app/generators/kuby.rb +17 -16
- data/lib/kuby/plugins/rails_app/plugin.rb +29 -18
- data/lib/kuby/plugins/rails_app/sqlite.rb +7 -3
- data/lib/kuby/plugins/rails_app/tasks.rake +25 -12
- data/lib/kuby/plugins/rails_app.rb +1 -0
- data/lib/kuby/plugins/system.rb +16 -0
- data/lib/kuby/plugins.rb +1 -0
- data/lib/kuby/railtie.rb +31 -1
- data/lib/kuby/tasks.rb +72 -5
- data/lib/kuby/trailing_hash.rb +2 -2
- data/lib/kuby/utils/sem_ver/constraint.rb +68 -0
- data/lib/kuby/utils/sem_ver/constraint_set.rb +25 -0
- data/lib/kuby/utils/sem_ver/version.rb +49 -0
- data/lib/kuby/utils/sem_ver.rb +17 -0
- data/lib/kuby/utils/which.rb +65 -0
- data/lib/kuby/utils.rb +7 -1
- data/lib/kuby/version.rb +1 -1
- data/lib/kuby.rb +37 -2
- data/rbi/kuby-core.rbi +2128 -0
- data/spec/docker/spec_spec.rb +50 -26
- data/spec/dummy/app/channels/application_cable/channel.rb +2 -1
- data/spec/dummy/app/channels/application_cable/connection.rb +2 -1
- data/spec/dummy/app/controllers/application_controller.rb +2 -1
- data/spec/dummy/app/jobs/application_job.rb +2 -1
- data/spec/dummy/app/mailers/application_mailer.rb +2 -1
- data/spec/dummy/app/models/application_record.rb +2 -1
- data/spec/dummy/config/application.rb +2 -1
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -1
- data/spec/dummy/config/routes.rb +2 -1
- data/spec/dummy/test/application_system_test_case.rb +2 -1
- data/spec/dummy/test/channels/application_cable/connection_test.rb +2 -1
- data/spec/spec_helper.rb +13 -1
- metadata +44 -39
- data/lib/kuby/plugins/rails_app/mysql.rb +0 -158
- data/lib/kuby/plugins/rails_app/postgres.rb +0 -163
data/lib/kuby/docker/debian.rb
CHANGED
@@ -3,39 +3,39 @@
|
|
3
3
|
module Kuby
|
4
4
|
module Docker
|
5
5
|
class Debian < Distro
|
6
|
-
SHELL_EXE =
|
6
|
+
SHELL_EXE = '/bin/bash'.freeze
|
7
7
|
|
8
|
-
DEFAULT_PACKAGES =
|
8
|
+
DEFAULT_PACKAGES = [
|
9
9
|
[:ca_certificates, nil],
|
10
10
|
[:nodejs, '12.14.1'],
|
11
11
|
[:yarn, '1.21.1']
|
12
|
-
].freeze
|
12
|
+
].freeze
|
13
13
|
|
14
|
-
sig { returns(Layer) }
|
14
|
+
# T::Sig::WithoutRuntime.sig { returns(Layer) }
|
15
15
|
attr_reader :phase
|
16
16
|
|
17
|
-
sig { override.params(packages: T::Array[Distro::PackageImpl], into: Dockerfile).void }
|
17
|
+
# T::Sig::WithoutRuntime.sig { override.params(packages: T::Array[Distro::PackageImpl], into: Dockerfile).void }
|
18
18
|
def install(packages, into:)
|
19
19
|
dockerfile = into
|
20
20
|
install_managed(packages, dockerfile)
|
21
21
|
install_unmanaged(packages, dockerfile)
|
22
22
|
end
|
23
23
|
|
24
|
-
sig { override.returns(T::Array[[Symbol, T.nilable(String)]]) }
|
24
|
+
# T::Sig::WithoutRuntime.sig { override.returns(T::Array[[Symbol, T.nilable(String)]]) }
|
25
25
|
def default_packages
|
26
26
|
DEFAULT_PACKAGES
|
27
27
|
end
|
28
28
|
|
29
|
-
sig { override.returns(String) }
|
29
|
+
# T::Sig::WithoutRuntime.sig { override.returns(String) }
|
30
30
|
def shell_exe
|
31
31
|
SHELL_EXE
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
35
35
|
|
36
|
-
sig { params(packages: T::Array[Distro::PackageImpl], dockerfile: Dockerfile).void }
|
36
|
+
# T::Sig::WithoutRuntime.sig { params(packages: T::Array[Distro::PackageImpl], dockerfile: Dockerfile).void }
|
37
37
|
def install_managed(packages, dockerfile)
|
38
|
-
pkgs =
|
38
|
+
pkgs = packages.select(&:managed?)
|
39
39
|
|
40
40
|
pkg_cmd = <<~CMD.strip
|
41
41
|
apt-get update -qq && \\
|
@@ -52,7 +52,7 @@ module Kuby
|
|
52
52
|
dockerfile.run(pkg_cmd)
|
53
53
|
end
|
54
54
|
|
55
|
-
sig { params(packages: T::Array[Distro::PackageImpl], dockerfile: Dockerfile).void }
|
55
|
+
# T::Sig::WithoutRuntime.sig { params(packages: T::Array[Distro::PackageImpl], dockerfile: Dockerfile).void }
|
56
56
|
def install_unmanaged(packages, dockerfile)
|
57
57
|
packages
|
58
58
|
.reject(&:managed?)
|
data/lib/kuby/docker/distro.rb
CHANGED
@@ -3,37 +3,37 @@
|
|
3
3
|
module Kuby
|
4
4
|
module Docker
|
5
5
|
class Distro
|
6
|
-
extend T::Sig
|
7
|
-
extend T::Helpers
|
6
|
+
# extend T::Sig
|
7
|
+
# extend T::Helpers
|
8
8
|
|
9
|
-
abstract!
|
9
|
+
# abstract!
|
10
10
|
|
11
|
-
PackageImpl = T.type_alias {
|
12
|
-
|
13
|
-
}
|
11
|
+
# PackageImpl = T.type_alias {
|
12
|
+
# T.any(Packages::Package, Packages::ManagedPackage, Packages::SimpleManagedPackage)
|
13
|
+
# }
|
14
14
|
|
15
|
-
ManagedPackageImpl = T.type_alias {
|
16
|
-
|
17
|
-
}
|
15
|
+
# ManagedPackageImpl = T.type_alias {
|
16
|
+
# T.any(Packages::ManagedPackage, Packages::SimpleManagedPackage)
|
17
|
+
# }
|
18
18
|
|
19
|
-
sig { params(phase: Layer).void }
|
19
|
+
# T::Sig::WithoutRuntime.sig { params(phase: Layer).void }
|
20
20
|
def initialize(phase)
|
21
21
|
@phase = phase
|
22
22
|
end
|
23
23
|
|
24
|
-
sig { params(packages: T::Array[PackageImpl], into: Dockerfile).void }
|
24
|
+
# T::Sig::WithoutRuntime.sig { params(packages: T::Array[PackageImpl], into: Dockerfile).void }
|
25
25
|
def install(packages, into:)
|
26
26
|
raise NotImplementedError,
|
27
27
|
"#{__method__} must be defined in derived classes"
|
28
28
|
end
|
29
29
|
|
30
|
-
sig { returns(T::Array[[Symbol, T.nilable(String)]]) }
|
30
|
+
# T::Sig::WithoutRuntime.sig { returns(T::Array[[Symbol, T.nilable(String)]]) }
|
31
31
|
def default_packages
|
32
32
|
raise NotImplementedError,
|
33
33
|
"#{__method__} must be defined in derived classes"
|
34
34
|
end
|
35
35
|
|
36
|
-
sig { returns(String) }
|
36
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
37
37
|
def shell_exe
|
38
38
|
raise NotImplementedError,
|
39
39
|
"#{__method__} must be defined in derived classes"
|
@@ -3,13 +3,13 @@
|
|
3
3
|
module Kuby
|
4
4
|
module Docker
|
5
5
|
class DockerURI
|
6
|
-
extend T::Sig
|
6
|
+
# extend T::Sig
|
7
7
|
|
8
|
-
DEFAULT_REGISTRY_HOST =
|
9
|
-
DEFAULT_REGISTRY_INDEX_HOST =
|
10
|
-
DEFAULT_PORT =
|
8
|
+
DEFAULT_REGISTRY_HOST = 'docker.io'.freeze
|
9
|
+
DEFAULT_REGISTRY_INDEX_HOST = 'index.docker.io'.freeze
|
10
|
+
DEFAULT_PORT = 443
|
11
11
|
|
12
|
-
sig { params(url: String).returns(DockerURI) }
|
12
|
+
# T::Sig::WithoutRuntime.sig { params(url: String).returns(DockerURI) }
|
13
13
|
def self.parse_uri(url)
|
14
14
|
parse(
|
15
15
|
url,
|
@@ -18,7 +18,7 @@ module Kuby
|
|
18
18
|
)
|
19
19
|
end
|
20
20
|
|
21
|
-
sig { params(url: String).returns(DockerURI) }
|
21
|
+
# T::Sig::WithoutRuntime.sig { params(url: String).returns(DockerURI) }
|
22
22
|
def self.parse_index_uri(url)
|
23
23
|
parse(
|
24
24
|
url,
|
@@ -27,13 +27,13 @@ module Kuby
|
|
27
27
|
)
|
28
28
|
end
|
29
29
|
|
30
|
-
sig {
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
}
|
30
|
+
# T::Sig::WithoutRuntime.sig {
|
31
|
+
# params(
|
32
|
+
# url: String,
|
33
|
+
# default_host: T.nilable(String),
|
34
|
+
# default_port: T.nilable(Integer)
|
35
|
+
# ).returns(DockerURI)
|
36
|
+
# }
|
37
37
|
def self.parse(url, default_host:, default_port:)
|
38
38
|
if idx = url.index('://')
|
39
39
|
url = url[(idx + 3)..-1] || ''
|
@@ -41,8 +41,8 @@ module Kuby
|
|
41
41
|
|
42
42
|
host_port, *path = url.split('/')
|
43
43
|
host, port, *path = if host_port =~ /[.:]/
|
44
|
-
hst, prt =
|
45
|
-
[
|
44
|
+
hst, prt = host_port.split(':')
|
45
|
+
[hst, prt || default_port, *path]
|
46
46
|
else
|
47
47
|
[default_host, default_port, host_port, *path]
|
48
48
|
end
|
@@ -50,23 +50,23 @@ module Kuby
|
|
50
50
|
new(host.to_s, port.to_i, (path || []).join('/'))
|
51
51
|
end
|
52
52
|
|
53
|
-
sig { returns(String) }
|
53
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
54
54
|
attr_reader :host
|
55
55
|
|
56
|
-
sig { returns(Integer) }
|
56
|
+
# T::Sig::WithoutRuntime.sig { returns(Integer) }
|
57
57
|
attr_reader :port
|
58
58
|
|
59
|
-
sig { returns(String) }
|
59
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
60
60
|
attr_reader :path
|
61
61
|
|
62
|
-
sig { params(host: String, port: Integer, path: String).void }
|
62
|
+
# T::Sig::WithoutRuntime.sig { params(host: String, port: Integer, path: String).void }
|
63
63
|
def initialize(host, port, path)
|
64
64
|
@host = host
|
65
65
|
@port = port
|
66
66
|
@path = path
|
67
67
|
end
|
68
68
|
|
69
|
-
sig { returns(T::Boolean) }
|
69
|
+
# T::Sig::WithoutRuntime.sig { returns(T::Boolean) }
|
70
70
|
def has_default_port?
|
71
71
|
port == DEFAULT_PORT
|
72
72
|
end
|
@@ -5,39 +5,39 @@ require 'digest'
|
|
5
5
|
module Kuby
|
6
6
|
module Docker
|
7
7
|
class Dockerfile
|
8
|
-
extend T::Sig
|
8
|
+
# extend T::Sig
|
9
9
|
|
10
10
|
class Command
|
11
|
-
extend T::Sig
|
11
|
+
# extend T::Sig
|
12
12
|
|
13
|
-
sig { returns(T::Array[T.any(String, Integer)]) }
|
13
|
+
# T::Sig::WithoutRuntime.sig { returns(T::Array[T.any(String, Integer)]) }
|
14
14
|
attr_reader :args
|
15
15
|
|
16
|
-
sig { params(args: T::Array[T.any(String, Integer)]).void }
|
16
|
+
# T::Sig::WithoutRuntime.sig { params(args: T::Array[T.any(String, Integer)]).void }
|
17
17
|
def initialize(args)
|
18
18
|
@args = args
|
19
19
|
end
|
20
20
|
|
21
|
-
sig { returns(String) }
|
21
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
22
22
|
def to_s
|
23
23
|
args.join(' ')
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
class From < Command
|
28
|
-
sig { returns(String) }
|
28
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
29
29
|
attr_reader :image_url
|
30
30
|
|
31
|
-
sig { returns(T.nilable(String)) }
|
31
|
+
# T::Sig::WithoutRuntime.sig { returns(T.nilable(String)) }
|
32
32
|
attr_reader :as
|
33
33
|
|
34
|
-
sig { params(image_url: String, as: T.nilable(String)).void }
|
34
|
+
# T::Sig::WithoutRuntime.sig { params(image_url: String, as: T.nilable(String)).void }
|
35
35
|
def initialize(image_url, as: nil)
|
36
36
|
@image_url = image_url
|
37
37
|
@as = as
|
38
38
|
end
|
39
39
|
|
40
|
-
sig { returns(String) }
|
40
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
41
41
|
def to_s
|
42
42
|
str = "FROM #{image_url}"
|
43
43
|
str << " AS #{as}" if as
|
@@ -46,38 +46,38 @@ module Kuby
|
|
46
46
|
end
|
47
47
|
|
48
48
|
class Workdir < Command
|
49
|
-
sig { returns(String) }
|
49
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
50
50
|
def to_s; "WORKDIR #{super}"; end
|
51
51
|
end
|
52
52
|
|
53
53
|
class Env < Command
|
54
|
-
sig { returns(String) }
|
54
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
55
55
|
def to_s; "ENV #{super}"; end
|
56
56
|
end
|
57
57
|
|
58
58
|
class Run < Command
|
59
|
-
sig { returns(String) }
|
59
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
60
60
|
def to_s; "RUN #{super}"; end
|
61
61
|
end
|
62
62
|
|
63
63
|
class Copy < Command
|
64
|
-
sig { returns(String) }
|
64
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
65
65
|
attr_reader :source
|
66
66
|
|
67
|
-
sig { returns(String) }
|
67
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
68
68
|
attr_reader :dest
|
69
69
|
|
70
|
-
sig { returns(T.nilable(String)) }
|
70
|
+
# T::Sig::WithoutRuntime.sig { returns(T.nilable(String)) }
|
71
71
|
attr_reader :from
|
72
72
|
|
73
|
-
sig { params(source: String, dest: String, from: T.nilable(String)).void }
|
73
|
+
# T::Sig::WithoutRuntime.sig { params(source: String, dest: String, from: T.nilable(String)).void }
|
74
74
|
def initialize(source, dest, from: nil)
|
75
75
|
@source = source
|
76
76
|
@dest = dest
|
77
77
|
@from = from
|
78
78
|
end
|
79
79
|
|
80
|
-
sig { returns(String) }
|
80
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
81
81
|
def to_s
|
82
82
|
cmd = ['COPY']
|
83
83
|
cmd << "--from=#{from}" if from
|
@@ -87,91 +87,100 @@ module Kuby
|
|
87
87
|
end
|
88
88
|
|
89
89
|
class Expose < Command
|
90
|
-
sig { returns(String) }
|
90
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
91
91
|
def to_s; "EXPOSE #{super}"; end
|
92
92
|
end
|
93
93
|
|
94
94
|
class Cmd < Command
|
95
|
-
sig { returns(String) }
|
95
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
96
96
|
def to_s; "CMD #{super}"; end
|
97
97
|
end
|
98
98
|
|
99
99
|
class Arg < Command
|
100
|
-
sig { returns(String) }
|
100
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
101
101
|
def to_s; "ARG #{super}"; end
|
102
102
|
end
|
103
103
|
|
104
|
-
sig { returns(T::Array[Command]) }
|
104
|
+
# T::Sig::WithoutRuntime.sig { returns(T::Array[Command]) }
|
105
105
|
attr_reader :commands
|
106
106
|
|
107
|
-
sig { returns(Integer) }
|
107
|
+
# T::Sig::WithoutRuntime.sig { returns(Integer) }
|
108
108
|
attr_reader :cursor
|
109
109
|
|
110
|
-
sig { void }
|
110
|
+
# T::Sig::WithoutRuntime.sig { void }
|
111
111
|
def initialize
|
112
|
-
@commands =
|
113
|
-
@cursor =
|
112
|
+
@commands = []
|
113
|
+
@cursor = 0
|
114
114
|
end
|
115
115
|
|
116
|
-
sig { params(image_url: String, as: T.nilable(String)).void }
|
116
|
+
# T::Sig::WithoutRuntime.sig { params(image_url: String, as: T.nilable(String)).void }
|
117
117
|
def from(image_url, as: nil)
|
118
118
|
add From.new(image_url, as: as)
|
119
119
|
end
|
120
120
|
|
121
|
-
sig { params(args: String).void }
|
121
|
+
# T::Sig::WithoutRuntime.sig { params(args: String).void }
|
122
122
|
def workdir(*args)
|
123
123
|
add Workdir.new(args)
|
124
124
|
end
|
125
125
|
|
126
|
-
sig { params(args: String).void }
|
126
|
+
# T::Sig::WithoutRuntime.sig { params(args: String).void }
|
127
127
|
def env(*args)
|
128
128
|
add Env.new(args)
|
129
129
|
end
|
130
130
|
|
131
|
-
sig { params(args: String).void }
|
131
|
+
# T::Sig::WithoutRuntime.sig { params(args: String).void }
|
132
132
|
def arg(*args)
|
133
133
|
add Arg.new(args)
|
134
134
|
end
|
135
135
|
|
136
|
-
sig { params(args: String).void }
|
136
|
+
# T::Sig::WithoutRuntime.sig { params(args: String).void }
|
137
137
|
def run(*args)
|
138
138
|
add Run.new(args)
|
139
139
|
end
|
140
140
|
|
141
|
-
sig { params(source: String, dest: String, from: T.nilable(String)).void }
|
141
|
+
# T::Sig::WithoutRuntime.sig { params(source: String, dest: String, from: T.nilable(String)).void }
|
142
142
|
def copy(source, dest, from: nil)
|
143
143
|
add Copy.new(source, dest, from: from)
|
144
144
|
end
|
145
145
|
|
146
|
-
sig { params(port: Integer).void }
|
146
|
+
# T::Sig::WithoutRuntime.sig { params(port: Integer).void }
|
147
147
|
def expose(port)
|
148
148
|
add Expose.new([port])
|
149
149
|
end
|
150
150
|
|
151
|
-
sig { params(args: String).void }
|
151
|
+
# T::Sig::WithoutRuntime.sig { params(args: String).void }
|
152
152
|
def cmd(*args)
|
153
153
|
add Cmd.new(args)
|
154
154
|
end
|
155
155
|
|
156
|
-
sig { returns(String) }
|
156
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
157
157
|
def to_s
|
158
158
|
# ensure trailing newline
|
159
159
|
"#{commands.map(&:to_s).join("\n")}\n"
|
160
160
|
end
|
161
161
|
|
162
|
-
sig { returns(String) }
|
162
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
163
163
|
def checksum
|
164
164
|
Digest::SHA256.hexdigest(to_s)
|
165
165
|
end
|
166
166
|
|
167
|
-
sig { returns(T::Array[Integer]) }
|
167
|
+
# T::Sig::WithoutRuntime.sig { returns(T::Array[Integer]) }
|
168
168
|
def exposed_ports
|
169
169
|
commands
|
170
170
|
.select { |c| c.is_a?(Expose) }
|
171
|
-
.map { |c|
|
171
|
+
.map { |c| c.args.first }
|
172
172
|
end
|
173
173
|
|
174
|
-
sig {
|
174
|
+
# T::Sig::WithoutRuntime.sig { returns(T.nilable(String)) }
|
175
|
+
def current_workdir
|
176
|
+
found = commands.reverse_each.find do |command|
|
177
|
+
command.is_a?(Kuby::Docker::Dockerfile::Workdir)
|
178
|
+
end
|
179
|
+
|
180
|
+
found.args.first if found
|
181
|
+
end
|
182
|
+
|
183
|
+
# T::Sig::WithoutRuntime.sig { params(pos: Integer, block: T.proc.void).void }
|
175
184
|
def insert_at(pos, &block)
|
176
185
|
@cursor = pos
|
177
186
|
yield
|
@@ -181,7 +190,7 @@ module Kuby
|
|
181
190
|
|
182
191
|
private
|
183
192
|
|
184
|
-
sig { params(cmd: Command).void }
|
193
|
+
# T::Sig::WithoutRuntime.sig { params(cmd: Command).void }
|
185
194
|
def add(cmd)
|
186
195
|
commands.insert(cursor, cmd)
|
187
196
|
@cursor += 1
|
data/lib/kuby/docker/image.rb
CHANGED
@@ -3,137 +3,149 @@
|
|
3
3
|
module Kuby
|
4
4
|
module Docker
|
5
5
|
class Image
|
6
|
-
extend T::Sig
|
6
|
+
# extend T::Sig
|
7
7
|
|
8
|
-
sig { returns(T.nilable(String)) }
|
8
|
+
# T::Sig::WithoutRuntime.sig { returns(T.nilable(String)) }
|
9
9
|
attr_reader :identifier
|
10
10
|
|
11
|
-
sig { returns(String) }
|
11
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
12
12
|
attr_reader :image_url
|
13
13
|
|
14
|
-
sig { returns(T.nilable(String)) }
|
14
|
+
# T::Sig::WithoutRuntime.sig { returns(T.nilable(String)) }
|
15
15
|
attr_reader :registry_index_url
|
16
16
|
|
17
|
-
sig { returns(Credentials) }
|
17
|
+
# T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::Credentials) }
|
18
18
|
attr_reader :credentials
|
19
19
|
|
20
|
-
sig { returns(T.nilable(String)) }
|
20
|
+
# T::Sig::WithoutRuntime.sig { returns(T.nilable(String)) }
|
21
21
|
attr_reader :main_tag
|
22
22
|
|
23
|
-
sig { returns T::Array[String] }
|
23
|
+
# T::Sig::WithoutRuntime.sig { returns T::Array[String] }
|
24
24
|
attr_reader :alias_tags
|
25
25
|
|
26
|
-
sig {
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
}
|
26
|
+
# T::Sig::WithoutRuntime.sig {
|
27
|
+
# params(
|
28
|
+
# dockerfile: T.any(Dockerfile, T.proc.returns(Kuby::Docker::Dockerfile)),
|
29
|
+
# image_url: String,
|
30
|
+
# credentials: Kuby::Docker::Credentials,
|
31
|
+
# registry_index_url: T.nilable(String),
|
32
|
+
# main_tag: T.nilable(String),
|
33
|
+
# alias_tags: T::Array[String]
|
34
|
+
# ).void
|
35
|
+
# }
|
36
36
|
def initialize(dockerfile, image_url, credentials, registry_index_url = nil, main_tag = nil, alias_tags = [])
|
37
|
-
@dockerfile =
|
38
|
-
@image_url =
|
39
|
-
@registry_index_url =
|
40
|
-
@credentials =
|
41
|
-
@main_tag =
|
42
|
-
@alias_tags =
|
43
|
-
@identifier = T.let(@identifier, T.nilable(String))
|
44
|
-
|
45
|
-
@image_host = T.let(@image_host, T.nilable(String))
|
46
|
-
@image_hostname = T.let(@image_hostname, T.nilable(String))
|
47
|
-
@registry_index_host = T.let(@registry_index_host, T.nilable(String))
|
48
|
-
@registry_index_hostname = T.let(@registry_index_hostname, T.nilable(String))
|
49
|
-
@registry_index_uri = T.let(@registry_index_uri, T.nilable(DockerURI))
|
50
|
-
@image_repo = T.let(@image_repo, T.nilable(String))
|
51
|
-
@full_image_uri = T.let(@full_image_uri, T.nilable(DockerURI))
|
52
|
-
@docker_cli = T.let(@docker_cli, T.nilable(Docker::CLI))
|
53
|
-
end
|
54
|
-
|
55
|
-
sig { returns(Image) }
|
37
|
+
@dockerfile = dockerfile
|
38
|
+
@image_url = image_url
|
39
|
+
@registry_index_url = registry_index_url
|
40
|
+
@credentials = credentials
|
41
|
+
@main_tag = main_tag
|
42
|
+
@alias_tags = alias_tags
|
43
|
+
# @identifier = T.let(@identifier, T.nilable(String))
|
44
|
+
|
45
|
+
# @image_host = T.let(@image_host, T.nilable(String))
|
46
|
+
# @image_hostname = T.let(@image_hostname, T.nilable(String))
|
47
|
+
# @registry_index_host = T.let(@registry_index_host, T.nilable(String))
|
48
|
+
# @registry_index_hostname = T.let(@registry_index_hostname, T.nilable(String))
|
49
|
+
# @registry_index_uri = T.let(@registry_index_uri, T.nilable(DockerURI))
|
50
|
+
# @image_repo = T.let(@image_repo, T.nilable(String))
|
51
|
+
# @full_image_uri = T.let(@full_image_uri, T.nilable(DockerURI))
|
52
|
+
# @docker_cli = T.let(@docker_cli, T.nilable(Docker::CLI))
|
53
|
+
end
|
54
|
+
|
55
|
+
# T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::Image) }
|
56
56
|
def new_version
|
57
57
|
raise NotImplementedError, 'please use a Docker::Image subclass'
|
58
58
|
end
|
59
59
|
|
60
|
-
sig { returns(Image) }
|
60
|
+
# T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::Image) }
|
61
61
|
def current_version
|
62
62
|
raise NotImplementedError, 'please use a Docker::Image subclass'
|
63
63
|
end
|
64
64
|
|
65
|
-
sig { params(current_tag: T.nilable(String)).returns(Image) }
|
65
|
+
# T::Sig::WithoutRuntime.sig { params(current_tag: T.nilable(String)).returns(Image) }
|
66
66
|
def previous_version(current_tag = nil)
|
67
67
|
raise NotImplementedError, 'please use a Docker::Image subclass'
|
68
68
|
end
|
69
69
|
|
70
|
-
sig { returns(Dockerfile) }
|
70
|
+
# T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::Dockerfile) }
|
71
71
|
def dockerfile
|
72
72
|
if @dockerfile.respond_to?(:call)
|
73
|
-
|
73
|
+
@dockerfile.call
|
74
74
|
else
|
75
|
-
|
75
|
+
@dockerfile
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
sig { returns(String) }
|
79
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
80
80
|
def image_host
|
81
81
|
@image_host ||= "#{image_uri.host}:#{image_uri.port}"
|
82
82
|
end
|
83
83
|
|
84
|
-
sig { returns(String) }
|
84
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
85
85
|
def registry_index_host
|
86
86
|
@registry_index_host ||= "#{registry_index_uri.host}:#{registry_index_uri.port}"
|
87
87
|
end
|
88
88
|
|
89
|
-
sig { returns(String) }
|
89
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
90
90
|
def registry_index_hostname
|
91
91
|
@registry_index_hostname ||= registry_index_uri.host
|
92
92
|
end
|
93
93
|
|
94
|
-
sig { returns(String) }
|
94
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
95
95
|
def image_hostname
|
96
96
|
@image_hostname ||= image_uri.host
|
97
97
|
end
|
98
98
|
|
99
|
-
sig { returns(String) }
|
99
|
+
# T::Sig::WithoutRuntime.sig { returns(String) }
|
100
100
|
def image_repo
|
101
101
|
@image_repo ||= image_uri.path
|
102
102
|
end
|
103
103
|
|
104
|
-
sig { returns(DockerURI) }
|
104
|
+
# T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::DockerURI) }
|
105
105
|
def image_uri
|
106
106
|
@full_image_uri ||= DockerURI.parse_uri(image_url)
|
107
107
|
end
|
108
108
|
|
109
|
-
sig { returns(DockerURI) }
|
109
|
+
# T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::DockerURI) }
|
110
110
|
def registry_index_uri
|
111
111
|
@registry_index_uri ||= DockerURI.parse_index_uri(registry_index_url || image_url)
|
112
112
|
end
|
113
113
|
|
114
|
-
sig { returns(T::Array[String]) }
|
114
|
+
# T::Sig::WithoutRuntime.sig { returns(T::Array[String]) }
|
115
115
|
def tags
|
116
116
|
[main_tag, *alias_tags].compact
|
117
117
|
end
|
118
118
|
|
119
|
-
|
120
|
-
|
119
|
+
# T::Sig::WithoutRuntime.sig {
|
120
|
+
# params(
|
121
|
+
# build_args: T::Hash[String, String],
|
122
|
+
# docker_args: T::Array[String],
|
123
|
+
# context: T.nilable(String),
|
124
|
+
# cache_from: T.nilable(String)
|
125
|
+
# ).void
|
126
|
+
# }
|
127
|
+
def build(build_args = {}, docker_args = [], context: nil, cache_from: nil)
|
121
128
|
raise NotImplementedError, 'please use a Docker::Image subclass'
|
122
129
|
end
|
123
130
|
|
124
|
-
sig { params(tag: String).void }
|
131
|
+
# T::Sig::WithoutRuntime.sig { params(tag: String).void }
|
125
132
|
def push(tag)
|
126
133
|
raise NotImplementedError, 'please use a Docker::Image subclass'
|
127
134
|
end
|
128
135
|
|
129
|
-
sig {
|
136
|
+
# T::Sig::WithoutRuntime.sig { params(tag: String).void }
|
137
|
+
def pull(tag)
|
138
|
+
raise NotImplementedError, 'please use a Docker::Image subclass'
|
139
|
+
end
|
140
|
+
|
141
|
+
# T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::CLI) }
|
130
142
|
def docker_cli
|
131
143
|
@docker_cli ||= Docker::CLI.new
|
132
144
|
end
|
133
145
|
|
134
146
|
private
|
135
147
|
|
136
|
-
sig { params(main_tag: String, alias_tags: T::Array[String]).returns(Image) }
|
148
|
+
# T::Sig::WithoutRuntime.sig { params(main_tag: String, alias_tags: T::Array[String]).returns(Image) }
|
137
149
|
def duplicate_with_tags(main_tag, alias_tags)
|
138
150
|
self.class.new(dockerfile, image_url, credentials, registry_index_url, main_tag, alias_tags)
|
139
151
|
end
|
@@ -3,17 +3,17 @@
|
|
3
3
|
module Kuby
|
4
4
|
module Docker
|
5
5
|
class InlineLayer < Layer
|
6
|
-
extend T::Sig
|
6
|
+
# extend T::Sig
|
7
7
|
|
8
|
-
sig { returns(T.proc.params(df: Dockerfile).void) }
|
8
|
+
# T::Sig::WithoutRuntime.sig { returns(T.proc.params(df: Dockerfile).void) }
|
9
9
|
attr_reader :block
|
10
10
|
|
11
|
-
sig { params(block: T.proc.params(df: Dockerfile).void).void }
|
11
|
+
# T::Sig::WithoutRuntime.sig { params(block: T.proc.params(df: Dockerfile).void).void }
|
12
12
|
def initialize(block)
|
13
13
|
@block = block
|
14
14
|
end
|
15
15
|
|
16
|
-
sig { override.params(dockerfile: Dockerfile).void }
|
16
|
+
# T::Sig::WithoutRuntime.sig { override.params(dockerfile: Dockerfile).void }
|
17
17
|
def apply_to(dockerfile)
|
18
18
|
block.call(dockerfile)
|
19
19
|
end
|
data/lib/kuby/docker/layer.rb
CHANGED
@@ -3,20 +3,20 @@
|
|
3
3
|
module Kuby
|
4
4
|
module Docker
|
5
5
|
class Layer
|
6
|
-
extend T::Sig
|
7
|
-
extend T::Helpers
|
6
|
+
# extend T::Sig
|
7
|
+
# extend T::Helpers
|
8
8
|
|
9
|
-
abstract!
|
9
|
+
# abstract!
|
10
10
|
|
11
|
-
sig { returns(Environment) }
|
11
|
+
# T::Sig::WithoutRuntime.sig { returns(Environment) }
|
12
12
|
attr_reader :environment
|
13
13
|
|
14
|
-
sig { params(environment: Environment).void }
|
14
|
+
# T::Sig::WithoutRuntime.sig { params(environment: Environment).void }
|
15
15
|
def initialize(environment)
|
16
16
|
@environment = environment
|
17
17
|
end
|
18
18
|
|
19
|
-
sig { params(dockerfile: Dockerfile).void }
|
19
|
+
# T::Sig::WithoutRuntime.sig { params(dockerfile: Dockerfile).void }
|
20
20
|
def apply_to(dockerfile)
|
21
21
|
raise NotImplementedError,
|
22
22
|
"#{__method__} must be defined in derived classes"
|