Skip to content

Commit 62b1322

Browse files
authored
Fix importing changesets with no docker images (#630)
When only importing changesets, no docker images would need to be pulled. In the TUI, a division by zero would be made and the input for the tab UI would be NaN. This caused an error, that was reported in #629.
1 parent 3fd8775 commit 62b1322

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ All notable changes to `src-cli` are documented in this file.
1717

1818
### Fixed
1919

20+
- Fixes an issue where src-cli would panic when importing existing changesets.
21+
2022
### Removed
2123

2224
## 3.31.1

cmd/src/batch_common.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,22 +248,26 @@ func executeBatchSpec(ctx context.Context, opts executeBatchSpecOpts) (err error
248248
}
249249
opts.ui.ResolvingNamespaceSuccess(namespace)
250250

251-
opts.ui.PreparingContainerImages()
252-
images, err := svc.EnsureDockerImages(ctx, batchSpec, opts.ui.PreparingContainerImagesProgress)
253-
if err != nil {
254-
return err
255-
}
256-
opts.ui.PreparingContainerImagesSuccess()
251+
var workspaceCreator workspace.Creator
257252

258-
opts.ui.DeterminingWorkspaceCreatorType()
259-
workspaceCreator := workspace.NewCreator(ctx, opts.flags.workspace, opts.flags.cacheDir, opts.flags.tempDir, images)
260-
if workspaceCreator.Type() == workspace.CreatorTypeVolume {
261-
_, err = svc.EnsureImage(ctx, workspace.DockerVolumeWorkspaceImage)
253+
if svc.HasDockerImages(batchSpec) {
254+
opts.ui.PreparingContainerImages()
255+
images, err := svc.EnsureDockerImages(ctx, batchSpec, opts.ui.PreparingContainerImagesProgress)
262256
if err != nil {
263257
return err
264258
}
259+
opts.ui.PreparingContainerImagesSuccess()
260+
261+
opts.ui.DeterminingWorkspaceCreatorType()
262+
workspaceCreator = workspace.NewCreator(ctx, opts.flags.workspace, opts.flags.cacheDir, opts.flags.tempDir, images)
263+
if workspaceCreator.Type() == workspace.CreatorTypeVolume {
264+
_, err = svc.EnsureImage(ctx, workspace.DockerVolumeWorkspaceImage)
265+
if err != nil {
266+
return err
267+
}
268+
}
269+
opts.ui.DeterminingWorkspaceCreatorTypeSuccess(workspaceCreator.Type())
265270
}
266-
opts.ui.DeterminingWorkspaceCreatorTypeSuccess(workspaceCreator.Type())
267271

268272
opts.ui.ResolvingRepositories()
269273
repos, err := svc.ResolveRepositories(ctx, batchSpec)

cmd/src/batch_exec.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,26 @@ func executeBatchSpecInWorkspaces(ctx context.Context, opts executeBatchSpecOpts
125125
}
126126
opts.ui.ParsingBatchSpecSuccess()
127127

128-
opts.ui.PreparingContainerImages()
129-
images, err := svc.EnsureDockerImages(ctx, batchSpec, opts.ui.PreparingContainerImagesProgress)
130-
if err != nil {
131-
return err
132-
}
133-
opts.ui.PreparingContainerImagesSuccess()
128+
var workspaceCreator workspace.Creator
134129

135-
opts.ui.DeterminingWorkspaceCreatorType()
136-
workspaceCreator := workspace.NewCreator(ctx, opts.flags.workspace, opts.flags.cacheDir, opts.flags.tempDir, images)
137-
if workspaceCreator.Type() == workspace.CreatorTypeVolume {
138-
_, err = svc.EnsureImage(ctx, workspace.DockerVolumeWorkspaceImage)
130+
if svc.HasDockerImages(batchSpec) {
131+
opts.ui.PreparingContainerImages()
132+
images, err := svc.EnsureDockerImages(ctx, batchSpec, opts.ui.PreparingContainerImagesProgress)
139133
if err != nil {
140134
return err
141135
}
136+
opts.ui.PreparingContainerImagesSuccess()
137+
138+
opts.ui.DeterminingWorkspaceCreatorType()
139+
workspaceCreator = workspace.NewCreator(ctx, opts.flags.workspace, opts.flags.cacheDir, opts.flags.tempDir, images)
140+
if workspaceCreator.Type() == workspace.CreatorTypeVolume {
141+
_, err = svc.EnsureImage(ctx, workspace.DockerVolumeWorkspaceImage)
142+
if err != nil {
143+
return err
144+
}
145+
}
146+
opts.ui.DeterminingWorkspaceCreatorTypeSuccess(workspaceCreator.Type())
142147
}
143-
opts.ui.DeterminingWorkspaceCreatorTypeSuccess(workspaceCreator.Type())
144148

145149
// EXECUTION OF TASKS
146150
coord := svc.NewCoordinator(executor.NewCoordinatorOpts{

internal/batches/service/service.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ func (svc *Service) EnsureDockerImages(ctx context.Context, spec *batcheslib.Bat
172172
return images, nil
173173
}
174174

175+
func (svc *Service) HasDockerImages(spec *batcheslib.BatchSpec) bool {
176+
return len(spec.Steps) > 0
177+
}
178+
175179
func (svc *Service) EnsureImage(ctx context.Context, name string) (docker.Image, error) {
176180
img := svc.imageCache.Get(name)
177181

0 commit comments

Comments
 (0)