Class: Ufo::DockerfileUpdater
- Inherits:
-
Object
- Object
- Ufo::DockerfileUpdater
- Defined in:
- lib/ufo/dockerfile_updater.rb
Instance Method Summary collapse
- #current_dockerfile ⇒ Object
- #dockerfile_path ⇒ Object
-
#initialize(full_image_name, options = {}) ⇒ DockerfileUpdater
constructor
A new instance of DockerfileUpdater.
- #new_dockerfile ⇒ Object
- #update ⇒ Object
- #write_new_dockerfile ⇒ Object
Constructor Details
#initialize(full_image_name, options = {}) ⇒ DockerfileUpdater
Returns a new instance of DockerfileUpdater.
3 4 5 6 7 |
# File 'lib/ufo/dockerfile_updater.rb', line 3 def initialize(full_image_name, ={}) @full_image_name = full_image_name @options = @project_root = [:project_root] || '.' end |
Instance Method Details
#current_dockerfile ⇒ Object
13 14 15 |
# File 'lib/ufo/dockerfile_updater.rb', line 13 def current_dockerfile @current_dockerfile ||= IO.read(dockerfile_path) end |
#dockerfile_path ⇒ Object
17 18 19 |
# File 'lib/ufo/dockerfile_updater.rb', line 17 def dockerfile_path "#{@project_root}/Dockerfile" end |
#new_dockerfile ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ufo/dockerfile_updater.rb', line 21 def new_dockerfile lines = current_dockerfile.split("\n") # replace FROM line new_lines = lines.map do |line| if line =~ /^FROM / "FROM #{@full_image_name}" else line end end new_lines.join("\n") + "\n" end |
#update ⇒ Object
9 10 11 |
# File 'lib/ufo/dockerfile_updater.rb', line 9 def update write_new_dockerfile end |
#write_new_dockerfile ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/ufo/dockerfile_updater.rb', line 34 def write_new_dockerfile IO.write(dockerfile_path, new_dockerfile) unless @options[:mute] puts "The Dockerfile FROM statement has been updated with the latest base image:".green puts " #{@full_image_name}".green end end |