Skip to content

Fix 'skaffold diagnose' for custom builder without dependencies #2724

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

Merged
merged 2 commits into from
Aug 28, 2019
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
6 changes: 3 additions & 3 deletions integration/diagnose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ func TestDiagnose(t *testing.T) {
tests := []struct {
name string
dir string
args []string
}{
{name: "kaniko builder", dir: "examples/kaniko"},
{name: "docker builder", dir: "examples/nodejs"},
{name: "jib maven builder", dir: "testdata/jib"},
{name: "jib gradle builder", dir: "testdata/jib-gradle"},
{name: "bazel builder", dir: "examples/bazel"},
// todo add test cases for "jib gradle builder" and "custom builder"
{name: "custom builder", dir: "testdata/custom"},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
skaffold.Diagnose(test.args...).InDir(test.dir).RunOrFailOutput(t)
skaffold.Diagnose().InDir(test.dir).RunOrFailOutput(t)
})
}
}
11 changes: 10 additions & 1 deletion pkg/skaffold/schema/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package defaults
import (
"fmt"

"github.com/mitchellh/go-homedir"
homedir "github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

Expand Down Expand Up @@ -68,6 +68,7 @@ func Set(c *latest.SkaffoldConfig) error {
setDefaultWorkspace(a)
defaultToDockerArtifact(a)
setDefaultDockerfile(a)
setDefaultCustomDependencies(a)
}

for _, pf := range c.PortForward {
Expand Down Expand Up @@ -154,6 +155,14 @@ func setDefaultDockerfile(a *latest.Artifact) {
}
}

func setDefaultCustomDependencies(a *latest.Artifact) {
if a.CustomArtifact != nil {
if a.CustomArtifact.Dependencies == nil {
a.CustomArtifact.Dependencies = &latest.CustomDependencies{}
}
}
}

// SetDefaultDockerArtifact sets defaults on docker artifacts
func SetDefaultDockerArtifact(a *latest.DockerArtifact) {
a.DockerfilePath = valueOrDefault(a.DockerfilePath, constants.DefaultDockerfilePath)
Expand Down
10 changes: 10 additions & 0 deletions pkg/skaffold/schema/defaults/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func TestSetDefaults(t *testing.T) {
},
},
},
{
ImageName: "third",
ArtifactType: latest.ArtifactType{
CustomArtifact: &latest.CustomArtifact{},
},
},
},
},
},
Expand All @@ -58,6 +64,10 @@ func TestSetDefaults(t *testing.T) {
testutil.CheckDeepEqual(t, "second", cfg.Build.Artifacts[1].ImageName)
testutil.CheckDeepEqual(t, "folder", cfg.Build.Artifacts[1].Workspace)
testutil.CheckDeepEqual(t, "Dockerfile.second", cfg.Build.Artifacts[1].DockerArtifact.DockerfilePath)

testutil.CheckDeepEqual(t, "third", cfg.Build.Artifacts[2].ImageName)
testutil.CheckDeepEqual(t, []string(nil), cfg.Build.Artifacts[2].CustomArtifact.Dependencies.Paths)
testutil.CheckDeepEqual(t, []string(nil), cfg.Build.Artifacts[2].CustomArtifact.Dependencies.Ignore)
}

func TestSetDefaultsOnCluster(t *testing.T) {
Expand Down