Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3ab841a
yeet
ecrupper Mar 22, 2023
a4eacdc
initial work
ecrupper Mar 22, 2023
5d61b68
remove unnecessary validation check
ecrupper Mar 22, 2023
b081082
adding some comments
ecrupper Mar 22, 2023
446a942
remove edits to inline testing
ecrupper Mar 22, 2023
73fb16e
Merge branch 'main' into feat/templateception
ecrupper Mar 23, 2023
2eba356
Merge branch 'main' into feat/templateception
ecrupper Mar 30, 2023
9b035c4
Merge branch 'main' into feat/templateception
ecrupper Apr 3, 2023
0b05339
Merge branch 'main' into feat/templateception
ecrupper Apr 5, 2023
132ff78
Merge branch 'main' into feat/templateception
cognifloyd Apr 10, 2023
67e635f
Merge branch 'main' into feat/templateception
ecrupper May 22, 2023
54da9db
fix typo
ecrupper May 22, 2023
7f90ed9
render inline init work
ecrupper May 22, 2023
6f73a4f
Merge branch 'main' into feat/templateception
ecrupper May 23, 2023
10938ac
support for render_inline
ecrupper May 23, 2023
6c68a78
Merge branch 'main' into feat/templateception
ecrupper May 23, 2023
f6f90fb
address feedback
ecrupper May 24, 2023
e40b5c7
Merge branch 'feat/templateception' of github.com:go-vela/server into…
ecrupper May 24, 2023
c5cd66a
validate template depth
ecrupper May 24, 2023
38a9fa4
added tests for compile inline
ecrupper May 25, 2023
7fea3ba
add test for error with called render_inline template in step
ecrupper May 25, 2023
cfc6c9b
drop vs code nonsense
ecrupper May 25, 2023
fb57519
add github.amrom.workers.devpiler flags to env example
ecrupper May 25, 2023
b712d33
Merge branch 'main' into feat/templateception
wass3rw3rk May 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/vela-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ func main() {
Usage: "modification retries, used by compiler, number of http requires that the modification http request will fail after",
Value: 5,
},
&cli.IntFlag{
EnvVars: []string{"VELA_MAX_TEMPLATE_DEPTH", "MAX_TEMPLATE_DEPTH"},
Name: "max-template-depth",
Usage: "max template depth, used by compiler, maximum number of templates that can be called in a template chain. Prevents circular depenendcies",
Value: 5,
},
&cli.DurationFlag{
EnvVars: []string{"VELA_WORKER_ACTIVE_INTERVAL", "WORKER_ACTIVE_INTERVAL"},
Name: "worker-active-interval",
Expand Down
2 changes: 1 addition & 1 deletion compiler/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type Engine interface {
ExpandStages(*yaml.Build, map[string]*yaml.Template) (*yaml.Build, error)
// ExpandSteps defines a function that injects the template
// for each templated step in a yaml configuration.
ExpandSteps(*yaml.Build, map[string]*yaml.Template) (*yaml.Build, error)
ExpandSteps(*yaml.Build, map[string]*yaml.Template, int) (*yaml.Build, error)

// Init Compiler Interface Functions

Expand Down
4 changes: 2 additions & 2 deletions compiler/native/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (c *client) CompileLite(v interface{}, template, substitute bool, localTemp
}
case len(p.Steps) > 0:
// inject the templates into the steps
p, err = c.ExpandSteps(p, templates)
p, err = c.ExpandSteps(p, templates, c.TemplateDepth)
if err != nil {
return nil, _pipeline, err
}
Expand Down Expand Up @@ -307,7 +307,7 @@ func (c *client) compileSteps(p *yaml.Build, _pipeline *library.Pipeline, tmpls
}

// inject the templates into the steps
p, err = c.ExpandSteps(p, tmpls)
p, err = c.ExpandSteps(p, tmpls, c.TemplateDepth)
if err != nil {
return nil, _pipeline, err
}
Expand Down
11 changes: 11 additions & 0 deletions compiler/native/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestNative_Compile_StagesPipeline(t *testing.T) {
// setup types
set := flag.NewFlagSet("test", 0)
set.String("clone-image", defaultCloneImage, "doc")
set.Int("max-template-depth", 5, "doc")
c := cli.NewContext(nil, set, nil)

m := &types.Metadata{
Expand Down Expand Up @@ -417,6 +418,7 @@ func TestNative_Compile_StepsPipeline(t *testing.T) {
// setup types
set := flag.NewFlagSet("test", 0)
set.String("clone-image", defaultCloneImage, "doc")
set.Int("max-template-depth", 5, "doc")
c := cli.NewContext(nil, set, nil)

m := &types.Metadata{
Expand Down Expand Up @@ -619,6 +621,7 @@ func TestNative_Compile_StagesPipelineTemplate(t *testing.T) {
set.String("github-url", s.URL, "doc")
set.String("github-token", "", "doc")
set.String("clone-image", defaultCloneImage, "doc")
set.Int("max-template-depth", 5, "doc")
c := cli.NewContext(nil, set, nil)

m := &types.Metadata{
Expand Down Expand Up @@ -883,6 +886,7 @@ func TestNative_Compile_StepsPipelineTemplate(t *testing.T) {
set.String("github-url", s.URL, "doc")
set.String("github-token", "", "doc")
set.String("clone-image", defaultCloneImage, "doc")
set.Int("max-template-depth", 5, "doc")
c := cli.NewContext(nil, set, nil)

m := &types.Metadata{
Expand Down Expand Up @@ -1112,6 +1116,7 @@ func TestNative_Compile_StepsPipelineTemplate_VelaFunction_TemplateName(t *testi
set.String("github-url", s.URL, "doc")
set.String("github-token", "", "doc")
set.String("clone-image", defaultCloneImage, "doc")
set.Int("max-template-depth", 5, "doc")
c := cli.NewContext(nil, set, nil)

m := &types.Metadata{
Expand Down Expand Up @@ -1231,6 +1236,7 @@ func TestNative_Compile_StepsPipelineTemplate_VelaFunction_TemplateName_Inline(t
set.String("github-url", s.URL, "doc")
set.String("github-token", "", "doc")
set.String("clone-image", defaultCloneImage, "doc")
set.Int("max-template-depth", 5, "doc")
c := cli.NewContext(nil, set, nil)

m := &types.Metadata{
Expand Down Expand Up @@ -1346,6 +1352,7 @@ func TestNative_Compile_InvalidType(t *testing.T) {
set.Bool("github-driver", true, "doc")
set.String("github-url", s.URL, "doc")
set.String("github-token", "", "doc")
set.Int("max-template-depth", 5, "doc")
c := cli.NewContext(nil, set, nil)

m := &types.Metadata{
Expand Down Expand Up @@ -1402,6 +1409,7 @@ func TestNative_Compile_Clone(t *testing.T) {
set.Bool("github-driver", true, "doc")
set.String("github-token", "", "doc")
set.String("clone-image", defaultCloneImage, "doc")
set.Int("max-template-depth", 5, "doc")
c := cli.NewContext(nil, set, nil)

m := &types.Metadata{
Expand Down Expand Up @@ -1592,6 +1600,7 @@ func TestNative_Compile_Pipeline_Type(t *testing.T) {
set.Bool("github-driver", true, "doc")
set.String("github-token", "", "doc")
set.String("clone-image", defaultCloneImage, "doc")
set.Int("max-template-depth", 5, "doc")
c := cli.NewContext(nil, set, nil)

m := &types.Metadata{
Expand Down Expand Up @@ -2161,6 +2170,7 @@ func Test_Compile_Inline(t *testing.T) {
set.String("github-url", s.URL, "doc")
set.String("github-token", "", "doc")
set.String("clone-image", defaultCloneImage, "doc")
set.Int("max-template-depth", 5, "doc")
c := cli.NewContext(nil, set, nil)

m := &types.Metadata{
Expand Down Expand Up @@ -2944,6 +2954,7 @@ func Test_CompileLite(t *testing.T) {
set.Bool("github-driver", true, "doc")
set.String("github-url", s.URL, "doc")
set.String("github-token", "", "doc")
set.Int("max-template-depth", 5, "doc")
c := cli.NewContext(nil, set, nil)

m := &types.Metadata{
Expand Down
19 changes: 17 additions & 2 deletions compiler/native/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (c *client) ExpandStages(s *yaml.Build, tmpls map[string]*yaml.Template) (*
// iterate through all stages
for _, stage := range s.Stages {
// inject the templates into the steps for the stage
p, err := c.ExpandSteps(&yaml.Build{Steps: stage.Steps, Secrets: s.Secrets, Services: s.Services, Environment: s.Environment}, tmpls)
p, err := c.ExpandSteps(&yaml.Build{Steps: stage.Steps, Secrets: s.Secrets, Services: s.Services, Environment: s.Environment}, tmpls, c.TemplateDepth)
if err != nil {
return nil, err
}
Expand All @@ -46,11 +46,18 @@ func (c *client) ExpandStages(s *yaml.Build, tmpls map[string]*yaml.Template) (*

// ExpandSteps injects the template for each
// templated step in a yaml configuration.
func (c *client) ExpandSteps(s *yaml.Build, tmpls map[string]*yaml.Template) (*yaml.Build, error) {
func (c *client) ExpandSteps(s *yaml.Build, tmpls map[string]*yaml.Template, depth int) (*yaml.Build, error) {
if len(tmpls) == 0 {
return s, nil
}

// if max template depth has been reached, return to avoid circular dependencies
if depth == 0 {
retErr := fmt.Errorf("max template depth of %d exceeded", c.TemplateDepth)

return s, retErr
}

steps := yaml.StepSlice{}
secrets := s.Secrets
services := s.Services
Expand Down Expand Up @@ -100,6 +107,14 @@ func (c *client) ExpandSteps(s *yaml.Build, tmpls map[string]*yaml.Template) (*y
return s, err
}

// if template references other templates, expand again
if len(tmplBuild.Templates) != 0 {
tmplBuild, err = c.ExpandSteps(tmplBuild, mapFromTemplates(tmplBuild.Templates), depth-1)
if err != nil {
return s, err
}
}

// loop over secrets within template
for _, secret := range tmplBuild.Secrets {
found := false
Expand Down
Loading