Skip to content

Commit

Permalink
Merge branch 'main' into chore/gitignore-vscode-template
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed May 19, 2023
2 parents d2a7e58 + ca21175 commit fa0c3fb
Show file tree
Hide file tree
Showing 10 changed files with 682 additions and 607 deletions.
56 changes: 56 additions & 0 deletions api/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,62 @@ func planBuild(database database.Interface, p *pipeline.Build, b *library.Build,
return nil
}

// planServices is a helper function to plan all services
// in the build for execution. This creates the services
// for the build in the configured backend.
func planServices(database database.Interface, p *pipeline.Build, b *library.Build) ([]*library.Service, error) {
// variable to store planned services
services := []*library.Service{}

// iterate through all pipeline services
for _, service := range p.Services {
// create the service object
s := new(library.Service)
s.SetBuildID(b.GetID())
s.SetRepoID(b.GetRepoID())
s.SetName(service.Name)
s.SetImage(service.Image)
s.SetNumber(service.Number)
s.SetStatus(constants.StatusPending)
s.SetCreated(time.Now().UTC().Unix())

// send API call to create the service
err := database.CreateService(s)
if err != nil {
return services, fmt.Errorf("unable to create service %s: %w", s.GetName(), err)
}

// send API call to capture the created service
s, err = database.GetServiceForBuild(b, s.GetNumber())
if err != nil {
return services, fmt.Errorf("unable to get service %s: %w", s.GetName(), err)
}

// populate environment variables from service library
//
// https://pkg.go.dev/github.com/go-vela/types/library#Service.Environment
err = service.MergeEnv(s.Environment())
if err != nil {
return services, err
}

// create the log object
l := new(library.Log)
l.SetServiceID(s.GetID())
l.SetBuildID(b.GetID())
l.SetRepoID(b.GetRepoID())
l.SetData([]byte{})

// send API call to create the service logs
err = database.CreateLog(l)
if err != nil {
return services, fmt.Errorf("unable to create service logs for service %s: %w", s.GetName(), err)
}
}

return services, nil
}

// cleanBuild is a helper function to kill the build
// without execution. This will kill all resources,
// like steps and services, for the build in the
Expand Down
Loading

0 comments on commit fa0c3fb

Please sign in to comment.