Class: Vtasks::Docker::Image::Build

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

Overview

Docker Build class

Constant Summary

Constants included from Utils::Git

Utils::Git::GITHUB_TOKEN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Output

#debug, #error, #info, #warn

Methods included from Utils::Git

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

Constructor Details

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

Returns a new instance of Build.



14
15
16
17
18
19
20
21
# File 'lib/vtasks/docker/image/build.rb', line 14

def initialize(image, path, args={})
  @image      ||= image
  @path       ||= path
  @build_date ||= args.fetch(:build_date)
  @build_tag  ||= args.fetch(:build_tag)

  @cmd = 'docker image build'
end

Instance Attribute Details

#build_dateObject (readonly)

Returns the value of attribute build_date.



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

def build_date
  @build_date
end

#build_tagObject (readonly)

Returns the value of attribute build_tag.



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

def build_tag
  @build_tag
end

#imageObject (readonly)

Returns the value of attribute image.



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

def image
  @image
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#with_argumentsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vtasks/docker/image/build.rb', line 36

def with_arguments
  build_args = {
    'BUILD_DATE' => build_date,
    'VERSION'    => build_tag,
    'VCS_URL'    => git_url,
    'VCS_REF'    => git_commit
  }

  build_args.map do |key, value|
    @cmd += " --build-arg #{key}=#{value}"
  end

  without_arguments
end

#without_argumentsObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vtasks/docker/image/build.rb', line 23

def without_arguments
  info "Pulling #{image}" # to speed up the building process
  system "docker pull #{image}" unless ENV['DOCKER_NO_CACHE']

  info "Building #{image}:#{build_tag}"
  system "#{@cmd} -t #{image}:#{build_tag} #{path}"

  if $?.exitstatus != 0
    error 'Build command failed!'
    abort
  end
end