Skip to content

Commit 3b38bd9

Browse files
authored
Fix running containers that don't have shell entrypoints (#300)
Previously when trying to run the following spec step: steps: - run: comby -in-place 'fmt.Sprintf("%d", :[v])' 'strconv.Itoa(:[v])' .go -matcher .go -d /work -exclude-dir .,vendor container: comby/comby I got this error: executing campaign spec: Error executing task. The log file can be found at: /tmp/changeset-github.com-sourcegraph-automation-testing.log747594520 : probing image "sha256:c7bdf774c287814a4958bd175f54e598571eae161aea791df4b62e255df6f590" for shell: 2 errors occurred: * probing shell "/bin/bash": Error parsing command line: flag -c is an ambiguous prefix: -color, -count, -custom-matcher For usage information, run comby -help : exit status 1 * probing shell "/bin/sh": Error parsing command line: flag -c is an ambiguous prefix: -color, -count, -custom-matcher For usage information, run comby -help : exit status 1 This fixes that error (and it fixes https://github.com/sourcegraph/sourcegraph/issues/13620) by setting the `--entrypoint` on each container and then passing arguments to that.
1 parent 63e675b commit 3b38bd9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

internal/campaigns/run_steps.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,12 @@ func runSteps(ctx context.Context, client api.Client, repo *graphql.Repository,
113113
"--workdir", workDir,
114114
"--mount", fmt.Sprintf("type=bind,source=%s,target=%s", volumeDir, workDir),
115115
"--mount", fmt.Sprintf("type=bind,source=%s,target=%s,ro", hostTemp, containerTemp),
116+
"--entrypoint", shell,
116117
)
117118
for k, v := range step.Env {
118119
cmd.Args = append(cmd.Args, "-e", k+"="+v)
119120
}
120-
cmd.Args = append(cmd.Args, "--", step.image, shell, containerTemp)
121+
cmd.Args = append(cmd.Args, "--", step.image, containerTemp)
121122
cmd.Dir = volumeDir
122123
cmd.Stdout = logger.PrefixWriter("stdout")
123124
cmd.Stderr = logger.PrefixWriter("stderr")
@@ -273,9 +274,6 @@ func probeImageForShell(ctx context.Context, image string) (shell, tempfile stri
273274
// same time by trying to run /bin/bash -c mktemp,
274275
// followed by /bin/sh -c mktemp.
275276

276-
// First, let's set up the base command we'll be using.
277-
args := []string{"run", "--rm", image}
278-
279277
// We'll also set up our error.
280278
err = new(multierror.Error)
281279

@@ -285,7 +283,9 @@ func probeImageForShell(ctx context.Context, image string) (shell, tempfile stri
285283
stdout := new(bytes.Buffer)
286284
stderr := new(bytes.Buffer)
287285

288-
cmd := exec.CommandContext(ctx, "docker", append(args, shell, "-c", "mktemp")...)
286+
args := []string{"run", "--rm", "--entrypoint", shell, image, "-c", "mktemp"}
287+
288+
cmd := exec.CommandContext(ctx, "docker", args...)
289289
cmd.Stdout = stdout
290290
cmd.Stderr = stderr
291291

0 commit comments

Comments
 (0)