grim/convey

Update convey.yml
redux
2021-10-11, Gary Kramlich
1f9aa32a4055
Update convey.yml

* re-enable the unit testing
* move everyting to the podman tasks
package podman
import (
"github.com/kballard/go-shellquote"
log "github.com/sirupsen/logrus"
"keep.imfreedom.org/grim/convey/environment"
"keep.imfreedom.org/grim/convey/exec"
"keep.imfreedom.org/grim/convey/runtime"
"keep.imfreedom.org/grim/convey/tasks"
"keep.imfreedom.org/grim/convey/yaml"
)
type Run struct {
Annotations yaml.StringOrSlice `yaml:"annotations"`
Command string `yaml:"command"`
Entrypoint string `yaml:"entrypoint"`
Environment yaml.StringOrSlice `yaml:"environment"`
Hostname string `yaml:"hostname"`
Image string `yaml:"image"`
User string `yaml:"user"`
Workdir string `yaml:"workdir"`
Workspace string `yaml:"workspace"`
commandv []string
}
func (r *Run) Execute(name string, logger *log.Entry, stageEnv environment.Environment, rt *runtime.Runtime) error {
// Create a new environment based on the stage's environment. Then merge
// the task's environment overriding anything from the stage. Finally merge
// the runtime enviroment which holds the environment from the command line.
env := stageEnv.Copy().MergeSlice(r.Environment).Merge(rt.Environment)
// Figure out where we're mounting the workspace. This should be done
// before workdir is expanded as work is typically set to CONVEY_WORKSPACE.
workspace := env.Expand(r.Workspace)
if workspace == "" {
workspace = "/workspace"
}
hostWorkspace, err := rt.Workspace()
if err != nil {
return err
}
env["CONVEY_WORKSPACE"] = workspace
generator := exec.NewGenerator(
"podman",
"run",
"--rm",
"--volume", hostWorkspace.Path()+":"+workspace,
)
// Add any annotations that the user specified.
for _, annotation := range r.Annotations {
generator.Append("--annotation", annotation)
}
// Add the entrypoint is one was specified.
if r.Entrypoint != "" {
generator.Append("--entrypoint", env.Expand(r.Entrypoint))
}
// Now add all the given environment variables
for _, name := range env.All() {
generator.Append("--env", name)
}
// Add the hostname if one was specified.
if r.Hostname != "" {
generator.Append("--hostname", env.Expand(r.Hostname))
}
// Add the user if one was specified.
if r.User != "" {
generator.Append("--user", env.Expand(r.User))
}
// Add the workdir if one was specified.
if r.Workdir != "" {
generator.Append("--workdir", env.Expand(r.Workdir))
}
// Finally append the image name.
generator.Append(env.Expand(r.Image))
if len(r.commandv) > 0 {
generator.Appendv(env.Expandv(r.commandv))
}
return exec.Run(name, generator.Command(), rt.Timeout)
}
func (r *Run) New() tasks.Task {
return &Run{}
}
func (r *Run) Valid() error {
if r.Image == "" {
return ErrNoImage
}
if r.Command != "" {
cmdv, err := shellquote.Split(r.Command)
if err != nil {
return err
}
r.commandv = cmdv
}
return nil
}
func (r *Run) Deprecated() error {
return nil
}