Class: Kuby::Docker::Image

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dockerfile, image_url, credentials, registry_index_url = nil, main_tag = nil, alias_tags = []) ⇒ Image

T::Sig::WithoutRuntime.sig

params(
  dockerfile: T.any(Dockerfile, T.proc.returns(Kuby::Docker::Dockerfile)),
  image_url: String,
  credentials: Kuby::Docker::Credentials,
  registry_index_url: T.nilable(String),
  main_tag: T.nilable(String),
  alias_tags: T::Array[String]
).void



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/kuby/docker/image.rb', line 36

def initialize(dockerfile, image_url, credentials, registry_index_url = nil, main_tag = nil, alias_tags = [])
  @dockerfile = dockerfile
  @image_url = image_url
  @registry_index_url = registry_index_url
  @credentials = credentials
  @main_tag = main_tag
  @alias_tags = alias_tags
  # @identifier = T.let(@identifier, T.nilable(String))

  # @image_host = T.let(@image_host, T.nilable(String))
  # @image_hostname = T.let(@image_hostname, T.nilable(String))
  # @registry_index_host = T.let(@registry_index_host, T.nilable(String))
  # @registry_index_hostname = T.let(@registry_index_hostname, T.nilable(String))
  # @registry_index_uri = T.let(@registry_index_uri, T.nilable(DockerURI))
  # @image_repo = T.let(@image_repo, T.nilable(String))
  # @full_image_uri = T.let(@full_image_uri, T.nilable(DockerURI))
  # @docker_cli = T.let(@docker_cli, T.nilable(Docker::CLI))
end

Instance Attribute Details

#alias_tagsObject (readonly)

T::Sig::WithoutRuntime.sig { returns T::Array }



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

def alias_tags
  @alias_tags
end

#credentialsObject (readonly)

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



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

def credentials
  @credentials
end

#identifierObject (readonly)

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



9
10
11
# File 'lib/kuby/docker/image.rb', line 9

def identifier
  @identifier
end

#image_urlObject (readonly)

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



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

def image_url
  @image_url
end

#main_tagObject (readonly)

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



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

def main_tag
  @main_tag
end

#registry_index_urlObject (readonly)

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



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

def registry_index_url
  @registry_index_url
end

Instance Method Details

#build(build_args = {}, docker_args = [], context: nil, cache_from: nil) ⇒ Object

T::Sig::WithoutRuntime.sig

params(
  build_args: T::Hash[String, String],
  docker_args: T::Array[String],
  context: T.nilable(String),
  cache_from: T.nilable(String)
).void

Raises:

  • (NotImplementedError)


127
128
129
# File 'lib/kuby/docker/image.rb', line 127

def build(build_args = {}, docker_args = [], context: nil, cache_from: nil)
  raise NotImplementedError, 'please use a Docker::Image subclass'
end

#current_versionObject

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

Raises:

  • (NotImplementedError)


61
62
63
# File 'lib/kuby/docker/image.rb', line 61

def current_version
  raise NotImplementedError, 'please use a Docker::Image subclass'
end

#docker_cliObject

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



142
143
144
# File 'lib/kuby/docker/image.rb', line 142

def docker_cli
  @docker_cli ||= Docker::CLI.new
end

#dockerfileObject

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



71
72
73
74
75
76
77
# File 'lib/kuby/docker/image.rb', line 71

def dockerfile
  if @dockerfile.respond_to?(:call)
    @dockerfile.call
  else
    @dockerfile
  end
end

#image_hostObject

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



80
81
82
# File 'lib/kuby/docker/image.rb', line 80

def image_host
  @image_host ||= "#{image_uri.host}:#{image_uri.port}"
end

#image_hostnameObject

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



95
96
97
# File 'lib/kuby/docker/image.rb', line 95

def image_hostname
  @image_hostname ||= image_uri.host
end

#image_repoObject

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



100
101
102
# File 'lib/kuby/docker/image.rb', line 100

def image_repo
  @image_repo ||= image_uri.path
end

#image_uriObject

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



105
106
107
# File 'lib/kuby/docker/image.rb', line 105

def image_uri
  @full_image_uri ||= DockerURI.parse_uri(image_url)
end

#new_versionObject

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

Raises:

  • (NotImplementedError)


56
57
58
# File 'lib/kuby/docker/image.rb', line 56

def new_version
  raise NotImplementedError, 'please use a Docker::Image subclass'
end

#previous_version(current_tag = nil) ⇒ Object

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

Raises:

  • (NotImplementedError)


66
67
68
# File 'lib/kuby/docker/image.rb', line 66

def previous_version(current_tag = nil)
  raise NotImplementedError, 'please use a Docker::Image subclass'
end

#pull(tag) ⇒ Object

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

Raises:

  • (NotImplementedError)


137
138
139
# File 'lib/kuby/docker/image.rb', line 137

def pull(tag)
  raise NotImplementedError, 'please use a Docker::Image subclass'
end

#push(tag) ⇒ Object

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

Raises:

  • (NotImplementedError)


132
133
134
# File 'lib/kuby/docker/image.rb', line 132

def push(tag)
  raise NotImplementedError, 'please use a Docker::Image subclass'
end

#registry_index_hostObject

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



85
86
87
# File 'lib/kuby/docker/image.rb', line 85

def registry_index_host
  @registry_index_host ||= "#{registry_index_uri.host}:#{registry_index_uri.port}"
end

#registry_index_hostnameObject

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



90
91
92
# File 'lib/kuby/docker/image.rb', line 90

def registry_index_hostname
  @registry_index_hostname ||= registry_index_uri.host
end

#registry_index_uriObject

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



110
111
112
# File 'lib/kuby/docker/image.rb', line 110

def registry_index_uri
  @registry_index_uri ||= DockerURI.parse_index_uri(registry_index_url || image_url)
end

#tagsObject

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



115
116
117
# File 'lib/kuby/docker/image.rb', line 115

def tags
  [main_tag, *alias_tags].compact
end