Make mtime flag enum
This commit is contained in:
parent
e6eb5d1abf
commit
591fef5d85
|
|
@ -33,7 +33,7 @@ var (
|
|||
dockerfilePath string
|
||||
destination string
|
||||
srcContext string
|
||||
mtime bool
|
||||
mtime 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(&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().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")
|
||||
}
|
||||
|
||||
|
|
@ -76,12 +76,8 @@ func execute() error {
|
|||
if err := util.ExtractFileSystemFromImage(baseImage); err != nil {
|
||||
return err
|
||||
}
|
||||
hasher := util.Hasher()
|
||||
if mtime {
|
||||
logrus.Info("Only file modification times will be considered when snapshotting.")
|
||||
hasher = util.MtimeHasher()
|
||||
}
|
||||
l := snapshot.NewLayeredMap(hasher)
|
||||
|
||||
l := snapshot.NewLayeredMap(getHasher())
|
||||
snapshotter := snapshot.NewSnapshotter(l, constants.RootDir)
|
||||
|
||||
// Take initial snapshot
|
||||
|
|
@ -131,3 +127,11 @@ func execute() error {
|
|||
// Push the image
|
||||
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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ var fileTests = []struct {
|
|||
configPath string
|
||||
context string
|
||||
repo string
|
||||
mtime bool
|
||||
mtime string
|
||||
}{
|
||||
{
|
||||
description: "test extract filesystem",
|
||||
|
|
@ -36,7 +36,7 @@ var fileTests = []struct {
|
|||
configPath: "/workspace/integration_tests/dockerfiles/config_test_extract_fs.json",
|
||||
context: "integration_tests/dockerfiles/",
|
||||
repo: "extract-filesystem",
|
||||
mtime: true,
|
||||
mtime: "time",
|
||||
},
|
||||
{
|
||||
description: "test run",
|
||||
|
|
@ -51,7 +51,7 @@ var fileTests = []struct {
|
|||
configPath: "/workspace/integration_tests/dockerfiles/config_test_run_2.json",
|
||||
context: "integration_tests/dockerfiles/",
|
||||
repo: "test-run-2",
|
||||
mtime: true,
|
||||
mtime: "time",
|
||||
},
|
||||
{
|
||||
description: "test copy",
|
||||
|
|
@ -59,7 +59,7 @@ var fileTests = []struct {
|
|||
configPath: "/workspace/integration_tests/dockerfiles/config_test_copy.json",
|
||||
context: "/workspace/integration_tests/",
|
||||
repo: "test-copy",
|
||||
mtime: true,
|
||||
mtime: "time",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -144,8 +144,8 @@ func main() {
|
|||
// Then, buld the image with kbuild
|
||||
kbuildImage := testRepo + kbuildPrefix + test.repo
|
||||
mtime := ""
|
||||
if test.mtime {
|
||||
mtime = "--mtime"
|
||||
if test.mtime != "" {
|
||||
mtime = "--mtime=" + test.mtime
|
||||
}
|
||||
kbuild := step{
|
||||
Name: executorImage,
|
||||
|
|
|
|||
Loading…
Reference in New Issue