Skip to content
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
12 changes: 12 additions & 0 deletions pkg/skaffold/tag/input_digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ func (t *inputDigestTagger) GenerateTag(ctx context.Context, image latest.Artifa
return "", err
}

if image.DockerArtifact != nil {
srcFiles = append(srcFiles, image.DockerArtifact.DockerfilePath)
}

if image.KanikoArtifact != nil {
srcFiles = append(srcFiles, image.KanikoArtifact.DockerfilePath)
}

if image.CustomArtifact != nil && image.CustomArtifact.Dependencies != nil && image.CustomArtifact.Dependencies.Dockerfile != nil {
srcFiles = append(srcFiles, image.CustomArtifact.Dependencies.Dockerfile.Path)
}

// must sort as hashing is sensitive to the order in which files are processed
sort.Strings(srcFiles)
for _, d := range srcFiles {
Expand Down
72 changes: 72 additions & 0 deletions pkg/skaffold/tag/input_digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ limitations under the License.
package tag

import (
"context"
"io"
"os"
"path/filepath"
"testing"

"github.com/google/go-cmp/cmp"

"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/graph"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/runner/runcontext"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/v2/testutil"
)

Expand Down Expand Up @@ -81,3 +88,68 @@ func TestInputDigest(t *testing.T) {
t.CheckFalse(hash1 == hash2)
})
}
func TestGenerateTag(t *testing.T) {
testutil.Run(t, "CompareTagWithAndWithoutDockerfile", func(t *testutil.T) {
runCtx := &runcontext.RunContext{}
dockerfile1Path := filepath.Join(t.TempDir(), "Dockerfile1")
dockerfile2Path := filepath.Join(t.TempDir(), "Dockerfile2")

f, err := os.Create(dockerfile1Path)
if err != nil {
panic(err)
}
defer f.Close()

_, err = io.WriteString(f, `
FROM busybox

CMD [ "ps", "faux" ]
`)
if err != nil {
panic(err)
}

f, err = os.Create(dockerfile2Path)
if err != nil {
panic(err)
}
defer f.Close()

_, err = io.WriteString(f, `
FROM busybox

CMD [ "true" ]
`)
if err != nil {
panic(err)
}

digestExample, _ := NewInputDigestTagger(runCtx, graph.ToArtifactGraph(runCtx.Artifacts()))
tag1, err := digestExample.GenerateTag(context.Background(), latest.Artifact{
ArtifactType: latest.ArtifactType{
DockerArtifact: &latest.DockerArtifact{
DockerfilePath: dockerfile1Path,
},
},
})
if err != nil {
t.Fatalf("Generate first tag failed: %v", err)
}

digestExample, _ = NewInputDigestTagger(runCtx, graph.ToArtifactGraph(runCtx.Artifacts()))
tag2, err := digestExample.GenerateTag(context.Background(), latest.Artifact{
ArtifactType: latest.ArtifactType{
DockerArtifact: &latest.DockerArtifact{
DockerfilePath: dockerfile2Path,
},
},
})
if err != nil {
t.Fatalf("Generate second tag failed: %v", err)
}

if diff := cmp.Diff(tag1, tag2); diff == "" {
t.Error("Tag does not differ between first and second Dockerfile")
}
})
}