From 18e94f8cb861bc9c1f8bd8d2bc3f5ce19e1f6f28 Mon Sep 17 00:00:00 2001 From: John Long Date: Thu, 19 Oct 2023 17:41:12 -0400 Subject: [PATCH] set opt to cleanup build containers --- internal/config/config.go | 4 ++-- internal/repo/build.go | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 977c464..953c7e7 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -113,11 +113,11 @@ func (cfg *Config) Setup() { log.Info("Fox needs a place to store the KubeFox Component images it will build, normally") log.Info("this is a remote container registry. However, if you only want to use KubeFox") log.Info("locally with Kind you can skip this step.") - kindOnly := utils.YesNoPrompt("Are you only using KubeFox locally?", false) + kindOnly := utils.YesNoPrompt("Are you only using KubeFox with local Kind cluster?", false) if kindOnly { cfg.ContainerRegistry.Address = LocalRegistry cfg.ContainerRegistry.Token = "" - cfg.Kind.ClusterName = utils.NamePrompt("Kind cluster", "kind", true) + cfg.Kind.ClusterName = utils.NamePrompt("Kind cluster name", "kind", true) cfg.Kind.AlwaysLoad = true cfg.done() return diff --git a/internal/repo/build.go b/internal/repo/build.go index 3f32e6d..49cbd9b 100644 --- a/internal/repo/build.go +++ b/internal/repo/build.go @@ -44,8 +44,9 @@ func (r *repo) BuildComp(compDirName string) string { gitCommit := r.GetCompCommit(compDirName) gitRef := r.GetRefName() regAuth := r.GetRegAuth() + localReg := strings.HasPrefix(r.cfg.ContainerRegistry.Address, config.LocalRegistry) - if !(r.cfg.Flags.ForceBuild || r.cfg.Flags.NoCache) { + if !(r.cfg.Flags.ForceBuild || r.cfg.Flags.NoCache || localReg) { if di, err := r.docker.DistributionInspect(context.Background(), img, regAuth); err != nil { log.Verbose("%s", err) } else { @@ -81,6 +82,7 @@ func (r *repo) BuildComp(compDirName string) string { buildResp, err := r.docker.ImageBuild(context.Background(), dfi, types.ImageBuildOptions{ Dockerfile: injectedDockerfile, NoCache: r.cfg.Flags.NoCache, + Remove: true, Tags: []string{img}, Labels: labels, BuildArgs: map[string]*string{ @@ -95,7 +97,6 @@ func (r *repo) BuildComp(compDirName string) string { } logResp(buildResp.Body) - localReg := strings.HasPrefix(r.cfg.ContainerRegistry.Address, config.LocalRegistry) if localReg { log.Verbose("Local registry is set, container image push will be skipped.") } @@ -146,7 +147,7 @@ func (r *repo) KindLoad(img string) { if out, err := cmd.CombinedOutput(); err != nil { log.Error("%s", strings.TrimSpace(string(out))) - log.Error("Error loading component image into Kind: %v", err) + log.Fatal("Error loading component image into Kind: %v", err) } else { log.Verbose("%s", strings.TrimSpace(string(out))) }