Skip to content

Commit b3a1ef4

Browse files
authored
Remove support for inline dockerfiles (#154)
1 parent 1bb998d commit b3a1ef4

File tree

3 files changed

+18
-64
lines changed

3 files changed

+18
-64
lines changed

cmd/src/actions_exec.go

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"flag"
99
"fmt"
1010
"io/ioutil"
11-
"log"
1211
"os"
1312
"os/exec"
1413
"path/filepath"
@@ -29,11 +28,10 @@ type Action struct {
2928
}
3029

3130
type ActionStep struct {
32-
Type string `json:"type"` // "command"
33-
Dockerfile string `json:"dockerfile,omitempty"`
34-
Image string `json:"image,omitempty"` // Docker image
35-
CacheDirs []string `json:"cacheDirs,omitempty"`
36-
Args []string `json:"args,omitempty"`
31+
Type string `json:"type"` // "command"
32+
Image string `json:"image,omitempty"` // Docker image
33+
CacheDirs []string `json:"cacheDirs,omitempty"`
34+
Args []string `json:"args,omitempty"`
3735

3836
// ImageContentDigest is an internal field that should not be set by users.
3937
ImageContentDigest string
@@ -61,21 +59,21 @@ Execute an action on code in repositories. The output of an action is a set of p
6159
6260
Examples:
6361
64-
Execute an action defined in ~/run-gofmt-in-dockerfile.json:
62+
Execute an action defined in ~/run-gofmt.json:
6563
66-
$ src actions exec -f ~/run-gofmt-in-dockerfile.json
64+
$ src actions exec -f ~/run-gofmt.json
6765
6866
Execute an action and create a campaign plan from the patches it produced:
6967
70-
$ src actions exec -f ~/run-gofmt-in-dockerfile.json -create-plan
68+
$ src actions exec -f ~/run-gofmt.json -create-plan
7169
7270
Verbosely execute an action and keep the logs available for debugging:
7371
74-
$ src -v actions exec -keep-logs -f ~/run-gofmt-in-dockerfile.json
72+
$ src -v actions exec -keep-logs -f ~/run-gofmt.json
7573
7674
Execute an action and pipe the patches it produced to 'src campaign plan create-from-patches':
7775
78-
$ src actions exec -f ~/run-gofmt-in-dockerfile.json | src campaign plan create-from-patches
76+
$ src actions exec -f ~/run-gofmt.json | src campaign plan create-from-patches
7977
8078
Read and execute an action definition from standard input:
8179
@@ -105,13 +103,13 @@ Format of the action JSON files:
105103
106104
This action runs a single step over repositories whose name contains "github", building and starting a Docker container based on the image defined through the "dockerfile". In the container the word 'this' is replaced with 'that' in all text files.
107105
108-
109106
{
110107
"scopeQuery": "repo:github",
111108
"steps": [
112109
{
113110
"type": "docker",
114-
"dockerfile": "FROM alpine:3 \n CMD find /work -iname '*.txt' -type f | xargs -n 1 sed -i s/this/that/g"
111+
"image": "alpine:3",
112+
"args": ["sh", "-c", "find /work -iname '*.txt' -type f | xargs -n 1 sed -i s/this/that/g"]
115113
}
116114
]
117115
}
@@ -291,12 +289,8 @@ Format of the action JSON files:
291289
func validateAction(ctx context.Context, action Action) error {
292290
for _, step := range action.Steps {
293291
if step.Type == "docker" {
294-
if step.Dockerfile == "" && step.Image == "" {
295-
return fmt.Errorf("docker run step has to specify either 'image' or 'dockerfile'")
296-
}
297-
298-
if step.Dockerfile != "" && step.Image != "" {
299-
return fmt.Errorf("docker run step may specify either image (%q) or dockerfile, not both", step.Image)
292+
if step.Image == "" {
293+
return fmt.Errorf("docker run step has to specify 'image'")
300294
}
301295

302296
if step.ImageContentDigest != "" {
@@ -314,44 +308,8 @@ func validateAction(ctx context.Context, action Action) error {
314308

315309
func prepareAction(ctx context.Context, action Action) error {
316310
// Build any Docker images.
317-
for i, step := range action.Steps {
311+
for _, step := range action.Steps {
318312
if step.Type == "docker" {
319-
if step.Dockerfile == "" && step.Image == "" {
320-
return fmt.Errorf("docker run step has to specify either 'image' or 'dockerfile'")
321-
}
322-
323-
if step.Dockerfile != "" && step.Image != "" {
324-
return fmt.Errorf("docker run step may specify either image (%q) or dockerfile, not both", step.Image)
325-
}
326-
327-
if step.Dockerfile != "" {
328-
iidFile, err := ioutil.TempFile("", "src-actions-exec-image-id")
329-
if err != nil {
330-
return err
331-
}
332-
defer os.Remove(iidFile.Name())
333-
334-
if *verbose {
335-
log.Printf("Building Docker container for step %d...", i)
336-
}
337-
338-
cmd := exec.CommandContext(ctx, "docker", "build", "--iidfile", iidFile.Name(), "-")
339-
cmd.Stdin = strings.NewReader(step.Dockerfile)
340-
verboseCmdOutput(cmd)
341-
if err := cmd.Run(); err != nil {
342-
return errors.Wrap(err, "build docker image")
343-
}
344-
if *verbose {
345-
log.Printf("Done building Docker container for step %d.", i)
346-
}
347-
348-
iid, err := ioutil.ReadFile(iidFile.Name())
349-
if err != nil {
350-
return err
351-
}
352-
step.Image = string(iid)
353-
}
354-
355313
// Set digests for Docker images so we don't cache action runs in 2 different images with
356314
// the same tag.
357315
if step.Image != "" {

cmd/src/actions_exec_backend_runner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func runAction(ctx context.Context, prefix, repoID, repoName, rev string, steps
165165
logger.CommandStepDone(repoName, i)
166166

167167
case "docker":
168-
logger.DockerStepStarted(repoName, i, step.Dockerfile, step.Image)
168+
logger.DockerStepStarted(repoName, i, step.Image)
169169

170170
cidFile, err := ioutil.TempFile(tempDirPrefix, prefix+"-container-id")
171171
if err != nil {
@@ -242,7 +242,7 @@ func runAction(ctx context.Context, prefix, repoID, repoName, rev string, steps
242242
// As of Sourcegraph 3.14 we only support unified diff format.
243243
// That means we need to strip away the `a/` and `/b` prefixes with `--no-prefix`.
244244
// See: https://github.com/sourcegraph/sourcegraph/blob/82d5e7e1562fef6be5c0b17f18631040fd330835/enterprise/internal/campaigns/service.go#L324-L329
245-
//
245+
//
246246
diffOut, err := runGitCmd("diff", "--cached", "--no-prefix")
247247
if err != nil {
248248
return nil, errors.Wrap(err, "git diff failed")

cmd/src/actions_exec_logger.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,8 @@ func (a *actionLogger) CommandStepDone(repoName string, step int) {
200200
a.write(repoName, yellow, "[Step %d] Done.\n", step)
201201
}
202202

203-
func (a *actionLogger) DockerStepStarted(repoName string, step int, dockerfile, image string) {
204-
var fromDockerfile string
205-
if dockerfile != "" {
206-
fromDockerfile = " (built from inline Dockerfile)"
207-
}
208-
a.write(repoName, yellow, "[Step %d] docker run %v%s\n", step, image, fromDockerfile)
203+
func (a *actionLogger) DockerStepStarted(repoName string, step int, image string) {
204+
a.write(repoName, yellow, "[Step %d] docker run %s\n", step, image)
209205
}
210206

211207
func (a *actionLogger) DockerStepErrored(repoName string, step int, err error, elapsed time.Duration) {

0 commit comments

Comments
 (0)