Skip to content

Commit 16f9963

Browse files
authored
Refactor execution to be able to use runSteps in exec mode directly (#798)
1 parent 2fbc937 commit 16f9963

26 files changed

+387
-679
lines changed

CHANGELOG.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,27 @@ All notable changes to `src-cli` are documented in this file.
1313

1414
### Added
1515

16+
### Changed
17+
18+
### Fixed
19+
20+
### Removed
21+
22+
## 3.41.1
23+
24+
### Added
25+
1626
- Batch specs that mount paths now cache results. [sourcegraph/sourcegraph#37216](https://github.com/sourcegraph/sourcegraph/issues/37216)
1727
- `SRC_HEADERS="key:value\nkey2:value2"` is now supported for passing multiple headers when authenticating `src` with custom auth proxies. See [auth proxy configuration docs](AUTH_PROXY.md) for more information. [#796](https://github.com/sourcegraph/src-cli/pull/796)
1828

1929
### Changed
2030

31+
- Some internal changes to `src batch exec` mode for server-side execution.
32+
2133
### Fixed
2234

2335
- Handle SIGINT interrupt when reading from Stdin. [#794](https://github.com/sourcegraph/src-cli/pull/794)
2436

25-
### Removed
26-
2737
## 3.41.0
2838

2939
### Changed

cmd/src/batch_common.go

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,11 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp
275275
}()
276276

277277
svc := service.New(&service.Opts{
278-
AllowUnsupported: opts.flags.allowUnsupported,
279-
AllowIgnored: opts.flags.allowIgnored,
280-
Client: opts.client,
278+
Client: opts.client,
281279
})
282280

281+
imageCache := docker.NewImageCache()
282+
283283
if err := svc.DetermineFeatureFlags(ctx); err != nil {
284284
return err
285285
}
@@ -324,7 +324,10 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp
324324
if len(batchSpec.Steps) > 0 {
325325
ui.PreparingContainerImages()
326326
images, err := svc.EnsureDockerImages(
327-
ctx, batchSpec.Steps, parallelism,
327+
ctx,
328+
imageCache,
329+
batchSpec.Steps,
330+
parallelism,
328331
ui.PreparingContainerImagesProgress,
329332
)
330333
if err != nil {
@@ -336,7 +339,8 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp
336339
var typ workspace.CreatorType
337340
workspaceCreator, typ = workspace.NewCreator(ctx, opts.flags.workspace, opts.flags.cacheDir, opts.flags.tempDir, images)
338341
if typ == workspace.CreatorTypeVolume {
339-
_, err = svc.EnsureImage(ctx, workspace.DockerVolumeWorkspaceImage)
342+
// This creator type requires an additional image, so let's ensure it exists.
343+
_, err = imageCache.Ensure(ctx, workspace.DockerVolumeWorkspaceImage)
340344
if err != nil {
341345
return err
342346
}
@@ -345,7 +349,7 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp
345349
}
346350

347351
ui.ResolvingRepositories()
348-
repos, err := svc.ResolveRepositories(ctx, batchSpec)
352+
repos, err := svc.ResolveRepositories(ctx, batchSpec, opts.flags.allowUnsupported, opts.flags.allowIgnored)
349353
if err != nil {
350354
if repoSet, ok := err.(batches.UnsupportedRepoSet); ok {
351355
ui.ResolvingRepositoriesDone(repos, repoSet, nil)
@@ -366,19 +370,25 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp
366370
ui.DeterminingWorkspacesSuccess(len(workspaces))
367371

368372
archiveRegistry := repozip.NewArchiveRegistry(opts.client, opts.flags.cacheDir, opts.flags.cleanArchives)
369-
370-
// EXECUTION OF TASKS
371-
coord := svc.NewCoordinator(
372-
archiveRegistry,
373-
log.NewDiskManager(opts.flags.tempDir, opts.flags.keepLogs),
373+
logManager := log.NewDiskManager(opts.flags.tempDir, opts.flags.keepLogs)
374+
coord := executor.NewCoordinator(
374375
executor.NewCoordinatorOpts{
375-
Creator: workspaceCreator,
376-
Cache: executor.NewDiskCache(opts.flags.cacheDir),
377-
Parallelism: parallelism,
378-
Timeout: opts.flags.timeout,
379-
TempDir: opts.flags.tempDir,
380-
GlobalEnv: os.Environ(),
381-
IsRemote: false,
376+
ExecOpts: executor.NewExecutorOpts{
377+
Logger: logManager,
378+
RepoArchiveRegistry: archiveRegistry,
379+
Creator: workspaceCreator,
380+
EnsureImage: imageCache.Ensure,
381+
Parallelism: parallelism,
382+
Timeout: opts.flags.timeout,
383+
TempDir: opts.flags.tempDir,
384+
GlobalEnv: os.Environ(),
385+
IsRemote: false,
386+
},
387+
Features: svc.Features(),
388+
Logger: logManager,
389+
Cache: executor.NewDiskCache(opts.flags.cacheDir),
390+
GlobalEnv: os.Environ(),
391+
IsRemote: false,
382392
},
383393
)
384394

0 commit comments

Comments
 (0)