Fixed merge conflict, added validation

This commit is contained in:
Priya Wadhwa
2018-04-12 10:30:25 -07:00
31 changed files with 653 additions and 108 deletions
+3 -3
View File
@@ -25,7 +25,7 @@ import (
"path/filepath"
)
// UnpackTarFromGCSBucket unpacks the kbuild.tar file in the given bucket to the given directory
// UnpackTarFromGCSBucket unpacks the context.tar.gz file in the given bucket to the given directory
func UnpackTarFromGCSBucket(bucketName, directory string) error {
// Get the tar from the bucket
tarPath, err := getTarFromBucket(bucketName, directory)
@@ -41,7 +41,7 @@ func UnpackTarFromGCSBucket(bucketName, directory string) error {
return os.Remove(tarPath)
}
// getTarFromBucket gets kbuild.tar from the GCS bucket and saves it to the filesystem
// getTarFromBucket gets context.tar.gz from the GCS bucket and saves it to the filesystem
// It returns the path to the tar file
func getTarFromBucket(bucketName, directory string) (string, error) {
ctx := context.Background()
@@ -50,7 +50,7 @@ func getTarFromBucket(bucketName, directory string) (string, error) {
return "", err
}
bucket := client.Bucket(bucketName)
// Get the tarfile kbuild.tar from the GCS bucket, and save it to a tar object
// Get the tarfile context.tar.gz from the GCS bucket, and save it to a tar object
reader, err := bucket.Object(constants.ContextTar).NewReader(ctx)
if err != nil {
return "", err
+21 -1
View File
@@ -30,7 +30,8 @@ import (
"time"
)
var whitelist = []string{"/kbuild"}
var whitelist = []string{"/kaniko"}
var volumeWhitelist = []string{}
// ExtractFileSystemFromImage pulls an image and unpacks it to a file system at root
func ExtractFileSystemFromImage(img string) error {
@@ -156,6 +157,25 @@ func CreateFile(path string, reader io.Reader, perm os.FileMode) error {
return dest.Chmod(perm)
}
// AddPathToVolumeWhitelist adds the given path to the volume whitelist
// It will get snapshotted when the VOLUME command is run then ignored
// for subsequent commands.
func AddPathToVolumeWhitelist(path string) error {
logrus.Infof("adding %s to volume whitelist", path)
volumeWhitelist = append(volumeWhitelist, path)
return nil
}
// MoveVolumeWhitelistToWhitelist copies over all directories that were volume mounted
// in this step to be whitelisted for all subsequent docker commands.
func MoveVolumeWhitelistToWhitelist() error {
if len(volumeWhitelist) > 0 {
whitelist = append(whitelist, volumeWhitelist...)
volumeWhitelist = []string{}
}
return nil
}
// DownloadFileToDest downloads the file at rawurl to the given dest for the ADD command
// From add command docs:
// 1. If <src> is a remote file URL:
+6 -6
View File
@@ -46,7 +46,7 @@ func Test_fileSystemWhitelist(t *testing.T) {
}
actualWhitelist, err := fileSystemWhitelist(path)
expectedWhitelist := []string{"/kbuild", "/proc", "/dev", "/dev/pts", "/sys"}
expectedWhitelist := []string{"/kaniko", "/proc", "/dev", "/dev/pts", "/sys"}
sort.Strings(actualWhitelist)
sort.Strings(expectedWhitelist)
testutil.CheckErrorAndDeepEqual(t, false, err, expectedWhitelist, actualWhitelist)
@@ -61,7 +61,7 @@ var tests = []struct {
files: map[string]string{
"/workspace/foo/a": "baz1",
"/workspace/foo/b": "baz2",
"/kbuild/file": "file",
"/kaniko/file": "file",
},
directory: "/workspace/foo/",
expectedFiles: []string{
@@ -84,7 +84,7 @@ var tests = []struct {
"/workspace/foo/a": "baz1",
"/workspace/foo/b": "baz2",
"/workspace/baz": "hey",
"/kbuild/file": "file",
"/kaniko/file": "file",
},
directory: "/workspace",
expectedFiles: []string{
@@ -99,16 +99,16 @@ var tests = []struct {
files: map[string]string{
"/workspace/foo/a": "baz1",
"/workspace/foo/b": "baz2",
"/kbuild/file": "file",
"/kaniko/file": "file",
},
directory: "",
expectedFiles: []string{
"workspace/foo/a",
"workspace/foo/b",
"kbuild/file",
"kaniko/file",
"workspace",
"workspace/foo",
"kbuild",
"kaniko",
".",
},
},