39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
log "github.com/sirupsen/logrus"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
// runOciCli execute binary formatted like this `{ociCli} {ociVerb} {ociOpt} {registry:port/image} {args}`
|
|
func runOciCli(ociCli string, ociVerb string, ociCliOpt string, registry Registry, image Image, args ...string) (string, error) {
|
|
if reg := registry.String(); reg != "" {
|
|
args = append([]string{fmt.Sprintf("%s/%s", registry.String(), image.String())}, args...)
|
|
} else {
|
|
args = append([]string{image.String()}, args...)
|
|
}
|
|
|
|
if ociCliOpt != "" {
|
|
args = append(strings.Split(ociCliOpt, " "), args...)
|
|
}
|
|
|
|
return runCli(ociCli, ociVerb, args...)
|
|
}
|
|
|
|
// runCli execute binary formatted like this `{bin} {verb} {args}`
|
|
func runCli(binary string, verb string, args ...string) (string, error) {
|
|
if verb != "" {
|
|
args = append(strings.Split(verb, " "), args...)
|
|
}
|
|
|
|
log.Debugf(" $ %s %s\n", binary, strings.Join(args, " "))
|
|
out, err := exec.Command(binary, args...).Output()
|
|
if err != nil {
|
|
log.Warnf("Executing binary with argument : `%s %s %s` failed\n", binary, verb, strings.Join(args, " "))
|
|
return "", err
|
|
}
|
|
return string(out), nil
|
|
}
|