test: add it
@@ -260,6 +260,50 @@ func TestGitBuildcontext(t *testing.T) {
checkContainerDiffOutput(t, diff, expected)
}
+func TestGitBuildcontextSubPath(t *testing.T) {
+ repo := getGitRepo()
+ dockerfile := "Dockerfile_test_run_2"
+
+ // Build with docker
+ dockerImage := GetDockerImage(config.imageRepo, "Dockerfile_test_git")
+ dockerCmd := exec.Command("docker",
+ append([]string{
+ "build",
+ "-t", dockerImage,
+ "-f", dockerfile,
+ filepath.Join(repo, integrationPath, dockerfilesPath),
+ })...)
+ out, err := RunCommandWithoutTest(dockerCmd)
+ if err != nil {
+ t.Errorf("Failed to build image %s with docker command %q: %s %s", dockerImage, dockerCmd.Args, err, string(out))
+ }
+
+ // Build with kaniko
+ kanikoImage := GetKanikoImage(config.imageRepo, "Dockerfile_test_git")
+ dockerRunFlags := []string{"run", "--net=host"}
+ dockerRunFlags = addServiceAccountFlags(dockerRunFlags, config.serviceAccount)
+ dockerRunFlags = append(
+ dockerRunFlags,
+ ExecutorImage,
+ "-f", dockerfile,
+ "-d", kanikoImage,
+ "-c", fmt.Sprintf("git://%s", repo),
+ "--context-sub-path", filepath.Join(integrationPath, dockerfilesPath),
+ )
+
+ kanikoCmd := exec.Command("docker", dockerRunFlags...)
+
+ out, err = RunCommandWithoutTest(kanikoCmd)
+ if err != nil {
+ t.Errorf("Failed to build image %s with kaniko command %q: %v %s", dockerImage, kanikoCmd.Args, err, string(out))
+ }
+
+ diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache")
+
+ expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage)
+ checkContainerDiffOutput(t, diff, expected)
+}
+
func TestBuildViaRegistryMirror(t *testing.T) {
repo := getGitRepo()
dockerfile := "integration/dockerfiles/Dockerfile_registry_mirror"
