Build computes and inserts a new workspace build into the database. If authFunc is provided, it also performs authorization preflight checks.
( ctx context.Context, store database.Store, fileCache *files.Cache, authFunc func(action policy.Action, object rbac.Objecter) bool, auditBaggage audit.WorkspaceBuildBaggage, )
| 303 | // Build computes and inserts a new workspace build into the database. If authFunc is provided, it also performs |
| 304 | // authorization preflight checks. |
| 305 | func (b *Builder) Build( |
| 306 | ctx context.Context, |
| 307 | store database.Store, |
| 308 | fileCache *files.Cache, |
| 309 | authFunc func(action policy.Action, object rbac.Objecter) bool, |
| 310 | auditBaggage audit.WorkspaceBuildBaggage, |
| 311 | ) ( |
| 312 | *database.WorkspaceBuild, *database.ProvisionerJob, []database.GetEligibleProvisionerDaemonsByProvisionerJobIDsRow, error, |
| 313 | ) { |
| 314 | var err error |
| 315 | b.ctx, err = audit.BaggageToContext(ctx, auditBaggage) |
| 316 | if err != nil { |
| 317 | return nil, nil, nil, xerrors.Errorf("create audit baggage: %w", err) |
| 318 | } |
| 319 | |
| 320 | b.fileCache = files.NewCacheCloser(fileCache) |
| 321 | // Always close opened files during the build |
| 322 | defer b.fileCache.Close() |
| 323 | |
| 324 | // Run the build in a transaction with RepeatableRead isolation, and retries. |
| 325 | // RepeatableRead isolation ensures that we get a consistent view of the database while |
| 326 | // computing the new build. This simplifies the logic so that we do not need to worry if |
| 327 | // later reads are consistent with earlier ones. |
| 328 | var workspaceBuild *database.WorkspaceBuild |
| 329 | var provisionerJob *database.ProvisionerJob |
| 330 | var provisionerDaemons []database.GetEligibleProvisionerDaemonsByProvisionerJobIDsRow |
| 331 | err = database.ReadModifyUpdate(store, func(tx database.Store) error { |
| 332 | var err error |
| 333 | b.store = tx |
| 334 | workspaceBuild, provisionerJob, provisionerDaemons, err = b.buildTx(authFunc) |
| 335 | return err |
| 336 | }) |
| 337 | if err != nil { |
| 338 | b.recordBuildMetrics(provisionerJob, err) |
| 339 | return nil, nil, nil, xerrors.Errorf("build tx: %w", err) |
| 340 | } |
| 341 | b.recordBuildMetrics(provisionerJob, nil) |
| 342 | return workspaceBuild, provisionerJob, provisionerDaemons, nil |
| 343 | } |
| 344 | |
| 345 | // recordBuildMetrics records the workspace build enqueue metric if metrics are |
| 346 | // configured. It determines the appropriate build reason label, using "prebuild" |
nothing calls this directly
no test coverage detected