Documentation
¶
Index ¶
- Variables
- func ApplyCommand(ctx context.Context, c Command, t Transport) error
- func ApplyCommandPrint(ctx context.Context, c Command, t Transport, log PrintFunc) error
- func RandomString(n int) string
- func ReadPrivateKey(path string) (*bytes.Buffer, error)
- func ReadPrivateKeys() ([]*bytes.Buffer, error)
- func Wait(ctx context.Context, f func() error) error
- type AWSUploadConfig
- type Closer
- type CombinedWriter
- type Command
- type CommonArgs
- type ContainerBootCommand
- type ContainerCliCommand
- type ExecuteOpt
- type Executor
- type PrintFunc
- type Pusher
- type SSHTransport
- type SSHTransportConfig
- type StringCommand
- type Transport
Constants ¶
This section is empty.
Variables ¶
var ErrCommand = errors.New("command error")
var ErrConfigure = errors.New("error while configuring")
ErrConfigure is returned when an error occurs during configuration.
var ErrContainerPull = errors.New("error while pulling container")
var ErrCopy = errors.New("copy error")
var ErrHostnameEmpty = errors.New("hostname is empty")
var ErrKnownHosts = errors.New("known hosts error")
var ErrNoContainerRuntime = errors.New("no container runtime found")
var ErrPush = errors.New("error while pushing")
ErrPush is returned when an error occurs during pushing.
var ErrSSHDial = errors.New("ssh dial error")
var ErrSSHNewSession = errors.New("ssh new session error")
Functions ¶
func ApplyCommand ¶
ApplyCommand configures, pushes, and executes a command.
func ApplyCommandPrint ¶
ApplyCommand configures, pushes, and executes a command. It logs the command to the provided PrintFunc.
func RandomString ¶
RandomString generates a random string of length n that is not cryptographically safe
func ReadPrivateKey ¶
ReadPrivateKey reads a private key from the specified path.
func ReadPrivateKeys ¶
ReadPrivateKeys reads the default private keys from the known paths.
Types ¶
type AWSUploadConfig ¶
type AWSUploadConfig struct {
// AWSAccessKeyID credential. Maps to the AWS_ACCESS_KEY_ID environment variable.
AWSAccessKeyID string
// AWSSecretAccessKey credential. Maps to the AWS_SECRET_ACCESS_KEY environment variable.
AWSSecretAccessKey string
// AMIName is the name of the AMI to register.
AMIName string
// S3Bucket is the name of a temporary S3 bucket to upload the image to.
S3Bucket string
// S3Region is the region of the S3 bucket and the resulting AMI.
Region string
}
AWSUploadCommand uploads the image to an S3 bucket and registers it as an AMI.
type CombinedWriter ¶
type CombinedWriter struct {
// contains filtered or unexported fields
}
CombinedWriter is a writer that writes to a buffer and is safe for concurrent use.
func (*CombinedWriter) FirstLine ¶
func (w *CombinedWriter) FirstLine() string
FirstLine returns the first line of the output trimmed of leading and trailing whitespace
func (*CombinedWriter) Reset ¶
func (w *CombinedWriter) Reset()
func (*CombinedWriter) String ¶
func (w *CombinedWriter) String() string
type Command ¶
type Command interface {
// Configure configures the command and prepares the environment.
Configure(ctx context.Context, exec Executor) error
// Push uploads one or more files to the remote host. Files are stored as temporary
// files and are automatically cleaned up after the command is executed.
Push(ctx context.Context, pusher Pusher) error
// Build returns the command to execute. This command is executed in the remote environment.
// The command should be a single string that can be passed to a shell. The command should
// not include the shell invocation and must be protected against shell injection.
Build() string
}
Command is an interface for a command that can be executed.
type CommonArgs ¶
type CommonArgs struct {
// DryRun is a flag to print the command instead of executing it. Blueprint is still pushed
// to the remote machine and then cleaned up.
DryRun bool
// Interactive passes the --interactive flag to the container runtime.
Interactive bool
// TTY passes the --tty flag to the container runtime.
TTY bool
// TeeLog is a flag to tee the output of the command to a file named build.log for later use.
TeeLog bool
}
type ContainerBootCommand ¶
type ContainerBootCommand struct {
// Source OCI (podman, docker) image repository URL.
Repository string
// Type is the image type: ami, anaconda-iso, gce, iso, qcow2, raw, vhd, vmdk (default [qcow2]
// Maps to the argument named --type.
Type string
// Arch is the architecture, must be set to the architecture of the remote machine
// since cross-compilation is not supported yet.
// Maps to the argument named --target-arch.
Arch string
// RootFS is the root filesystem to use. Supported values: ext4, xfs, btrfs.
// Maps to the argument named --rootfs.
RootFS string
// Blueprint is the full contents of a blueprint.
Blueprint string
// OutputDir is the directory where the output image is saved. When unset, a new directory will
// be created in the remote machine home directory. The caller must cleanup the directory.
OutputDir string
// Common arguments for all container commands.
Common CommonArgs
// AWSUploadConfig is the configuration for uploading the image to AWS. Must be set when the
// Type is set to "ami".
AWSUploadConfig *AWSUploadConfig
// contains filtered or unexported fields
}
ContainerBootCommand builds a bootc-image-builder command line via podman or docker which builds an image from a blueprint. The blueprint is pushed to the remote machine via SSH and the command is executed there. The output image is saved to the specified directory which must be created and cleanuped up beforehand.
For more information see https://github.com/osbuild/bootc-image-builder
func (*ContainerBootCommand) Build ¶
func (c *ContainerBootCommand) Build() string
type ContainerCliCommand ¶
type ContainerCliCommand struct {
// Distro is the distribution name
Distro string
// Type is the image type
Type string
// Arch is the architecture, must be set to the architecture of the remote machine
// since cross-compilation is not supported yet.
Arch string
// Blueprint is the full contents of a blueprint.
Blueprint string
// OutputDir is the directory where the output image is saved. When unset, a new directory will
// be created in the remote machine home directory. The caller must cleanup the directory.
OutputDir string
// Common arguments for all container commands.
Common CommonArgs
// contains filtered or unexported fields
}
ContainerCliCommand builds an image-builder-cli command line via podman or docker which builds an image from a blueprint. The blueprint is pushed to the remote machine via SSH and the command is executed there. The output image is saved to the specified directory which must be created and cleanuped up beforehand.
For more information see https://github.com/osbuild/image-builder-cli
func (*ContainerCliCommand) Build ¶
func (c *ContainerCliCommand) Build() string
type ExecuteOpt ¶
ExecuteOpt is a function that configures the SSH session for a command execution
func WithCombinedWriter ¶
func WithCombinedWriter(w *CombinedWriter) ExecuteOpt
WithStdinWriter configures the SSH session to use the specified writer for standard input.
func WithInputOutput ¶
func WithInputOutput(stdin io.Reader, stdout, stderr io.Writer) ExecuteOpt
WithInputOutput configures the SSH session to use the specified reader and writers for standard input, output, and error.
type Executor ¶
type Executor interface {
Execute(ctx context.Context, cmd Command, opts ...ExecuteOpt) error
}
type SSHTransport ¶
type SSHTransport struct {
// contains filtered or unexported fields
}
SSHTransport is a struct that represents an SSH connection to a remote machine.
func NewSSHTransport ¶
func NewSSHTransport(cfg SSHTransportConfig) (*SSHTransport, error)
NewSSHTransport creates a new SSHTransport with the given configuration. It immediatelly establishes a connection to the remote machine. Use Close to close the connection.
func (*SSHTransport) Close ¶
func (t *SSHTransport) Close(ctx context.Context) error
Close closes the SSH connection. Additionally, it deletes the temporary files created during the session.
func (*SSHTransport) Execute ¶
func (t *SSHTransport) Execute(ctx context.Context, cmd Command, opts ...ExecuteOpt) error
Execute performs a command remotely via SSH session with standard input, output, and error configured as specified in the SSHTransportConfig. The command is executed in the remote machine. An optional arguments can be provided to override Stdout and Stderr config.
type SSHTransportConfig ¶
type SSHTransportConfig struct {
// Host is the hostname or IP address of the remote machine including optional port (e.g. "example.com:22").
Host string
// Username is the username to use for authentication.
Username string
// Password is the password to use for authentication. It is optional if private keys are provided.
Password string
// PrivateKeys is a list of private keys to use for authentication. If not provided, the default private keys will be used.
PrivateKeys []*bytes.Buffer
// KnownHosts is the path to the known hosts file. If not provided, the default known hosts file will be used.
KnownHosts string
// Timeout is the maximum amount of time a dial will wait for a connect to complete. The default is 10 seconds.
Timeout time.Duration
// Stdin is the standard input for the SSH session. The default is os.Stdin.
Stdin io.Reader
// Stdout is the standard output for the SSH session. The default is os.Stdout.
Stdout io.Writer
// Stderr is the standard error for the SSH session. The default is os.Stderr.
Stderr io.Writer
}
SSHTransportConfig is a configuration struct for creating a new SSHTransport.
type StringCommand ¶
type StringCommand string
StringCommand is a command that is just a string. Useful for testing purposes. The caller is responsible for escaping the command properly.
func (StringCommand) Build ¶
func (c StringCommand) Build() string