diff --git a/integration_tests/dockerfiles/Dockerfile_test_scratch b/integration_tests/dockerfiles/Dockerfile_test_scratch new file mode 100644 index 000000000..0fb22d93b --- /dev/null +++ b/integration_tests/dockerfiles/Dockerfile_test_scratch @@ -0,0 +1,4 @@ +FROM scratch +ADD context/foo /foo +ENV hello hello +ADD context/foo /$hello diff --git a/integration_tests/dockerfiles/config_test_registry.json b/integration_tests/dockerfiles/config_test_registry.json index 5674ccbed..27e7a402e 100644 --- a/integration_tests/dockerfiles/config_test_registry.json +++ b/integration_tests/dockerfiles/config_test_registry.json @@ -1,7 +1,7 @@ [ { - "Image1": "gcr.io/kbuild-test/docker-test-registry:latest", - "Image2": "gcr.io/kbuild-test/kbuild-test-registry:latest", + "Image1": "gcr.io/kaniko-test/docker-test-registry:latest", + "Image2": "gcr.io/kaniko-test/kaniko-test-registry:latest", "DiffType": "File", "Diff": { "Adds": null, diff --git a/integration_tests/dockerfiles/config_test_scratch.json b/integration_tests/dockerfiles/config_test_scratch.json new file mode 100644 index 000000000..b9b8930fe --- /dev/null +++ b/integration_tests/dockerfiles/config_test_scratch.json @@ -0,0 +1,12 @@ +[ + { + "Image1": "gcr.io/kaniko-test/docker-test-scratch:latest", + "Image2": "gcr.io/kaniko-test/kaniko-test-scratch:latest", + "DiffType": "File", + "Diff": { + "Adds": null, + "Dels": null, + "Mods": null + } + } +] \ No newline at end of file diff --git a/integration_tests/integration_test_yaml.go b/integration_tests/integration_test_yaml.go index a543eb963..c73bb9326 100644 --- a/integration_tests/integration_test_yaml.go +++ b/integration_tests/integration_test_yaml.go @@ -127,6 +127,14 @@ var fileTests = []struct { kanikoContext: buildcontextPath, repo: "test-onbuild", }, + { + description: "test scratch", + dockerfilePath: "/workspace/integration_tests/dockerfiles/Dockerfile_test_scratch", + configPath: "/workspace/integration_tests/dockerfiles/config_test_scratch.json", + dockerContext: buildcontextPath, + kanikoContext: buildcontextPath, + repo: "test-scratch", + }, } var structureTests = []struct { diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 004bb3c89..00185eaca 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -39,4 +39,7 @@ const ( // BuildContextDir is the directory a build context will be unpacked into, // for example, a tarball from a GCS bucket will be unpacked here BuildContextDir = "/kaniko/buildcontext/" + + // NoBaseImage is the scratch image + NoBaseImage = "scratch" ) diff --git a/pkg/image/image.go b/pkg/image/image.go index f458ab1f1..4b9354abe 100644 --- a/pkg/image/image.go +++ b/pkg/image/image.go @@ -18,6 +18,7 @@ package image import ( img "github.com/GoogleCloudPlatform/container-diff/pkg/image" + "github.com/GoogleCloudPlatform/k8s-container-builder/pkg/constants" "github.com/containers/image/copy" "github.com/containers/image/docker" "github.com/containers/image/signature" @@ -30,6 +31,9 @@ import ( // InitializeSourceImage initializes the source image with the base image func NewSourceImage(srcImg string) (*img.MutableSource, error) { + if srcImg == constants.NoBaseImage { + return img.NewMutableSource(nil) + } logrus.Infof("Initializing source image %s", srcImg) ref, err := docker.ParseReference("//" + srcImg) if err != nil { diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index 58815dbe2..df03a4266 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -35,6 +35,15 @@ var volumeWhitelist = []string{} // ExtractFileSystemFromImage pulls an image and unpacks it to a file system at root func ExtractFileSystemFromImage(img string) error { + whitelist, err := fileSystemWhitelist(constants.WhitelistPath) + if err != nil { + return err + } + logrus.Infof("Whitelisted directories are %s", whitelist) + if img == constants.NoBaseImage { + logrus.Info("No base image, nothing to extract") + return nil + } ref, err := docker.ParseReference("//" + img) if err != nil { return err @@ -43,11 +52,6 @@ func ExtractFileSystemFromImage(img string) error { if err != nil { return err } - whitelist, err := fileSystemWhitelist(constants.WhitelistPath) - if err != nil { - return err - } - logrus.Infof("Whitelisted directories are %s", whitelist) return pkgutil.GetFileSystemFromReference(ref, imgSrc, constants.RootDir, whitelist) }