Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
9186ca1
feat(database): add support for pipelines
jbrockopp Jan 19, 2022
e9e05bd
chore: update copyright year to 2022
jbrockopp Jan 19, 2022
0a28d42
chore: cleanup comments and imports
jbrockopp Jan 19, 2022
1ab6afe
enhance(pipeline): add fields for secrets
jbrockopp Jan 21, 2022
57e5162
Merge branch 'master' of github.com:go-vela/server
jbrockopp Feb 23, 2022
5366bb3
chore: update go-vela/types dependency
jbrockopp Feb 25, 2022
e07e7bc
enhance(pipeline): add field for commit
jbrockopp Mar 7, 2022
66d626f
Merge branch 'master' into feature/database/pipeline
jbrockopp Mar 7, 2022
b6b840c
Merge branch 'master' of github.com:go-vela/server
jbrockopp Mar 10, 2022
858c818
Merge branch 'master' of github.com:go-vela/server
jbrockopp Mar 16, 2022
6f314e4
Merge branch 'master' into feature/database/pipeline
jbrockopp Mar 16, 2022
7b688cb
Merge branch 'feature/database/pipeline' of github.com:go-vela/server…
jbrockopp Mar 16, 2022
9a14f8c
chore: fix tests
jbrockopp Mar 17, 2022
c2fed8f
feat: add pipeline engine opts
jbrockopp Mar 17, 2022
b4589f8
refactor: structure for creating pipeline engine
jbrockopp Mar 17, 2022
35b52b6
chore: finalize pipeline engine setup
jbrockopp Mar 17, 2022
4a8f272
chore: clean up pipeline database engine
jbrockopp Mar 17, 2022
1195c76
chore: clean up imports
jbrockopp Mar 17, 2022
740e5e0
Merge branch 'feature/database/pipeline' of github.com:go-vela/server…
jbrockopp Mar 18, 2022
0ec78e3
feat(compiler): add support for pipelines
jbrockopp Mar 18, 2022
c763621
feat(api): add support for pipelines
jbrockopp Mar 18, 2022
3958114
Merge branch 'master' into feature/api/pipeline
jbrockopp Mar 18, 2022
4b5bc54
Merge branch 'master' into feature/api/pipeline
jbrockopp Mar 20, 2022
d6fe4f7
Merge branch 'feature/api/pipeline' of github.com:go-vela/server into…
jbrockopp Mar 20, 2022
29888a6
chore: address linter feedback
jbrockopp Mar 20, 2022
ceddb11
Merge branch 'master' of github.com:go-vela/server
jbrockopp Mar 28, 2022
b90e443
Merge branch 'master' into feature/api/pipeline
jbrockopp Mar 31, 2022
cb1ac35
Merge branch 'master' into feature/api/pipeline
jbrockopp Apr 11, 2022
331b2a2
Merge branch 'master' of github.com:go-vela/server
jbrockopp Apr 11, 2022
dc6c732
Merge branch 'feature/api/pipeline' of github.com:go-vela/server into…
jbrockopp Apr 11, 2022
9ee0017
chore: remove unused code
jbrockopp Apr 11, 2022
a6997a8
chore: update go-vela/types dependency
jbrockopp Apr 11, 2022
133439e
Merge branch 'master' into feature/api/pipeline
jbrockopp Apr 12, 2022
45f7fd1
Merge branch 'feature/api/pipeline' of github.com:go-vela/server into…
jbrockopp Apr 12, 2022
9c1825e
enhance: use pipeline commit instead of number
jbrockopp Apr 13, 2022
8a66a15
Merge branch 'master' into feature/api/pipeline
jbrockopp Apr 18, 2022
f858ecd
Merge branch 'feature/api/pipeline' of github.com:go-vela/server into…
jbrockopp Apr 18, 2022
be6c877
chore: remove pipeline number
jbrockopp Apr 18, 2022
c4ec5fb
Merge branches 'master' and 'master' of github.com:go-vela/server
jbrockopp Apr 18, 2022
b3423d4
chore: remove number field from pipelines
jbrockopp Apr 18, 2022
edbc030
Merge branch 'chore/pipeline/number' of github.com:go-vela/server int…
jbrockopp Apr 18, 2022
f8eb267
Merge branch 'master' into feature/api/pipeline
jbrockopp Apr 19, 2022
bfbc27f
Merge branch 'feature/api/pipeline' of github.com:go-vela/server into…
jbrockopp Apr 19, 2022
782c15f
Merge branch 'master' into feature/api/pipeline
jbrockopp Apr 20, 2022
0ef35b5
Merge branch 'feature/api/pipeline' of github.com:go-vela/server into…
jbrockopp Apr 20, 2022
a794666
fix: merge with master
jbrockopp Apr 20, 2022
159df8e
chore: clean go dependencies
jbrockopp Apr 20, 2022
760ed7c
fix(pipeline): update mocks for API changes
jbrockopp Apr 21, 2022
d973677
Merge branch 'master' into feature/api/pipeline
jbrockopp Apr 21, 2022
33d0d03
Merge branch 'master' into feature/api/pipeline
jbrockopp Apr 22, 2022
1183bd4
Merge branch 'feature/api/pipeline' of github.com:go-vela/server into…
jbrockopp Apr 22, 2022
2e147f7
chore: fix go formatting
jbrockopp Apr 22, 2022
256369e
chore: address linter feedback
jbrockopp Apr 22, 2022
c17860d
fix: mock changes for pipelines
jbrockopp Apr 22, 2022
7050468
chore: address review feedback
jbrockopp Apr 26, 2022
da3142e
enhance: add permissions to pipeline endpoints
jbrockopp Apr 26, 2022
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
Prev Previous commit
Next Next commit
feat(compiler): add support for pipelines
  • Loading branch information
jbrockopp committed Mar 18, 2022
commit 0ec78e360e83a14d18f20ad86a3ee666e967bcf1
6 changes: 3 additions & 3 deletions compiler/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ type Engine interface {
// Compile defines a function that produces an executable
// representation of a pipeline from an object. This calls
// Parse internally to convert the object to a yaml configuration.
Compile(interface{}) (*pipeline.Build, error)
Compile(interface{}) (*pipeline.Build, *library.Pipeline, error)

// CompileLite defines a function that produces an light executable
// representation of a pipeline from an object. This calls
// Parse internally to convert the object to a yaml configuration.
CompileLite(interface{}, bool, bool, []string) (*yaml.Build, error)
CompileLite(interface{}, bool, bool, []string) (*yaml.Build, *library.Pipeline, error)

// Duplicate defines a function that
// creates a clone of the Engine.
Duplicate() Engine

// Parse defines a function that converts
// an object to a yaml configuration.
Parse(interface{}, string, map[string]interface{}) (*yaml.Build, error)
Parse(interface{}, string, map[string]interface{}) (*yaml.Build, []byte, error)

// ParseRaw defines a function that converts
// an object to a string.
Expand Down
118 changes: 69 additions & 49 deletions compiler/native/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,21 @@ type ModifyResponse struct {
}

// Compile produces an executable pipeline from a yaml configuration.
func (c *client) Compile(v interface{}) (*pipeline.Build, error) {
p, err := c.Parse(v, c.repo.GetPipelineType(), map[string]interface{}{})
func (c *client) Compile(v interface{}) (*pipeline.Build, *library.Pipeline, error) {
p, data, err := c.Parse(v, c.repo.GetPipelineType(), map[string]interface{}{})
if err != nil {
return nil, err
return nil, nil, err
}

// create the library pipeline object from the yaml configuration
_pipeline := p.ToPipelineLibrary()
_pipeline.SetData(data)
_pipeline.SetType(c.repo.GetPipelineType())

// validate the yaml configuration
err = c.Validate(p)
if err != nil {
return nil, err
return nil, _pipeline, err
}

// create map of templates for easy lookup
Expand All @@ -71,42 +76,47 @@ func (c *client) Compile(v interface{}) (*pipeline.Build, error) {
case p.Metadata.RenderInline:
newPipeline, err := c.compileInline(p, nil)
if err != nil {
return nil, err
return nil, _pipeline, err
}
// validate the yaml configuration
err = c.Validate(newPipeline)
if err != nil {
return nil, err
return nil, _pipeline, err
}

if len(newPipeline.Stages) > 0 {
return c.compileStages(newPipeline, map[string]*yaml.Template{}, r)
return c.compileStages(newPipeline, _pipeline, map[string]*yaml.Template{}, r)
}

return c.compileSteps(newPipeline, map[string]*yaml.Template{}, r)
return c.compileSteps(newPipeline, _pipeline, map[string]*yaml.Template{}, r)
case len(p.Stages) > 0:
return c.compileStages(p, templates, r)
return c.compileStages(p, _pipeline, templates, r)
default:
return c.compileSteps(p, templates, r)
return c.compileSteps(p, _pipeline, templates, r)
}
}

// CompileLite produces a partial of an executable pipeline from a yaml configuration.
func (c *client) CompileLite(v interface{}, template, substitute bool, localTemplates []string) (*yaml.Build, error) {
p, err := c.Parse(v, c.repo.GetPipelineType(), map[string]interface{}{})
func (c *client) CompileLite(v interface{}, template, substitute bool, localTemplates []string) (*yaml.Build, *library.Pipeline, error) {
p, data, err := c.Parse(v, c.repo.GetPipelineType(), map[string]interface{}{})
if err != nil {
return nil, err
return nil, nil, err
}

// create the library pipeline object from the yaml configuration
_pipeline := p.ToPipelineLibrary()
_pipeline.SetData(data)
_pipeline.SetType(c.repo.GetPipelineType())

if p.Metadata.RenderInline {
newPipeline, err := c.compileInline(p, localTemplates)
if err != nil {
return nil, err
return nil, _pipeline, err
}
// validate the yaml configuration
err = c.Validate(newPipeline)
if err != nil {
return nil, err
return nil, _pipeline, err
}

p = newPipeline
Expand All @@ -126,7 +136,7 @@ func (c *client) CompileLite(v interface{}, template, substitute bool, localTemp
// make sure the template was configured
_, ok := templates[parts[0]]
if !ok {
return nil, fmt.Errorf("template with name %s is not configured", parts[0])
return nil, _pipeline, fmt.Errorf("template with name %s is not configured", parts[0])
}

// override the source for the given template
Expand All @@ -139,28 +149,28 @@ func (c *client) CompileLite(v interface{}, template, substitute bool, localTemp
// inject the templates into the steps
p, err = c.ExpandStages(p, templates)
if err != nil {
return nil, err
return nil, _pipeline, err
}

if substitute {
// inject the substituted environment variables into the steps
p.Stages, err = c.SubstituteStages(p.Stages)
if err != nil {
return nil, err
return nil, _pipeline, err
}
}
case len(p.Steps) > 0:
// inject the templates into the steps
p, err = c.ExpandSteps(p, templates)
if err != nil {
return nil, err
return nil, _pipeline, err
}

if substitute {
// inject the substituted environment variables into the steps
p.Steps, err = c.SubstituteSteps(p.Steps)
if err != nil {
return nil, err
return nil, _pipeline, err
}
}
}
Expand All @@ -169,10 +179,10 @@ func (c *client) CompileLite(v interface{}, template, substitute bool, localTemp
// validate the yaml configuration
err = c.Validate(p)
if err != nil {
return nil, err
return nil, _pipeline, err
}

return p, nil
return p, _pipeline, nil
}

// compileInline parses and expands out inline pipelines.
Expand Down Expand Up @@ -208,7 +218,7 @@ func (c *client) compileInline(p *yaml.Build, localTemplates []string) (*yaml.Bu
format = constants.PipelineTypeGo
}

parsed, err := c.Parse(bytes, format, template.Variables)
parsed, _, err := c.Parse(bytes, format, template.Variables)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -270,42 +280,42 @@ func (c *client) compileInline(p *yaml.Build, localTemplates []string) (*yaml.Bu
// compileSteps executes the workflow for converting a YAML pipeline into an executable struct.
//
// nolint:dupl,lll // linter thinks the steps and stages workflows are identical
func (c *client) compileSteps(p *yaml.Build, tmpls map[string]*yaml.Template, r *pipeline.RuleData) (*pipeline.Build, error) {
func (c *client) compileSteps(p *yaml.Build, _pipeline *library.Pipeline, tmpls map[string]*yaml.Template, r *pipeline.RuleData) (*pipeline.Build, *library.Pipeline, error) {
var err error

// check if the pipeline disabled the clone
if p.Metadata.Clone == nil || *p.Metadata.Clone {
// inject the clone step
p, err = c.CloneStep(p)
if err != nil {
return nil, err
return nil, _pipeline, err
}
}

// inject the init step
p, err = c.InitStep(p)
if err != nil {
return nil, err
return nil, _pipeline, err
}

// inject the templates into the steps
p, err = c.ExpandSteps(p, tmpls)
if err != nil {
return nil, err
return nil, _pipeline, err
}

if c.ModificationService.Endpoint != "" {
// send config to external endpoint for modification
p, err = c.modifyConfig(p, c.build, c.repo)
if err != nil {
return nil, err
return nil, _pipeline, err
}
}

// validate the yaml configuration
err = c.Validate(p)
if err != nil {
return nil, err
return nil, _pipeline, err
}

// Create some default global environment inject vars
Expand All @@ -328,76 +338,81 @@ func (c *client) compileSteps(p *yaml.Build, tmpls map[string]*yaml.Template, r
// inject the environment variables into the services
p.Services, err = c.EnvironmentServices(p.Services, envGlobalServices)
if err != nil {
return nil, err
return nil, _pipeline, err
}

// inject the environment variables into the secrets
p.Secrets, err = c.EnvironmentSecrets(p.Secrets, envGlobalSecrets)
if err != nil {
return nil, err
return nil, _pipeline, err
}

// inject the environment variables into the steps
p.Steps, err = c.EnvironmentSteps(p.Steps, envGlobalSteps)
if err != nil {
return nil, err
return nil, _pipeline, err
}

// inject the substituted environment variables into the steps
p.Steps, err = c.SubstituteSteps(p.Steps)
if err != nil {
return nil, err
return nil, _pipeline, err
}

// inject the scripts into the steps
p.Steps, err = c.ScriptSteps(p.Steps)
if err != nil {
return nil, err
return nil, _pipeline, err
}

// create executable representation
build, err := c.TransformSteps(r, p)
if err != nil {
return nil, _pipeline, err
}

// return executable representation
return c.TransformSteps(r, p)
return build, _pipeline, nil
}

// compileStages executes the workflow for converting a YAML pipeline into an executable struct.
//
// nolint:dupl,lll // linter thinks the steps and stages workflows are identical
func (c *client) compileStages(p *yaml.Build, tmpls map[string]*yaml.Template, r *pipeline.RuleData) (*pipeline.Build, error) {
func (c *client) compileStages(p *yaml.Build, _pipeline *library.Pipeline, tmpls map[string]*yaml.Template, r *pipeline.RuleData) (*pipeline.Build, *library.Pipeline, error) {
var err error

// check if the pipeline disabled the clone
if p.Metadata.Clone == nil || *p.Metadata.Clone {
// inject the clone stage
p, err = c.CloneStage(p)
if err != nil {
return nil, err
return nil, _pipeline, err
}
}

// inject the init stage
p, err = c.InitStage(p)
if err != nil {
return nil, err
return nil, _pipeline, err
}

// inject the templates into the stages
p, err = c.ExpandStages(p, tmpls)
if err != nil {
return nil, err
return nil, _pipeline, err
}

if c.ModificationService.Endpoint != "" {
// send config to external endpoint for modification
p, err = c.modifyConfig(p, c.build, c.repo)
if err != nil {
return nil, err
return nil, _pipeline, err
}
}

// validate the yaml configuration
err = c.Validate(p)
if err != nil {
return nil, err
return nil, _pipeline, err
}

// Create some default global environment inject vars
Expand All @@ -420,35 +435,40 @@ func (c *client) compileStages(p *yaml.Build, tmpls map[string]*yaml.Template, r
// inject the environment variables into the services
p.Services, err = c.EnvironmentServices(p.Services, envGlobalServices)
if err != nil {
return nil, err
return nil, _pipeline, err
}

// inject the environment variables into the secrets
p.Secrets, err = c.EnvironmentSecrets(p.Secrets, envGlobalSecrets)
if err != nil {
return nil, err
return nil, _pipeline, err
}

// inject the environment variables into the stages
p.Stages, err = c.EnvironmentStages(p.Stages, envGlobalSteps)
if err != nil {
return nil, err
return nil, _pipeline, err
}

// inject the substituted environment variables into the stages
p.Stages, err = c.SubstituteStages(p.Stages)
if err != nil {
return nil, err
return nil, _pipeline, err
}

// inject the scripts into the stages
p.Stages, err = c.ScriptStages(p.Stages)
if err != nil {
return nil, err
return nil, _pipeline, err
}

// create executable representation
build, err := c.TransformStages(r, p)
if err != nil {
return nil, _pipeline, err
}

// return executable representation
return c.TransformStages(r, p)
return build, _pipeline, nil
}

// errorHandler ensures the error contains the number of request attempts.
Expand Down
Loading