grim/convey

Add a .reviewboardrc file

2022-03-26, Gary Kramlich
8fea0c778f8e
Add a .reviewboardrc file
package podman
import (
"path/filepath"
"strings"
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/yaml"
)
type Build struct {
Annotations yaml.StringOrSlice `yaml:"annotations"`
Containerfile string `yaml:"containerfile"`
Context string `yaml:"context"`
Tags yaml.StringOrSlice `yaml:"tags"`
Target string `yaml:"target"`
}
func (b *Build) Execute(name string, logger *log.Entry, stageEnv environment.Environment, rt *runtime.Runtime) error {
env := stageEnv.Copy().Merge(rt.Environment)
ws, err := rt.Workspace()
if err != nil {
return err
}
context := filepath.Join(ws.Path(), env.Expand(b.Context))
if !strings.HasSuffix(context, string(filepath.Separator)) {
context += string(filepath.Separator)
}
log.Infof("resolved context: %q", context)
log.Infof("wspath: %q", ws.Path())
if !strings.HasPrefix(context, ws.Path()) {
return ErrContextOutsideOfWorkspace
}
generator := exec.NewGenerator(
"podman",
"build",
"--tag", env.Expand(b.Tags[0]),
"--file", env.Expand(b.Containerfile),
)
for _, annotation := range b.Annotations {
generator.Append("--annotation", annotation)
}
if b.Target != "" {
generator.Append("--target", b.Target)
}
generator.Append(context)
err = exec.Run(name, generator.Command(), rt.Timeout)
if err != nil {
return err
}
// if we were give more than one tag run a tag test to do the rest
if len(b.Tags) > 1 {
t := Tag{
Image: b.Tags[0],
Targets: b.Tags[1:],
}
return t.Execute(name, logger, stageEnv, rt)
}
return nil
}
func (b *Build) New() runtime.Task {
return &Build{}
}
func (b *Build) Valid() error {
if b.Containerfile == "" {
return ErrNoContainerfile
}
if len(b.Tags) == 0 {
return ErrNoTags
}
if b.Context == "" {
b.Context = "."
}
return nil
}
func (b *Build) Deprecated() error {
return nil
}