Skip to content

Commit

Permalink
Dockerfile should always be sent to daemon
Browse files Browse the repository at this point in the history
Fixes #597
  • Loading branch information
dgageot committed May 31, 2018
1 parent 389905f commit e59ffac
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 38 deletions.
10 changes: 2 additions & 8 deletions pkg/skaffold/docker/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,8 @@ func GetDockerfileDependencies(dockerfilePath, workspace string) ([]string, erro
})
}

// Add dockerfile?
m, err := fileutils.Matches(dockerfilePath, excludes)
if err != nil {
return nil, err
}
if !m {
files[dockerfilePath] = true
}
// Always add dockerfile even if it's .dockerignored. The daemon will need it anyways.
files[dockerfilePath] = true

// Ignore .dockerignore
delete(files, ".dockerignore")
Expand Down
62 changes: 32 additions & 30 deletions pkg/skaffold/docker/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import (
"github.com/google/go-containerregistry/v1"
)

const copyDockerfile = `
const copyServerGo = `
FROM ubuntu:14.04
COPY server.go .
CMD server.go
`

const addDockerfile = `
const addNginx = `
FROM nginx
ADD nginx.conf /etc/nginx
CMD nginx
Expand Down Expand Up @@ -90,11 +90,6 @@ COPY . /files
CMD nginx
`

const dockerIgnore = `
bar
docker/*
`

// This has an ONBUILD instruction of "COPY . /go/src/app"
const onbuild = `
FROM golang:onbuild
Expand Down Expand Up @@ -140,24 +135,24 @@ func mockRetrieveImage(image string) (*v1.ConfigFile, error) {

func TestGetDockerfileDependencies(t *testing.T) {
var tests = []struct {
description string
dockerfile string
workspace string
dockerIgnore bool
description string
dockerfile string
workspace string
ignore string

expected []string
badReader bool
shouldErr bool
}{
{
description: "copy dependency",
dockerfile: copyDockerfile,
dockerfile: copyServerGo,
workspace: ".",
expected: []string{"Dockerfile", "server.go"},
},
{
description: "add dependency",
dockerfile: addDockerfile,
dockerfile: addNginx,
workspace: "docker",
expected: []string{"Dockerfile", "nginx.conf"},
},
Expand Down Expand Up @@ -197,25 +192,32 @@ func TestGetDockerfileDependencies(t *testing.T) {
expected: []string{"Dockerfile", "file", "server.go"},
},
{
description: "dockerignore test",
dockerfile: copyDirectory,
dockerIgnore: true,
workspace: ".",
expected: []string{"Dockerfile", "file", "server.go", "test.conf", "worker.go"},
description: "dockerignore test",
dockerfile: copyDirectory,
ignore: "bar\ndocker/*",
workspace: ".",
expected: []string{"Dockerfile", "file", "server.go", "test.conf", "worker.go"},
},
{
description: "dockerignore dockerfile",
dockerfile: copyServerGo,
ignore: "Dockerfile",
workspace: ".",
expected: []string{"Dockerfile", "server.go"},
},
{
description: "dockerignore with non canonical workspace",
dockerfile: contextDockerfile,
workspace: "docker/../docker",
dockerIgnore: true,
expected: []string{"Dockerfile", "nginx.conf"},
description: "dockerignore with non canonical workspace",
dockerfile: contextDockerfile,
workspace: "docker/../docker",
ignore: "bar\ndocker/*",
expected: []string{"Dockerfile", "nginx.conf"},
},
{
description: "dockerignore with context in parent directory",
dockerfile: contextDockerfile,
workspace: "docker/..",
dockerIgnore: true,
expected: []string{"Dockerfile", "file", "server.go", "test.conf", "worker.go"},
description: "dockerignore with context in parent directory",
dockerfile: contextDockerfile,
workspace: "docker/..",
ignore: "bar\ndocker/*",
expected: []string{"Dockerfile", "file", "server.go", "test.conf", "worker.go"},
},
{
description: "onbuild test",
Expand Down Expand Up @@ -251,8 +253,8 @@ func TestGetDockerfileDependencies(t *testing.T) {
ioutil.WriteFile(filepath.Join(workspace, "Dockerfile"), []byte(test.dockerfile), 0644)
}

if test.dockerIgnore {
ioutil.WriteFile(filepath.Join(workspace, ".dockerignore"), []byte(dockerIgnore), 0644)
if test.ignore != "" {
ioutil.WriteFile(filepath.Join(workspace, ".dockerignore"), []byte(test.ignore), 0644)
}

deps, err := GetDockerfileDependencies("Dockerfile", workspace)
Expand Down

0 comments on commit e59ffac

Please sign in to comment.