mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-19 13:41:08 +02:00
Add support for scratch images, and integration test
This commit is contained in:
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+9
-5
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user