Sha256: a8914726044a565d75018c92b65400e3dc8c8e95434ea88d4c5983618b487afb

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

module Percheron
  module Container
    module Actions
      class Create

        include Base

        def initialize(container)
          @container = container
        end

        def execute!
          build!
          insert_post_start_scripts!
          create!
        end

        private

          attr_reader :container

          def create_opts
            {
              'name'          => container.name,
              'Image'         => container.image_name,
              'Hostname'      => container.name,
              'Env'           => container.env,
              'ExposedPorts'  => container.exposed_ports,
              'VolumesFrom'   => container.volumes
            }
          end

          def build!
            unless container.image
              $logger.debug "Creating '#{container.image_name}' image"
              Container::Actions::Build.new(container).execute!
            end
          end

          def create!
            $logger.debug "Creating '#{container.name}' container"
            Docker::Container.create(create_opts)
          end

          def insert_post_start_scripts!
            container.post_start_scripts.each do |script|
              file = Pathname.new(File.expand_path(script, base_dir))
              new_image = container.image.insert_local('localPath' => file.to_s, 'outputPath' => "/tmp/#{file.basename}")
              new_image.tag(repo: container.name, tag: container.version.to_s, force: true)
            end
          end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
percheron-0.5.0 lib/percheron/container/actions/create.rb