Class: Kuby::Docker::TimestampedImage
- Defined in:
- lib/kuby/docker/timestamped_image.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Image
#alias_tags, #credentials, #identifier, #image_url, #main_tag, #registry_index_url
Instance Method Summary collapse
-
#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, context: T.nilable(String), cache_from: T.nilable(String) ).void }.
-
#current_version ⇒ Object
T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::Image) }.
-
#exists? ⇒ Boolean
T::Sig::WithoutRuntime.sig { returns(T::Boolean) }.
-
#initialize(dockerfile, image_url, credentials, registry_index_url_str = nil, main_tag = nil, alias_tags = []) ⇒ TimestampedImage
constructor
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 ).void }.
-
#latest_timestamp_tag ⇒ Object
T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::TimestampTag) }.
-
#new_version ⇒ Object
T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::Image) }.
-
#previous_timestamp_tag(current_tag = nil) ⇒ Object
T::Sig::WithoutRuntime.sig { params(current_tag: T.nilable(String)).returns(Kuby::Docker::TimestampTag) }.
-
#previous_version(current_tag = nil) ⇒ Object
T::Sig::WithoutRuntime.sig { params(current_tag: T.nilable(String)).returns(Kuby::Docker::Image) }.
-
#pull(tag) ⇒ Object
T::Sig::WithoutRuntime.sig { params(tag: String).void }.
-
#push(tag) ⇒ Object
T::Sig::WithoutRuntime.sig { params(tag: String).void }.
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, = []) # @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_version ⇒ Object
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 ( .to_s, [Kuby::Docker::LATEST_TAG] ) rescue MissingTagError new_version end end |
#exists? ⇒ Boolean
T::Sig::WithoutRuntime.sig { returns(T::Boolean) }
110 111 112 113 |
# File 'lib/kuby/docker/timestamped_image.rb', line 110 def exists? return false unless main_tag .include?(TimestampTag.try_parse(main_tag)) end |
#latest_timestamp_tag ⇒ Object
T::Sig::WithoutRuntime.sig { returns(Kuby::Docker::TimestampTag) }
75 76 77 78 79 |
# File 'lib/kuby/docker/timestamped_image.rb', line 75 def tag = .sort.last raise MissingTagError, 'could not find latest timestamp tag' unless tag tag end |
#new_version ⇒ Object
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 ||= ( 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) }
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 (current_tag = nil) current_tag = TimestampTag.try_parse(current_tag || .to_s) raise MissingTagError, 'could not find current timestamp tag' unless current_tag = .sort idx = .index do |tag| tag.time == current_tag.time end idx ||= 0 raise MissingTagError, 'could not find previous timestamp tag' unless idx > 0 [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 ||= ( (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 |