grim/convey

Port from logrus to log/slog
default tip
4 months ago, Elliott Sales de Andrade
c588f9b3f559
Port from logrus to log/slog

This doesn't really take much advantage of structured logging beyond what is already done (`id` and `idColor`), and consequently the log handler does not try to do any handling of anything more than that (i.e., grouping, or arbitrary attributes beyond those defined).

One should maybe have a `Context` available to pass in, but there isn't one, and anyway, the log handler doesn't use it, so I've passed in a `TODO` instead.

Everything else is just normal import/rename changes.

Testing Done:
Ran `go run . run`

Reviewed at https://reviews.imfreedom.org/r/2871/
package podman
import (
"fmt"
"log/slog"
"path/filepath"
"strings"
"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 *slog.Logger, 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)
}
slog.Info(fmt.Sprintf("resolved context: %q", context))
slog.Info(fmt.Sprintf("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
}