Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile should always be sent to daemon #605

Merged
merged 1 commit into from
Jun 1, 2018
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
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