Sha256: 371bbad7c081ae7aeea356043949a42ddd924a4ab3b3935249843ba09466fa54

Contents?: true

Size: 1.17 KB

Versions: 9

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EacDocker
  class Container
    enable_immutable
    immutable_accessor :interactive, :temporary, :tty, type: :boolean
    immutable_accessor :env, type: :hash
    immutable_accessor :command_arg, :volume, type: :array
    common_constructor :image

    def immutable_constructor_args
      [image]
    end

    alias immutable_volume volume

    def volume(left_part, right_part = null)
      immutable_volume(right_part.if_present(left_part) { |v| "#{left_part}:#{v}" })
    end

    def run_command
      ::EacDocker::Executables.docker.command('run', *run_command_args)
    end

    def run_command_args
      run_command_boolean_args + run_command_envs_args + run_command_volumes_args + [image.id] +
        command_args
    end

    private

    def run_command_boolean_args
      r = []
      r << '--interactive' if interactive?
      r << '--tty' if tty?
      r << '--rm' if temporary?
      r
    end

    def run_command_volumes_args
      volumes.flat_map { |volume| ['--volume', volume] }
    end

    def run_command_envs_args
      envs.flat_map { |name, value| ['--env', "#{name}=#{value}"] }
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
ehbrs-tools-0.16.2 vendor/eac_docker/lib/eac_docker/container.rb
ehbrs-tools-0.16.1 vendor/eac_docker/lib/eac_docker/container.rb
ehbrs-tools-0.16.0 vendor/eac_docker/lib/eac_docker/container.rb
ehbrs-tools-0.15.0 vendor/eac_docker/lib/eac_docker/container.rb
ehbrs-tools-0.14.1 vendor/eac_docker/lib/eac_docker/container.rb
ehbrs-tools-0.14.0 vendor/eac_docker/lib/eac_docker/container.rb
ehbrs-tools-0.13.1 vendor/eac_docker/lib/eac_docker/container.rb
eac_docker-0.1.0 lib/eac_docker/container.rb
ehbrs-tools-0.13.0 vendor/eac_docker/lib/eac_docker/container.rb