diff --git a/internal/commands/root/root.go b/internal/commands/root/root.go index 9f898ec..c360dbd 100644 --- a/internal/commands/root/root.go +++ b/internal/commands/root/root.go @@ -112,7 +112,7 @@ func NewCmd(dockerCli command.Cli, isPlugin bool) *cobra.Command { return nil } - action = selectAction(action, lc.Images[src], rk.Config.Default) + action = selectAction(action, src, rk.Config.Default) if list || action == "" { if tui.IsATTY(dockerCli.In().FD()) && len(rk.Config.Actions) > 0 { @@ -176,7 +176,7 @@ func getValuesLocal(src, action string) map[string]string { localOpts := make(map[string]string) lc := runkit.GetLocalConfig() - img, ok := lc.Images[src] + img, ok := lc.Image(src) if !ok { return localOpts } @@ -235,12 +235,12 @@ func run(ctx context.Context, out io.Writer, src string, rk *runkit.RunKit, acti return runnable.Run(ctx) } -func selectAction(action string, conf runkit.ConfigImage, defaultAction string) string { +func selectAction(action, src, defaultAction string) string { if action != "" { return action } - if conf.Default != "" { + if conf, ok := runkit.GetLocalConfig().Image(src); ok && conf.Default != "" { return conf.Default } diff --git a/runkit/config.go b/runkit/config.go index 191dc59..57ccffa 100644 --- a/runkit/config.go +++ b/runkit/config.go @@ -8,6 +8,7 @@ import ( "path/filepath" "sync" + "github.com/google/go-containerregistry/pkg/name" "gopkg.in/yaml.v2" ) @@ -20,7 +21,7 @@ var ( readOnce = sync.Once{} ) -func GetLocalConfig() LocalConfig { +func GetLocalConfig() *LocalConfig { readOnce.Do(func() { lc, err := getLocalConfig() if err != nil { @@ -29,7 +30,7 @@ func GetLocalConfig() LocalConfig { } localConfig = lc }) - return localConfig + return &localConfig } func getLocalConfig() (LocalConfig, error) { @@ -118,3 +119,23 @@ func read(filePath string) (LocalConfig, error) { return config, nil } + +func (lc *LocalConfig) Image(src string) (*ConfigImage, bool) { + ref, err := name.ParseReference(src) + if err != nil { + return nil, false + } + refName := ref.Name() + + for imgName, img := range lc.Images { + imgRef, err := name.ParseReference(imgName) + if err != nil { + continue + } + if imgRef.Name() == refName { + return &img, true + } + } + + return nil, false +}