Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
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