exec

package
v0.10.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package exec provides configuration options for executing programs inside containers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd []string

func Command

func Command(cmd string, args ...string) Cmd

Command takes a command with its optional arguments, returning a Cmd object to be used with github.com/thediveo/morbyd.Container.Exec.

type Opt

type Opt func(*Options) error

Opt is a configuration option to run a command inside a container using github.com/thediveo/morbyd.Container.Run.

func WithCombinedOutput

func WithCombinedOutput(w io.Writer) Opt

WithCombinedOutput sends the commands's stdout and stderr to the specified io.Writer. This also automatically attaches the commands's stdout and stderr after the command execution context has been created.

func WithConsoleSize

func WithConsoleSize(width, height uint) Opt

WithConsoleSize sets with width and height of the pseudo TTY; please note the width-height order in contrast to the Docker API order.

func WithDemuxedOutput

func WithDemuxedOutput(out io.Writer, err io.Writer) Opt

WithDemuxedOutput disables the TTY option in order to send the command's stdout and stderr properly separated to the specified out and err io.Writer.

It is a known limitation of the (pseudo) TTY to combine both stdout and stderr of the commands's output streams, and there is no way for Docker (and thus for us) to demultiplex this output sludge after the fact.

func WithEnvVars

func WithEnvVars(vars ...string) Opt

WithEnvVars adds multiple environment variables to the container to be started.

func WithInput

func WithInput(r io.Reader) Opt

WithInput sends input data from the specified io.Reader to the commands's stdin. For this, it allocates a stdin for the command when creating its execution context and then attaches to this stdin after creation.

func WithPrivileged

func WithPrivileged() Opt

WithPrivileged executes the command as privileged inside the container.

func WithTTY

func WithTTY() Opt

WithTTY allocates a pseudo TTY for the commands's input and output.

Please note that using a TTY causes the commands's stdout and stderr streams to get mixed together, so this option can be used only in combination with WithCombinedOutput. Specifying it after WithDemuxedOutput will cause the combined stdout+stderr output to appear only on the specified output io.Writer, whereas the specified error io.Writer won't receive any (error) output at all.

When WithTTY is used before WithDemuxedOutput, it'll become ineffective.

func WithUser

func WithUser(user string) Opt

WithUser sets the user (ID or name) that executes the command.

func WithWorkingDir

func WithWorkingDir(path string) Opt

WithWorkingDir sets the (current) working directory when executing the command inside the container.

type Options

type Options struct {
	In   io.Reader
	Out  io.Writer
	Err  io.Writer
	Conf types.ExecConfig
}

Options represents the plethora of configuration options when running a command inside a container, as well as additional configuration options for handling the output (and optionally input) stream of the command.

Please note that the command to be executed is not passed as an option to github.com/thediveo/morbyd.Container.Exec, but instead as a required Cmd.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL