Sha256: 7af9d02c8628d598fc048f6531f69cfc684632ea1c89f071c290859aa98d6386

Contents?: true

Size: 1.44 KB

Versions: 5

Compression:

Stored size: 1.44 KB

Contents

require 'openssl'

module Docker
  module Cli
    class Dockerfile

      class NoDockerfileFound < StandardError; end
      
      def self.find_available(root = Dir.getwd)
        Dir.glob("**/Dockerfile*")
      end

      def self.run_before?(dockerfile_path)
        DockerRunLog.instance.has_dockerfile_seen_before?(dockerfile_path)
      end

      # expect dockerfile is CONTENT, not file path
      def self.images(dockerfile)
        DockerRunLog.instance.dockerfile_images(dockerfile)
      end

      def initialize(file)
        @dfile = file
      end

      def render_dockerfile(vals = {}, &block)
        if @_df.nil?
          if @dfile.nil?
            @_df = nil
          else
            if File.exist?(@dfile)
              if is_erb_template?
                @_df = process_dockerfile_template(@dfile, vals)
              else
                @_df = File.read(@dfile)
              end
            else
              @_df = nil
            end
          end
        end
        @_df
      end

      def is_erb_template?
        if File.exist?(@dfile)
          cont = File.read(@dfile)
          (cont =~ /<%=/ and cont =~ /%>/) != nil
        else
          false
        end
      end

      def process_dockerfile_template(file, values = {})
        raise Error, "Given dockerfile to process as template not found" if not File.exist?(file)
        DockerfileTemplate::TemplateEngine.new.process(File.read(file), values) 
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
docker-cli-0.5.4 lib/docker/cli/dockerfile.rb
docker-cli-0.5.3 lib/docker/cli/dockerfile.rb
docker-cli-0.5.2 lib/docker/cli/dockerfile.rb
docker-cli-0.5.1 lib/docker/cli/dockerfile.rb
docker-cli-0.5.0 lib/docker/cli/dockerfile.rb