courgette/internal/driver/driver.go

48 lines
1.1 KiB
Go
Raw Permalink Normal View History

package driver
import (
"errors"
)
type ContainerDriver interface {
Pull(string) error
Start(string, string, string) error
Stop(string) error
Exec(containerId string, command string, options CommandOptions) CommandResult
}
// Represents the outcome of a command call made by the driver.
type CommandResult struct {
// Exit code of the underlying exec.Command call.
ExitCode int
// Error (or nil) returned by the attempt to run the command.
Error error
}
type CommandOptions struct {
// Directory to run the command from. Equivalent of cd-ing before running.
Cwd string
// Map of environment variables exposed in the environment the command runs in.
// Note: In the case of container drivers, these mappings are applied within the
// container.
Env map[string]string
// Shell to use when running the command.
Shell string
}
func NewCommandOptions() CommandOptions {
return CommandOptions{
Cwd: ".",
Shell: "bash",
Env: map[string]string{},
}
}
func NewDriver(driverType string) (ContainerDriver, error) {
if driverType == "podman" {
return &PodmanDriver{}, nil
}
return nil, errors.New("Unrecognized driver type.")
}