Class: Vtasks::Docker::Image

Inherits:
Object
  • Object
show all
Includes:
Utils::Git, Utils::Semver
Defined in:
lib/vtasks/docker/image.rb,
lib/vtasks/docker/image/tag.rb,
lib/vtasks/docker/image/push.rb,
lib/vtasks/docker/image/build.rb

Overview

Docker Image class

Defined Under Namespace

Classes: Build, Push, Tag

Constant Summary

Constants included from Utils::Semver

Utils::Semver::SEM_LEVELS

Constants included from Utils::Git

Utils::Git::GITHUB_TOKEN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Semver

#bump, #gitver, #semver

Methods included from Utils::Git

#git_branch, #git_ci_status, #git_clean_repo, #git_commit, #git_url

Constructor Details

#initialize(image, path, args = {}) ⇒ Image

Returns a new instance of Image.



18
19
20
21
22
# File 'lib/vtasks/docker/image.rb', line 18

def initialize(image, path, args = {})
  @image          ||= image
  @path           ||= path
  @has_build_args ||= args.fetch(:has_build_args, false)
end

Instance Attribute Details

#has_build_argsObject (readonly)

Returns the value of attribute has_build_args.



16
17
18
# File 'lib/vtasks/docker/image.rb', line 16

def has_build_args
  @has_build_args
end

#imageObject (readonly)

Returns the value of attribute image.



16
17
18
# File 'lib/vtasks/docker/image.rb', line 16

def image
  @image
end

#pathObject (readonly)

Returns the value of attribute path.



16
17
18
# File 'lib/vtasks/docker/image.rb', line 16

def path
  @path
end

#tagsObject (readonly)

Returns the value of attribute tags.



16
17
18
# File 'lib/vtasks/docker/image.rb', line 16

def tags
  @tags
end

Instance Method Details

#buildObject

Build image



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/vtasks/docker/image.rb', line 49

def build
  args = {
    build_date: build_date,
    build_tag: build_tag
  }
  build = Vtasks::Docker::Image::Build.new(image, path, args)
  if has_build_args
    build.with_arguments
  else
    build.without_arguments
  end
end

#build_dateObject

Compose build date



39
40
41
# File 'lib/vtasks/docker/image.rb', line 39

def build_date
  @build_date ||= ::Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
end

#build_tagObject

Compose build tag



44
45
46
# File 'lib/vtasks/docker/image.rb', line 44

def build_tag
  @build_tag ||= gitver.to_s
end

#build_with_tagsObject

Build image with tags



70
71
72
73
# File 'lib/vtasks/docker/image.rb', line 70

def build_with_tags
  build
  tag
end

#pushObject

Push image



76
77
78
79
80
# File 'lib/vtasks/docker/image.rb', line 76

def push
  tags.each do |tag|
    Vtasks::Docker::Image::Push.new(image, tag)
  end
end

#tagObject

Tag image



63
64
65
66
67
# File 'lib/vtasks/docker/image.rb', line 63

def tag
  tags.each do |tag|
    Vtasks::Docker::Image::Tag.new(image, build_tag, tag)
  end
end