Class: Kuby::Docker::TimestampedImage

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

Direct Known Subclasses

AppImage

Instance Attribute Summary

Attributes inherited from Image

#alias_tags, #credentials, #identifier, #image_url, #main_tag, #registry_index_url

Instance Method Summary collapse

Methods inherited from Image

#docker_cli, #dockerfile, #image_host, #image_hostname, #image_repo, #image_uri, #registry_index_host, #registry_index_hostname, #registry_index_uri, #tags

Constructor Details

#initialize(dockerfile, image_url, credentials, registry_index_url_str = nil, main_tag = nil, alias_tags = []) ⇒ TimestampedImage

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_str: T.nilable(String),
  main_tag: T.nilable(String),
  alias_tags: T::Array[String]
).void



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kuby/docker/timestamped_image.rb', line 20

def initialize(dockerfile, image_url, credentials, registry_index_url_str = nil, main_tag = nil, alias_tags = [])
  # @new_version = T.let(@new_version, T.nilable(Image))
  # @current_version = T.let(@current_version, T.nilable(Image))
  # @previous_version = T.let(@previous_version, T.nilable(Image))

  # @remote_client = T.let(@remote_client, T.nilable(::Docker::Remote::Client))
  # @local = T.let(@local, T.nilable(LocalTags))
  # @remote = T.let(@remote, T.nilable(RemoteTags))

  super
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



89
90
91
92
93
94
95
96
97
# File 'lib/kuby/docker/timestamped_image.rb', line 89

def build(build_args = {}, docker_args = [], context: nil, cache_from: nil)
  docker_cli.build(
    self,
    build_args: build_args,
    docker_args: docker_args,
    context: context,
    cache_from: cache_from
  )
end

#current_versionObject

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



40
41
42
43
44
45
46
47
48
# File 'lib/kuby/docker/timestamped_image.rb', line 40

def current_version
  @current_version ||= begin
    duplicate_with_tags(
      latest_timestamp_tag.to_s, [Kuby::Docker::LATEST_TAG]
    )
  rescue MissingTagError
    new_version
  end
end

#exists?Boolean

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

Returns:

  • (Boolean)


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

def exists?
  return false unless main_tag
  timestamp_tags.include?(TimestampTag.try_parse(main_tag))
end

#latest_timestamp_tagObject

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

Raises:



75
76
77
78
79
# File 'lib/kuby/docker/timestamped_image.rb', line 75

def latest_timestamp_tag
  tag = timestamp_tags.sort.last
  raise MissingTagError, 'could not find latest timestamp tag' unless tag
  tag
end

#new_versionObject

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



33
34
35
36
37
# File 'lib/kuby/docker/timestamped_image.rb', line 33

def new_version
  @new_version ||= duplicate_with_tags(
    TimestampTag.now.to_s, [Kuby::Docker::LATEST_TAG]
  )
end

#previous_timestamp_tag(current_tag = nil) ⇒ Object

T::Sig::WithoutRuntime.sig { params(current_tag: T.nilable(String)).returns(Kuby::Docker::TimestampTag) }

Raises:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/kuby/docker/timestamped_image.rb', line 58

def previous_timestamp_tag(current_tag = nil)
  current_tag = TimestampTag.try_parse(current_tag || latest_timestamp_tag.to_s)
  raise MissingTagError, 'could not find current timestamp tag' unless current_tag

  all_tags = timestamp_tags.sort

  idx = all_tags.index do |tag|
    tag.time == current_tag.time
  end

  idx ||= 0
  raise MissingTagError, 'could not find previous timestamp tag' unless idx > 0

  all_tags[idx - 1]
end

#previous_version(current_tag = nil) ⇒ Object

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



51
52
53
54
55
# File 'lib/kuby/docker/timestamped_image.rb', line 51

def previous_version(current_tag = nil)
  @previous_version ||= duplicate_with_tags(
    previous_timestamp_tag(current_tag).to_s, []
  )
end

#pull(tag) ⇒ Object

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



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

def pull(tag)
  docker_cli.pull(image_url, tag)
end

#push(tag) ⇒ Object

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



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

def push(tag)
  docker_cli.push(image_url, tag)
end