Sha256: 598bdf67947faf17d4615c2c5d73bfeb9001f78c036ab4313a1e0d8c25780ded

Contents?: true

Size: 1.57 KB

Versions: 8

Compression:

Stored size: 1.57 KB

Contents

require 'fileutils'

class Indocker::Images::ImageCompiler
  BUILDS_DIR = 'image_build'.freeze
  DOCKERIGNORE = <<~EOS
    Dockerfile
    .DS_Store
    **/.DS_Store
    **/*.log
    **/*_spec.rb
    node_modules
    .vagrant
    .vscode
    tmp
    logs
  EOS

  def initialize
    @compiled_images = Hash.new(false)
  end

  def compile(build_context, image, skip_dependent)
    if !skip_dependent
      image.dependent_images.each do |dependent_image|
        compile_image(build_context, dependent_image)
      end
    end

    compile_image(build_context, image)
  end

  def compile_image(build_context, image)
    return if @compiled_images[image]

    compile_dir = File.join(build_context.configuration.build_dir, BUILDS_DIR, image.name.to_s)
    FileUtils.rm_rf(compile_dir)
    FileUtils.mkdir_p(compile_dir)

    if image.build_context
      templates_compiler = Indocker::Images::TemplatesCompiler.new

      templates_compiler.compile(
        templates_dir: image.build_context,
        compile_dir: compile_dir,
        context: build_context
      )
    end

    compiler = Indocker::Images::TemplateCompiler.new

    target_dockerfile = File.join(compile_dir, 'Dockerfile')
    FileUtils.cp(image.dockerfile, target_dockerfile)
    compiler.compile(target_dockerfile, build_context)

    File
      .join(compile_dir, '.dockerignore')
      .tap { |_| File.write(_, Indocker.dockerignore.join("\n")) }

    if image.before_build
      image.before_build.call(build_context, compile_dir)
    end

    build_context.build_image(image, compile_dir)

    @compiled_images[image] = true
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
indocker-0.1.18 lib/indocker/images/image_compiler.rb
indocker-0.3.1 lib/indocker/images/image_compiler.rb
indocker-0.3.0 lib/indocker/images/image_compiler.rb
indocker-0.1.17 lib/indocker/images/image_compiler.rb
indocker-0.1.16 lib/indocker/images/image_compiler.rb
indocker-0.1.15 lib/indocker/images/image_compiler.rb
indocker-0.1.14 lib/indocker/images/image_compiler.rb
indocker-0.1.13 lib/indocker/images/image_compiler.rb