Skip to content

Commit aaec055

Browse files
daniel-hutaosteinliber
authored andcommitted
feat: new config format support
Signed-off-by: Daniel Hu <tao.hu@merico.dev>
1 parent 60cd686 commit aaec055

17 files changed

Lines changed: 159 additions & 1357 deletions

File tree

internal/pkg/configmanager/app.go

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@ package configmanager
33
import (
44
"fmt"
55

6-
"gopkg.in/yaml.v3"
7-
8-
"github.com/devstream-io/devstream/pkg/util/log"
9-
"github.com/devstream-io/devstream/pkg/util/mapz"
106
"github.com/devstream-io/devstream/pkg/util/scm"
117
)
128

139
const (
1410
repoScaffoldingPluginName = "repo-scaffolding"
1511
)
1612

17-
type rawApp struct {
13+
type app struct {
1814
Name string `yaml:"name" mapstructure:"name"`
1915
Spec map[string]any `yaml:"spec" mapstructure:"spec"`
2016
Repo *scm.SCMInfo `yaml:"repo" mapstructure:"repo"`
@@ -23,39 +19,8 @@ type rawApp struct {
2319
CDRawConfigs []pipelineRaw `yaml:"cd" mapstructure:"cd"`
2420
}
2521

26-
// getToolsFromApp return app tools
27-
func getToolsFromApp(appStr string, globalVars map[string]any, templateMap map[string]string) (Tools, error) {
28-
//1. render appStr with globalVars
29-
appRenderStr, err := renderConfigWithVariables(appStr, globalVars)
30-
if err != nil {
31-
log.Debugf("configmanager/app %s render globalVars %+v failed", appRenderStr, globalVars)
32-
return nil, fmt.Errorf("app render globalVars failed: %w", err)
33-
}
34-
// 2. unmarshal rawApp config for render pipelineTemplate
35-
var rawData rawApp
36-
if err := yaml.Unmarshal([]byte(appRenderStr), &rawData); err != nil {
37-
return nil, fmt.Errorf("app parse yaml failed: %w", err)
38-
}
39-
rawData.setDefault()
40-
appVars := mapz.Merge(globalVars, rawData.Spec)
41-
// 3. generate app repo and tempalte repo from scmInfo
42-
repoScaffoldingTool, err := rawData.getRepoTemplateTool(appVars)
43-
if err != nil {
44-
return nil, fmt.Errorf("app[%s] get repo failed: %w", rawData.Name, err)
45-
}
46-
// 4. get ci/cd pipelineTemplates
47-
tools, err := rawData.generateCICDToolsFromAppConfig(templateMap, appVars)
48-
if err != nil {
49-
return nil, fmt.Errorf("app[%s] get pipeline tools failed: %w", rawData.Name, err)
50-
}
51-
if repoScaffoldingTool != nil {
52-
tools = append(tools, *repoScaffoldingTool)
53-
}
54-
return tools, nil
55-
}
56-
5722
// getAppPipelineTool generate ci/cd tools from app config
58-
func (a *rawApp) generateCICDToolsFromAppConfig(templateMap map[string]string, appVars map[string]any) (Tools, error) {
23+
func (a *app) generateCICDToolsFromAppConfig(templateMap map[string]string, appVars map[string]any) (Tools, error) {
5924
allPipelineRaw := append(a.CIRawConfigs, a.CDRawConfigs...)
6025
var tools Tools
6126
for _, p := range allPipelineRaw {
@@ -74,7 +39,7 @@ func (a *rawApp) generateCICDToolsFromAppConfig(templateMap map[string]string, a
7439
}
7540

7641
// getRepoTemplateTool will use repo-scaffolding plugin for app
77-
func (a *rawApp) getRepoTemplateTool(appVars map[string]any) (*Tool, error) {
42+
func (a *app) getRepoTemplateTool(appVars map[string]any) (*Tool, error) {
7843
if a.Repo == nil {
7944
return nil, fmt.Errorf("app.repo field can't be empty")
8045
}
@@ -99,14 +64,14 @@ func (a *rawApp) getRepoTemplateTool(appVars map[string]any) (*Tool, error) {
9964
}
10065

10166
// setDefault will set repoName to appName if repo.name field is empty
102-
func (a *rawApp) setDefault() {
67+
func (a *app) setDefault() {
10368
if a.Repo != nil && a.Repo.Name == "" {
10469
a.Repo.Name = a.Name
10570
}
10671
}
10772

10873
// since all plugin depends on code is deployed, get dependsOn for repoTemplate
109-
func (a *rawApp) getRepoTemplateDependants() []string {
74+
func (a *app) getRepoTemplateDependants() []string {
11075
var dependsOn []string
11176
// if a.RepoTemplate is configured, pipeline need to wait reposcaffolding finished
11277
if a.RepoTemplate != nil {

internal/pkg/configmanager/app_test.go

Lines changed: 0 additions & 288 deletions
This file was deleted.

0 commit comments

Comments
 (0)