60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
// Podman driver
|
|
//
|
|
// Abstracts interactions with Podman commands via the ContainerDriver interface.
|
|
package runner
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
)
|
|
|
|
type PodmanDriver struct{}
|
|
|
|
func (d PodmanDriver) Pull(uri string) error {
|
|
cmd := exec.Command("podman", "pull", uri)
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (d PodmanDriver) Start(uri string, containerName string) error {
|
|
cmd := exec.Command("podman", "run", "-td", "--name", containerName, uri)
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (d PodmanDriver) Stop(containerName string) error {
|
|
cmd := exec.Command("podman", "rm", "-f", containerName)
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (d PodmanDriver) Exec(containerId string, command string) CommandResult {
|
|
cmd := exec.Command("podman", "exec", containerId, "bash", "-c", command)
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
|
|
err := cmd.Run()
|
|
|
|
return CommandResult{
|
|
Error: err,
|
|
ExitCode: cmd.ProcessState.ExitCode(),
|
|
}
|
|
}
|