Skip to content

Commit

Permalink
test: add test case for setcap in Dockerfile
Browse files Browse the repository at this point in the history
This is a followup of #1994. This test runs a Dockerfile where setcap is
executed. Without the fix in #1994, the last command won't generate any
diff and thus is discarded by kaniko and thus should fail this test.
  • Loading branch information
zhouhaibing089 committed May 9, 2022
1 parent 816e6d5 commit ce042f0
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 13 deletions.
17 changes: 17 additions & 0 deletions integration/dockerfiles-with-context/issue-1851/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2022 Google, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM wildwildangel/setcap-static:sha-a5c7425
ADD test-file /usr/bin/test-file
RUN ["/setcap-static", "cap_net_bind_service=+ep", "/usr/bin/test-file"]
Empty file.
29 changes: 19 additions & 10 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@ const (
"Adds": [],
"Dels": []
}
}
},
{
"Image1": "%s",
"Image2": "%s",
"DiffType": "History",
"Diff": {
"Adds": [],
"Dels": []
}
}
]`
)

Expand Down Expand Up @@ -187,7 +196,7 @@ func TestRun(t *testing.T) {

diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache")

expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage)
expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage, dockerImage, kanikoImage)
checkContainerDiffOutput(t, diff, expected)

})
Expand Down Expand Up @@ -262,7 +271,7 @@ func testGitBuildcontextHelper(t *testing.T, repo string) {

diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache")

expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage)
expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage, dockerImage, kanikoImage)
checkContainerDiffOutput(t, diff, expected)
}

Expand Down Expand Up @@ -331,7 +340,7 @@ func TestGitBuildcontextSubPath(t *testing.T) {

diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache")

expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage)
expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage, dockerImage, kanikoImage)
checkContainerDiffOutput(t, diff, expected)
}

Expand Down Expand Up @@ -371,7 +380,7 @@ func TestBuildViaRegistryMirrors(t *testing.T) {

diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache")

expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage)
expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage, dockerImage, kanikoImage)
checkContainerDiffOutput(t, diff, expected)
}

Expand Down Expand Up @@ -411,7 +420,7 @@ func TestKanikoDir(t *testing.T) {

diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache")

expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage)
expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage, dockerImage, kanikoImage)
checkContainerDiffOutput(t, diff, expected)
}

Expand Down Expand Up @@ -454,7 +463,7 @@ func TestBuildWithLabels(t *testing.T) {

diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache")

expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage)
expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage, dockerImage, kanikoImage)
checkContainerDiffOutput(t, diff, expected)
}

Expand Down Expand Up @@ -565,7 +574,7 @@ func TestCache(t *testing.T) {

diff := containerDiff(t, kanikoVersion0, kanikoVersion1)

expected := fmt.Sprintf(emptyContainerDiff, kanikoVersion0, kanikoVersion1, kanikoVersion0, kanikoVersion1)
expected := fmt.Sprintf(emptyContainerDiff, kanikoVersion0, kanikoVersion1, kanikoVersion0, kanikoVersion1, kanikoVersion0, kanikoVersion1)
checkContainerDiffOutput(t, diff, expected)
})
}
Expand Down Expand Up @@ -601,7 +610,7 @@ func TestRelativePaths(t *testing.T) {

diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache")

expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage)
expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage, dockerImage, kanikoImage)
checkContainerDiffOutput(t, diff, expected)
})
}
Expand Down Expand Up @@ -893,7 +902,7 @@ func meetsRequirements() bool {
func containerDiff(t *testing.T, image1, image2 string, flags ...string) []byte {
flags = append([]string{"diff"}, flags...)
flags = append(flags, image1, image2,
"-q", "--type=file", "--type=metadata", "--json")
"-q", "--type=file", "--type=metadata", "--history", "--json")

containerdiffCmd := exec.Command("container-diff", flags...)
diff := RunCommand(containerdiffCmd, t)
Expand Down
2 changes: 1 addition & 1 deletion integration/integration_with_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestWithContext(t *testing.T) {

diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache")

expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage)
expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage, dockerImage, kanikoImage)
checkContainerDiffOutput(t, diff, expected)

})
Expand Down
2 changes: 1 addition & 1 deletion integration/integration_with_stdin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestBuildWithStdin(t *testing.T) {

diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImageStdin, "--no-cache")

expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImageStdin, dockerImage, kanikoImageStdin)
expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImageStdin, dockerImage, kanikoImageStdin, dockerImage, kanikoImageStdin)
checkContainerDiffOutput(t, diff, expected)

if err := os.RemoveAll(testDirLongPath); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion integration/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestK8s(t *testing.T) {

diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache")

expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage)
expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage, dockerImage, kanikoImage)
checkContainerDiffOutput(t, diff, expected)
})
}
Expand Down

0 comments on commit ce042f0

Please sign in to comment.