2024-08-23 03:11:00 +00:00
|
|
|
package driver
|
2024-08-01 22:43:18 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ContainerDriver interface {
|
|
|
|
Pull(string) error
|
2024-09-02 14:14:59 +00:00
|
|
|
Start(string, string, string) error
|
2024-08-01 22:43:18 +00:00
|
|
|
Stop(string) error
|
2024-08-21 17:46:57 +00:00
|
|
|
Exec(containerId string, command string, options CommandOptions) CommandResult
|
2024-08-02 20:38:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2024-08-01 22:43:18 +00:00
|
|
|
}
|
|
|
|
|
2024-08-21 17:46:57 +00:00
|
|
|
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
|
2024-08-23 03:38:32 +00:00
|
|
|
// Shell to use when running the command.
|
|
|
|
Shell string
|
2024-08-21 17:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewCommandOptions() CommandOptions {
|
|
|
|
return CommandOptions{
|
2024-08-23 03:38:32 +00:00
|
|
|
Cwd: ".",
|
|
|
|
Shell: "bash",
|
|
|
|
Env: map[string]string{},
|
2024-08-21 17:46:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-01 22:43:18 +00:00
|
|
|
func NewDriver(driverType string) (ContainerDriver, error) {
|
|
|
|
if driverType == "podman" {
|
|
|
|
return &PodmanDriver{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, errors.New("Unrecognized driver type.")
|
|
|
|
}
|