Sha256: b41b92a6385ee82af192cb4dfcd2cf8ce24bc0f5e2aa4a61ede1afae84eb1cd2

Contents?: true

Size: 989 Bytes

Versions: 36

Compression:

Stored size: 989 Bytes

Contents

module Ufo::Docker
  class Dockerfile
    include Ufo::Utils::Logging

    def initialize(docker_image, options={})
      @docker_image, @options = docker_image, options
    end

    def update
      write_new_dockerfile
    end

    def current_dockerfile
      @current_dockerfile ||= IO.read(dockerfile_path)
    end

    def dockerfile_path
      "#{Ufo.root}/Dockerfile"
    end

    def new_dockerfile
      lines = current_dockerfile.split("\n")
      # replace FROM line
      new_lines = lines.map do |line|
                    if line =~ /^FROM /
                      "FROM #{@docker_image}"
                    else
                      line
                    end
                  end
      new_lines.join("\n") + "\n"
    end

    def write_new_dockerfile
      IO.write(dockerfile_path, new_dockerfile)
      logger.debug <<~EOL
        The Dockerfile FROM statement has been updated with the latest base image:

            #{@docker_image}

      EOL
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
ufo-6.3.13 lib/ufo/docker/dockerfile.rb
ufo-6.3.12 lib/ufo/docker/dockerfile.rb
ufo-6.3.11 lib/ufo/docker/dockerfile.rb
ufo-6.3.10 lib/ufo/docker/dockerfile.rb
ufo-6.3.9 lib/ufo/docker/dockerfile.rb
ufo-6.3.8 lib/ufo/docker/dockerfile.rb
ufo-6.3.7 lib/ufo/docker/dockerfile.rb
ufo-6.3.6 lib/ufo/docker/dockerfile.rb
ufo-6.3.5 lib/ufo/docker/dockerfile.rb
ufo-6.3.4 lib/ufo/docker/dockerfile.rb
ufo-6.3.3 lib/ufo/docker/dockerfile.rb
ufo-6.3.2 lib/ufo/docker/dockerfile.rb
ufo-6.3.1 lib/ufo/docker/dockerfile.rb
ufo-6.3.0 lib/ufo/docker/dockerfile.rb
ufo-6.2.5 lib/ufo/docker/dockerfile.rb
ufo-6.2.4 lib/ufo/docker/dockerfile.rb
ufo-6.2.3 lib/ufo/docker/dockerfile.rb
ufo-6.2.2 lib/ufo/docker/dockerfile.rb
ufo-6.2.1 lib/ufo/docker/dockerfile.rb
ufo-6.2.0 lib/ufo/docker/dockerfile.rb