Class: Kuby::Docker::TimestampedImage

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

Direct Known Subclasses

AppImage

Instance Attribute Summary

Attributes inherited from Image

#alias_tags, #credentials, #image_url, #main_tag

Instance Method Summary collapse

Methods inherited from Image

#docker_cli, #dockerfile, #image_host, #image_hostname, #image_repo, #image_uri, #tags

Constructor Details

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

Returns a new instance of TimestampedImage.



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

def initialize(dockerfile, image_url, credentials, 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 = {}) ⇒ Object



77
78
79
80
81
# File 'lib/kuby/docker/timestamped_image.rb', line 77

def build(build_args = {})
  docker_cli.build(new_version, build_args: build_args)
  @current_version = new_version
  @new_version = nil
end

#current_versionObject



39
40
41
42
43
# File 'lib/kuby/docker/timestamped_image.rb', line 39

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

#latest_timestamp_tagObject

Raises:



70
71
72
73
74
# File 'lib/kuby/docker/timestamped_image.rb', line 70

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

#new_versionObject



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

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

#previous_timestamp_tag(current_tag = nil) ⇒ Object

Raises:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/kuby/docker/timestamped_image.rb', line 53

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

  T.must(all_tags[idx - 1])
end

#previous_version(current_tag = nil) ⇒ Object



46
47
48
49
50
# File 'lib/kuby/docker/timestamped_image.rb', line 46

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

#push(tag) ⇒ Object



84
85
86
# File 'lib/kuby/docker/timestamped_image.rb', line 84

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