Sha256: 6940fc73f54ea19aadec365a61e5b917b11a59dc604281de0fc28116328483e9

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

module Percheron
  module Actions
    module Base

      def base_dir
        container.dockerfile.dirname.to_s
      end

      def in_working_directory(new_dir)
        old_dir = Dir.pwd
        Dir.chdir(new_dir)
        yield
      ensure
        Dir.chdir(old_dir)
      end

      def now_timestamp
        Time.now.strftime('%Y%m%d%H%M%S')
      end

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

      def stop_containers!(containers)
        exec_on_containers!(containers) do |container|
          if container.running?
            $logger.debug "Stopping '#{container.name}' container"
            Stop.new(container).execute!
          end
        end
      end

      def start_containers!(containers)
        exec_on_containers!(containers) do |container|
          unless container.running?
            $logger.debug "Starting '#{container.name}' container"
            Start.new(container, container.dependant_containers.values).execute!
          end
        end
      end

      def exec_on_containers!(containers)
        containers.inject([]) do |all, container|
          all << container if yield(container)
          all
        end.compact
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
percheron-0.6.3 lib/percheron/actions/base.rb
percheron-0.6.2 lib/percheron/actions/base.rb