Skip to content

Commit

Permalink
Merge pull request #483 from yui-knk/copy_command_http
Browse files Browse the repository at this point in the history
Return an error when copying from url
  • Loading branch information
tonistiigi authored Jul 3, 2018
2 parents 2e7a680 + 30c27cd commit 0f20a37
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion frontend/dockerfile/dockerfile2llb/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,11 @@ func dispatchCopy(d *dispatchState, c instructions.SourcesAndDest, sourceState l

for i, src := range c.Sources() {
commitMessage.WriteString(" " + src)
if isAddCommand && (strings.HasPrefix(src, "http://") || strings.HasPrefix(src, "https://")) {
if strings.HasPrefix(src, "http://") || strings.HasPrefix(src, "https://") {
if !isAddCommand {
return errors.New("source can't be a URL for COPY")
}

// Resources from remote URLs are not decompressed.
// https://docs.docker.com/engine/reference/builder/#add
//
Expand Down
12 changes: 12 additions & 0 deletions frontend/dockerfile/dockerfile2llb/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ COPY --from=0 f2 /
})
assert.Error(t, err)

df = `FROM busybox
ADD http://github.com/moby/buildkit/blob/master/README.md /
`
_, _, err = Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{})
assert.NoError(t, err)

df = `FROM busybox
COPY http://github.com/moby/buildkit/blob/master/README.md /
`
_, _, err = Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{})
assert.EqualError(t, err, "source can't be a URL for COPY")

df = `FROM "" AS foo`
_, _, err = Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{})
assert.Error(t, err)
Expand Down

0 comments on commit 0f20a37

Please sign in to comment.