github.com/helmwave/helmwave@v0.36.4-0.20240509190856-b35563eba4c6/pkg/plan/build.go (about) 1 package plan 2 3 import ( 4 "context" 5 6 log "github.com/sirupsen/logrus" 7 ) 8 9 type BuildOptions struct { //nolint:govet 10 Tags []string 11 Yml string 12 Templater string 13 MatchAll bool 14 GraphWidth int 15 } 16 17 // Build plan with yml and tags/matchALL options. 18 // 19 //nolint:cyclop,gocognit // TODO: reduce cyclomatic complexity 20 func (p *Plan) Build(ctx context.Context, o BuildOptions) (err error) { //nolint:funlen 21 p.templater = o.Templater 22 23 // Create Body 24 var body *planBody 25 body, err = NewBody(ctx, o.Yml, false) 26 if err != nil { 27 return 28 } 29 p.body = body 30 31 // Run hooks 32 err = p.body.Lifecycle.RunPreBuild(ctx) 33 if err != nil { 34 return 35 } 36 37 defer func() { 38 lifecycleErr := p.body.Lifecycle.RunPostBuild(ctx) 39 if lifecycleErr != nil { 40 log.Errorf("got an error from postbuild hooks: %v", lifecycleErr) 41 if err == nil { 42 err = lifecycleErr 43 } 44 } 45 }() 46 47 // Build Releases 48 log.Info("🔨 Building releases...") 49 p.body.Releases, err = p.buildReleases(o.Tags, o.MatchAll) 50 if err != nil { 51 return 52 } 53 54 // Build Values 55 log.Info("🔨 Building values...") 56 err = p.buildValues(ctx) 57 if err != nil { 58 return 59 } 60 61 // Build Repositories 62 log.Info("🔨 Building repositories...") 63 p.body.Repositories, err = p.buildRepositories() 64 if err != nil { 65 return 66 } 67 68 // Sync Repositories 69 err = SyncRepositories(ctx, p.body.Repositories) 70 if err != nil { 71 return 72 } 73 74 // Build Registries 75 log.Info("🔨 Building registries...") 76 p.body.Registries, err = p.buildRegistries() 77 if err != nil { 78 return 79 } 80 // Sync Registries 81 err = p.syncRegistries(ctx) 82 if err != nil { 83 return 84 } 85 86 // to build charts, we need repositories and registries first 87 log.Info("🔨 Building charts...") 88 err = p.buildCharts() 89 if err != nil { 90 return 91 } 92 93 // Validating plan after it was changed 94 err = p.body.Validate() 95 if err != nil { 96 return 97 } 98 99 // Build Manifest 100 log.Info("🔨 Building manifests...") 101 err = p.buildManifest(ctx) 102 if err != nil { 103 return 104 } 105 106 // Build graphs 107 if o.GraphWidth != 1 { 108 log.Info("🔨 Building graphs...") 109 p.graphMD = buildGraphMD(p.body.Releases) 110 log.Infof("show graph:\n%s", p.BuildGraphASCII(o.GraphWidth)) 111 } 112 113 return 114 }