Skip to content

Commit 51aaa5a

Browse files
authored
campaigns: use the temp dir when mounting scripts in volume mode (#436)
1 parent 5fe51e6 commit 51aaa5a

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
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+
- Executing campaigns on macOS 11 with Docker 3.1 could fail when using a volume workspace. This has been fixed. [#436](https://github.com/sourcegraph/src-cli/pull/436)
21+
2022
### Removed
2123

2224
## 3.24.1

cmd/src/campaigns_common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func campaignsExecute(ctx context.Context, out *output.Output, svc *campaigns.Se
224224
}
225225

226226
pending = campaignsCreatePending(out, "Preparing workspaces")
227-
workspaceCreator := svc.NewWorkspaceCreator(ctx, flags.cacheDir, campaignSpec.Steps)
227+
workspaceCreator := svc.NewWorkspaceCreator(ctx, flags.cacheDir, flags.tempDir, campaignSpec.Steps)
228228
pending.VerboseLine(output.Linef("🚧", output.StyleSuccess, "Workspace creator: %T", workspaceCreator))
229229
campaignsCompletePending(pending, "Prepared workspaces")
230230

internal/campaigns/service.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (svc *Service) NewRepoFetcher(dir string, cleanArchives bool) RepoFetcher {
211211
}
212212
}
213213

214-
func (svc *Service) NewWorkspaceCreator(ctx context.Context, dir string, steps []Step) WorkspaceCreator {
214+
func (svc *Service) NewWorkspaceCreator(ctx context.Context, cacheDir, tempDir string, steps []Step) WorkspaceCreator {
215215
var workspace workspaceCreatorType
216216
if svc.workspace == "volume" {
217217
workspace = workspaceCreatorVolume
@@ -222,9 +222,9 @@ func (svc *Service) NewWorkspaceCreator(ctx context.Context, dir string, steps [
222222
}
223223

224224
if workspace == workspaceCreatorVolume {
225-
return &dockerVolumeWorkspaceCreator{}
225+
return &dockerVolumeWorkspaceCreator{tempDir: tempDir}
226226
}
227-
return &dockerBindWorkspaceCreator{dir: dir}
227+
return &dockerBindWorkspaceCreator{dir: cacheDir}
228228
}
229229

230230
// dockerImageSet represents a set of Docker images that need to be pulled. The

internal/campaigns/volume_workspace.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import (
1313
"github.com/sourcegraph/src-cli/internal/version"
1414
)
1515

16-
type dockerVolumeWorkspaceCreator struct{}
16+
type dockerVolumeWorkspaceCreator struct {
17+
tempDir string
18+
}
1719

1820
var _ WorkspaceCreator = &dockerVolumeWorkspaceCreator{}
1921

@@ -23,7 +25,7 @@ func (wc *dockerVolumeWorkspaceCreator) Create(ctx context.Context, repo *graphq
2325
return nil, errors.Wrap(err, "creating Docker volume")
2426
}
2527

26-
w := &dockerVolumeWorkspace{volume: volume}
28+
w := &dockerVolumeWorkspace{tempDir: wc.tempDir, volume: volume}
2729
if err := wc.unzipRepoIntoVolume(ctx, w, zip); err != nil {
2830
return nil, errors.Wrap(err, "unzipping repo into workspace")
2931
}
@@ -87,7 +89,8 @@ func (*dockerVolumeWorkspaceCreator) unzipRepoIntoVolume(ctx context.Context, w
8789
// advantages if bind mounts are slow, such as on Docker for Mac, but could make
8890
// debugging harder and is slower when it's time to actually retrieve the diff.
8991
type dockerVolumeWorkspace struct {
90-
volume string
92+
tempDir string
93+
volume string
9194
}
9295

9396
var _ Workspace = &dockerVolumeWorkspace{}
@@ -165,7 +168,7 @@ func init() {
165168
// container started from the dockerWorkspaceImage, then run it and return the
166169
// output.
167170
func (w *dockerVolumeWorkspace) runScript(ctx context.Context, target, script string) ([]byte, error) {
168-
f, err := ioutil.TempFile(os.TempDir(), "src-run-*")
171+
f, err := ioutil.TempFile(w.tempDir, "src-run-*")
169172
if err != nil {
170173
return nil, errors.Wrap(err, "creating run script")
171174
}

0 commit comments

Comments
 (0)