Make mtime flag enum

This commit is contained in:
Priya Wadhwa 2018-03-28 10:11:21 -07:00
parent e6eb5d1abf
commit 591fef5d85
No known key found for this signature in database
GPG Key ID: 0D0DAFD8F7AA73AE
2 changed files with 18 additions and 14 deletions

View File

@ -33,7 +33,7 @@ var (
dockerfilePath string dockerfilePath string
destination string destination string
srcContext string srcContext string
mtime bool mtime string
logLevel string logLevel string
) )
@ -41,7 +41,7 @@ func init() {
RootCmd.PersistentFlags().StringVarP(&dockerfilePath, "dockerfile", "f", "/workspace/Dockerfile", "Path to the dockerfile to be built.") RootCmd.PersistentFlags().StringVarP(&dockerfilePath, "dockerfile", "f", "/workspace/Dockerfile", "Path to the dockerfile to be built.")
RootCmd.PersistentFlags().StringVarP(&srcContext, "context", "c", "", "Path to the dockerfile build context.") RootCmd.PersistentFlags().StringVarP(&srcContext, "context", "c", "", "Path to the dockerfile build context.")
RootCmd.PersistentFlags().StringVarP(&destination, "destination", "d", "", "Registry the final image should be pushed to (ex: gcr.io/test/example:latest)") RootCmd.PersistentFlags().StringVarP(&destination, "destination", "d", "", "Registry the final image should be pushed to (ex: gcr.io/test/example:latest)")
RootCmd.PersistentFlags().BoolVarP(&mtime, "mtime", "", false, "Only look at mtime of a file when snapshotting") RootCmd.PersistentFlags().StringVarP(&mtime, "mtime", "", "full", "Set this flag to change the file attributes inspected during snapshotting")
RootCmd.PersistentFlags().StringVarP(&logLevel, "verbosity", "v", constants.DefaultLogLevel, "Log level (debug, info, warn, error, fatal, panic") RootCmd.PersistentFlags().StringVarP(&logLevel, "verbosity", "v", constants.DefaultLogLevel, "Log level (debug, info, warn, error, fatal, panic")
} }
@ -76,12 +76,8 @@ func execute() error {
if err := util.ExtractFileSystemFromImage(baseImage); err != nil { if err := util.ExtractFileSystemFromImage(baseImage); err != nil {
return err return err
} }
hasher := util.Hasher()
if mtime { l := snapshot.NewLayeredMap(getHasher())
logrus.Info("Only file modification times will be considered when snapshotting.")
hasher = util.MtimeHasher()
}
l := snapshot.NewLayeredMap(hasher)
snapshotter := snapshot.NewSnapshotter(l, constants.RootDir) snapshotter := snapshot.NewSnapshotter(l, constants.RootDir)
// Take initial snapshot // Take initial snapshot
@ -131,3 +127,11 @@ func execute() error {
// Push the image // Push the image
return image.PushImage(sourceImage, destination) return image.PushImage(sourceImage, destination)
} }
func getHasher() func(string) (string, error) {
if mtime == "time" {
logrus.Info("Only file modification time will be considered when snapshotting")
return util.MtimeHasher()
}
return util.Hasher()
}

View File

@ -28,7 +28,7 @@ var fileTests = []struct {
configPath string configPath string
context string context string
repo string repo string
mtime bool mtime string
}{ }{
{ {
description: "test extract filesystem", description: "test extract filesystem",
@ -36,7 +36,7 @@ var fileTests = []struct {
configPath: "/workspace/integration_tests/dockerfiles/config_test_extract_fs.json", configPath: "/workspace/integration_tests/dockerfiles/config_test_extract_fs.json",
context: "integration_tests/dockerfiles/", context: "integration_tests/dockerfiles/",
repo: "extract-filesystem", repo: "extract-filesystem",
mtime: true, mtime: "time",
}, },
{ {
description: "test run", description: "test run",
@ -51,7 +51,7 @@ var fileTests = []struct {
configPath: "/workspace/integration_tests/dockerfiles/config_test_run_2.json", configPath: "/workspace/integration_tests/dockerfiles/config_test_run_2.json",
context: "integration_tests/dockerfiles/", context: "integration_tests/dockerfiles/",
repo: "test-run-2", repo: "test-run-2",
mtime: true, mtime: "time",
}, },
{ {
description: "test copy", description: "test copy",
@ -59,7 +59,7 @@ var fileTests = []struct {
configPath: "/workspace/integration_tests/dockerfiles/config_test_copy.json", configPath: "/workspace/integration_tests/dockerfiles/config_test_copy.json",
context: "/workspace/integration_tests/", context: "/workspace/integration_tests/",
repo: "test-copy", repo: "test-copy",
mtime: true, mtime: "time",
}, },
} }
@ -144,8 +144,8 @@ func main() {
// Then, buld the image with kbuild // Then, buld the image with kbuild
kbuildImage := testRepo + kbuildPrefix + test.repo kbuildImage := testRepo + kbuildPrefix + test.repo
mtime := "" mtime := ""
if test.mtime { if test.mtime != "" {
mtime = "--mtime" mtime = "--mtime=" + test.mtime
} }
kbuild := step{ kbuild := step{
Name: executorImage, Name: executorImage,