Class: Kuby::Docker::Spec

Inherits:
Object
  • Object
show all
Defined in:
lib/kuby/docker/spec.rb

Constant Summary collapse

DEFAULT_DISTRO =

extend T::Sig

:debian
DEFAULT_APP_ROOT_PATH =
'.'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment) ⇒ Spec

T::Sig::WithoutRuntime.sig { params(environment: Kuby::Environment).void }



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kuby/docker/spec.rb', line 27

def initialize(environment)
  @environment = environment

  # @credentials = T.let(@credentials, T.nilable(Credentials))
  # @setup_phase = T.let(@setup_phase, T.nilable(SetupPhase))
  # @package_phase = T.let(@package_phase, T.nilable(PackagePhase))
  # @bundler_phase = T.let(@bundler_phase, T.nilable(BundlerPhase))
  # @yarn_phase = T.let(@yarn_phase, T.nilable(YarnPhase))
  # @copy_phase = T.let(@copy_phase, T.nilable(CopyPhase))
  # @app_phase = T.let(@app_phase, T.nilable(AppPhase))
  # @assets_phase = T.let(@assets_phase, T.nilable(AssetsPhase))
  # @webserver_phase = T.let(@webserver_phase, T.nilable(WebserverPhase))

  # @distro_name = T.let(@distro_name, T.nilable(Symbol))
  # @distro_spec = T.let(@distro_spec, T.nilable(Distro))
  # @layer_stack = T.let(@layer_stack, T.nilable(Kuby::Docker::LayerStack))

  # @image_url_str = T.let(@image_url_str, T.nilable(String))
  # @registry_index_url_str = T.let(@registry_index_url_str, T.nilable(String))
  # @image = T.let(@image, T.nilable(Docker::AppImage))

  @app_root_path = DEFAULT_APP_ROOT_PATH
end

Instance Attribute Details

#app_root_pathObject (readonly)

T::Sig::WithoutRuntime.sig { returns(T.nilable(String)) }



21
22
23
# File 'lib/kuby/docker/spec.rb', line 21

def app_root_path
  @app_root_path
end

#environmentObject (readonly)

T::Sig::WithoutRuntime.sig { returns(Kuby::Environment) }



12
13
14
# File 'lib/kuby/docker/spec.rb', line 12

def environment
  @environment
end

#imageObject (readonly)

T::Sig::WithoutRuntime.sig { returns T.nilable(Kuby::Docker::AppImage) }



24
25
26
# File 'lib/kuby/docker/spec.rb', line 24

def image
  @image
end

#image_url_strObject (readonly)

T::Sig::WithoutRuntime.sig { returns(T.nilable(String)) }



15
16
17
# File 'lib/kuby/docker/spec.rb', line 15

def image_url_str
  @image_url_str
end

#registry_index_url_strObject (readonly)

T::Sig::WithoutRuntime.sig { returns(T.nilable(String)) }



18
19
20
# File 'lib/kuby/docker/spec.rb', line 18

def registry_index_url_str
  @registry_index_url_str
end

Instance Method Details

#after_configurationObject

T::Sig::WithoutRuntime.sig { void }



173
174
175
176
177
178
179
180
181
182
183
# File 'lib/kuby/docker/spec.rb', line 173

def after_configuration
  @image = begin
    dockerfile = Dockerfile.new.tap do |df|
      layer_stack.each { |layer| layer.apply_to(df) }
    end

    Docker::AppImage.new(
      dockerfile, image_url_str, credentials, registry_index_url_str
    )
  end
end

#app_phaseObject

T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::AppPhase) }



211
212
213
# File 'lib/kuby/docker/spec.rb', line 211

def app_phase
  @app_phase ||= AppPhase.new(environment)
end

#app_root(path) ⇒ Object

T::Sig::WithoutRuntime.sig { params(path: String).void }



82
83
84
# File 'lib/kuby/docker/spec.rb', line 82

def app_root(path)
  @app_root_path = path
end

#assets_phaseObject

T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::AssetsPhase) }



216
217
218
# File 'lib/kuby/docker/spec.rb', line 216

def assets_phase
  @assets_phase ||= AssetsPhase.new(environment)
end

#base_image(image_url) ⇒ Object

T::Sig::WithoutRuntime.sig { params(image_url: String).void }



57
58
59
# File 'lib/kuby/docker/spec.rb', line 57

def base_image(image_url)
  setup_phase.base_image = image_url
end

#bundler_phaseObject

T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::BundlerPhase) }



196
197
198
# File 'lib/kuby/docker/spec.rb', line 196

def bundler_phase
  @bundler_phase ||= BundlerPhase.new(environment)
end

#bundler_version(version) ⇒ Object

T::Sig::WithoutRuntime.sig { params(version: String).void }



72
73
74
# File 'lib/kuby/docker/spec.rb', line 72

def bundler_version(version)
  bundler_phase.version = version
end

#copy_phaseObject

T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::CopyPhase) }



206
207
208
# File 'lib/kuby/docker/spec.rb', line 206

def copy_phase
  @copy_phase ||= CopyPhase.new(environment)
end

#credentials(&block) ⇒ Object

T::Sig::WithoutRuntime.sig

params(block: T.nilable(T.proc.void)).returns(Kuby::Docker::Credentials)



166
167
168
169
170
# File 'lib/kuby/docker/spec.rb', line 166

def credentials(&block)
  @credentials ||= Credentials.new
  @credentials.instance_eval(&block) if block
  @credentials
end

#delete(name) ⇒ Object

T::Sig::WithoutRuntime.sig { params(name: Symbol).void }



154
155
156
# File 'lib/kuby/docker/spec.rb', line 154

def delete(name)
  layer_stack.delete(name)
end

#distro(distro_name) ⇒ Object

T::Sig::WithoutRuntime.sig { params(distro_name: Symbol).void }



98
99
100
101
# File 'lib/kuby/docker/spec.rb', line 98

def distro(distro_name)
  @distro_name = distro_name
  @distro_spec = nil
end

#distro_nameObject

T::Sig::WithoutRuntime.sig { returns(Symbol) }



52
53
54
# File 'lib/kuby/docker/spec.rb', line 52

def distro_name
  @distro_name || DEFAULT_DISTRO
end

#distro_specObject

T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::Distro) }



226
227
228
229
230
231
232
# File 'lib/kuby/docker/spec.rb', line 226

def distro_spec
  @distro_spec ||= if distro_klass = Kuby.distros[distro_name]
    distro_klass.new(self)
  else
    raise MissingDistroError, "distro '#{distro_name}' hasn't been registered"
  end
end

#exists?(name) ⇒ Boolean

T::Sig::WithoutRuntime.sig { params(name: Symbol).returns(T::Boolean) }

Returns:

  • (Boolean)


159
160
161
# File 'lib/kuby/docker/spec.rb', line 159

def exists?(name)
  layer_stack.includes?(name)
end

#files(path) ⇒ Object

T::Sig::WithoutRuntime.sig { params(path: String).void }



104
105
106
# File 'lib/kuby/docker/spec.rb', line 104

def files(path)
  copy_phase << path
end

#gemfile(path) ⇒ Object

T::Sig::WithoutRuntime.sig { params(path: String).void }



77
78
79
# File 'lib/kuby/docker/spec.rb', line 77

def gemfile(path)
  bundler_phase.gemfile = path
end

#image_url(url) ⇒ Object

T::Sig::WithoutRuntime.sig { params(url: String).void }



114
115
116
# File 'lib/kuby/docker/spec.rb', line 114

def image_url(url)
  @image_url_str = url
end

#insert(name, layer = nil, options = {}, &block) ⇒ Object

T::Sig::WithoutRuntime.sig

params(
  name: Symbol,
  layer: T.nilable(T.any(Layer, T::Hash[Symbol, T.untyped])),
  options: T::Hash[Symbol, T.untyped],
  block: T.nilable(T.proc.params(df: Dockerfile).void)
)
.void



144
145
146
# File 'lib/kuby/docker/spec.rb', line 144

def insert(name, layer = nil, options = {}, &block)
  layer_stack.insert(name, layer, options, &block)
end

#package(package_name, version = nil) ⇒ Object

T::Sig::WithoutRuntime.sig

params(
  package_name: Symbol,
  version: T.nilable(String)
)
.void



93
94
95
# File 'lib/kuby/docker/spec.rb', line 93

def package(package_name, version = nil)
  package_phase.add(package_name, version)
end

#package_phaseObject

T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::PackagePhase) }



191
192
193
# File 'lib/kuby/docker/spec.rb', line 191

def package_phase
  @package_phase ||= PackagePhase.new(environment)
end

#port(port) ⇒ Object

T::Sig::WithoutRuntime.sig { params(port: Integer).void }



109
110
111
# File 'lib/kuby/docker/spec.rb', line 109

def port(port)
  webserver_phase.port = port
end

#rails_env(env) ⇒ Object

T::Sig::WithoutRuntime.sig { params(env: String).void }



67
68
69
# File 'lib/kuby/docker/spec.rb', line 67

def rails_env(env)
  setup_phase.rails_env = env
end

#registry_index_url(url) ⇒ Object

T::Sig::WithoutRuntime.sig { params(url: String).void }



119
120
121
# File 'lib/kuby/docker/spec.rb', line 119

def registry_index_url(url)
  @registry_index_url_str = url
end

#replace(name, layer) ⇒ Object

T::Sig::WithoutRuntime.sig { params(name: Symbol, layer: Layer).void }



149
150
151
# File 'lib/kuby/docker/spec.rb', line 149

def replace(name, layer)
  layer_stack.replace(name, layer)
end

#setup_phaseObject

T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::SetupPhase) }



186
187
188
# File 'lib/kuby/docker/spec.rb', line 186

def setup_phase
  @setup_phase ||= SetupPhase.new(environment, self)
end

#use(name, layer = nil, &block) ⇒ Object

T::Sig::WithoutRuntime.sig

params(
  name: Symbol,
  layer: T.nilable(Layer),
  block: T.nilable(T.proc.params(df: Kuby::Docker::Dockerfile).void)
)
.void



131
132
133
# File 'lib/kuby/docker/spec.rb', line 131

def use(name, layer = nil, &block)
  layer_stack.use(name, layer, &block)
end

#webserver_phaseObject

T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::WebserverPhase) }



221
222
223
# File 'lib/kuby/docker/spec.rb', line 221

def webserver_phase
  @webserver_phase ||= WebserverPhase.new(environment)
end

#working_dir(dir) ⇒ Object

T::Sig::WithoutRuntime.sig { params(dir: String).void }



62
63
64
# File 'lib/kuby/docker/spec.rb', line 62

def working_dir(dir)
  setup_phase.working_dir = dir
end

#yarn_phaseObject

T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::YarnPhase) }



201
202
203
# File 'lib/kuby/docker/spec.rb', line 201

def yarn_phase
  @yarn_phase ||= YarnPhase.new(environment)
end