Sha256: 9c42327811a79cc8c2f3b9bb55d0a71aca25ca77fc5012521ebe53715a9cb88d

Contents?: true

Size: 743 Bytes

Versions: 2

Compression:

Stored size: 743 Bytes

Contents

module Percheron
  module Actions
    class Shell
      include Base

      DEFAULT_COMMAND = '/bin/sh'
      DOCKER_CLIENT = 'docker'

      def initialize(container, command: DEFAULT_COMMAND)
        @container = container
        @command = command
      end

      def execute!
        exec! if valid?
      end

      private

        attr_reader :container

        def valid?
          Validators::DockerClient.new.valid?
        end

        def command
          "sh -c '%s'" % @command
        end

        def exec!
          cmd = '%s exec -ti %s %s' % [ DOCKER_CLIENT, container.full_name, command ]
          $logger.debug "Executing '#{cmd}' on '#{container.name}' container"
          system(cmd)
        end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
percheron-0.7.6 lib/percheron/actions/shell.rb
percheron-0.7.5 lib/percheron/actions/shell.rb