Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All notable changes to `src-cli` are documented in this file.
### Fixed

- Campaign steps run in a container that does not run as root could fail on systems that do not map the running user ID to the container, most notably desktop Linux. This has been fixed: temporary files and workspaces mounted into the container now have sufficient permissions to allow the container user to execute the step. [#366](https://github.com/sourcegraph/src-cli/pull/366)
- Executing campaigns on Windows would fail due to obscure `--cidfile` errors: namely, the temporary cidfile would not be removed before `docker run` was invoked. This has been fixed. [#368](https://github.com/sourcegraph/src-cli/pull/368)

## 3.21.5

Expand Down
15 changes: 14 additions & 1 deletion internal/campaigns/run_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,24 @@ func runSteps(ctx context.Context, wc *WorkspaceCreator, repo *graphql.Repositor
stepContext.PreviousStep = results[i-1]
}

// Find a location that we can use for a cidfile, which will contain the
// container ID that is used below. We can then use this to remove the
// container on a successful run, rather than leaving it dangling.
cidFile, err := ioutil.TempFile(tempDir, repo.Slug()+"-container-id")
if err != nil {
return nil, errors.Wrap(err, "Creating a CID file failed")
}
_ = os.Remove(cidFile.Name()) // docker exits if this file exists upon `docker run` starting

// However, Docker will fail if the cidfile actually exists, so we need
// to remove it. Because Windows can't remove open files, we'll first
// close it, even though that's unnecessary elsewhere.
cidFile.Close()
if err = os.Remove(cidFile.Name()); err != nil {
return nil, errors.Wrap(err, "removing cidfile")
}

// Since we went to all that effort, we can now defer a function that
// uses the cidfile to clean up after this function is done.
defer func() {
cid, err := ioutil.ReadFile(cidFile.Name())
_ = os.Remove(cidFile.Name())
Expand Down