Class: Vtasks::Docker::Image::Build
- Inherits:
-
Object
- Object
- Vtasks::Docker::Image::Build
- Includes:
- Utils::Git, Utils::Output
- Defined in:
- lib/vtasks/docker/image/build.rb
Overview
Docker Build class
Constant Summary
Constants included from Utils::Git
Instance Attribute Summary collapse
-
#build_date ⇒ Object
readonly
Returns the value of attribute build_date.
-
#build_tag ⇒ Object
readonly
Returns the value of attribute build_tag.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(image, path, args = {}) ⇒ Build
constructor
A new instance of Build.
- #with_arguments ⇒ Object
- #without_arguments ⇒ Object
Methods included from Utils::Output
Methods included from Utils::Git
#git_branch, #git_ci_status, #git_clean_repo, #git_commit, #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_date ⇒ Object (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_tag ⇒ Object (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 |
#image ⇒ Object (readonly)
Returns the value of attribute image.
12 13 14 |
# File 'lib/vtasks/docker/image/build.rb', line 12 def image @image end |
#path ⇒ Object (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_arguments ⇒ Object
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_arguments ⇒ Object
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 |