@@ -16,6 +16,7 @@ import (
1616
1717var bundleValidateFlags = []cli.Flag {
1818 cli.StringFlag {Name : "path" , Usage : "path to a bundle" },
19+ cli.BoolFlag {Name : "hooks-check" , Usage : "Specify check hooks on host, default is false" },
1920}
2021
2122var (
@@ -72,18 +73,23 @@ var bundleValidateCommand = cli.Command{
7273 logrus .Fatalf ("Rootfs: %v is not a directory." , spec .Root .Path )
7374 }
7475
75- bundleValidate (spec , rootfsPath )
76+ hooksCheck := context .Bool ("hooks-check" )
77+ bundleValidate (spec , rootfsPath , hooksCheck )
7678 logrus .Infof ("Bundle validation succeeded." )
7779 },
7880}
7981
80- func bundleValidate (spec rspec.Spec , rootfs string ) {
82+ func bundleValidate (spec rspec.Spec , rootfs string , hooksCheck bool ) {
8183 checkMandatoryField (spec )
8284 checkSemVer (spec .Version )
8385 checkPlatform (spec .Platform )
8486 checkProcess (spec .Process , rootfs )
8587 checkMounts (spec .Mounts , rootfs )
8688 checkLinux (spec .Linux , rootfs )
89+
90+ if hooksCheck {
91+ checkHooks (spec .Hooks )
92+ }
8793}
8894
8995func checkSemVer (version string ) {
@@ -128,6 +134,26 @@ func checkPlatform(platform rspec.Platform) {
128134 logrus .Fatalf ("Operation system '%s' of the bundle is not supported yet." , platform .OS )
129135}
130136
137+ func checkHooks (hooks rspec.Hooks ) {
138+ for _ , prestart := range hooks .Prestart {
139+ if _ , err := os .Stat (prestart .Path ); err != nil {
140+ logrus .Fatalf ("Cannot find pre-start hook: %v" , prestart .Path )
141+ }
142+ }
143+
144+ for _ , poststart := range hooks .Poststart {
145+ if _ , err := os .Stat (poststart .Path ); err != nil {
146+ logrus .Fatalf ("Cannot find post-start hook: %v" , poststart .Path )
147+ }
148+ }
149+
150+ for _ , poststop := range hooks .Poststop {
151+ if _ , err := os .Stat (poststop .Path ); err != nil {
152+ logrus .Fatalf ("Cannot find post-stop hook: %v" , poststop .Path )
153+ }
154+ }
155+ }
156+
131157func checkProcess (process rspec.Process , rootfs string ) {
132158 for index := 0 ; index < len (process .Capabilities ); index ++ {
133159 capability := process .Capabilities [index ]
0 commit comments