@@ -37,8 +37,12 @@ var ociHook = cli.Command{
3737 if err != nil {
3838 return err
3939 }
40+ spec , err := loadSpec (state .Bundle )
41+ if err != nil {
42+ return err
43+ }
4044 var (
41- ctx = newTemplateContext (state )
45+ ctx = newTemplateContext (state , spec )
4246 args = []string (context .Args ())
4347 env = os .Environ ()
4448 )
@@ -52,6 +56,25 @@ var ociHook = cli.Command{
5256 },
5357}
5458
59+ type hookSpec struct {
60+ Root struct {
61+ Path string `json:"path"`
62+ } `json:"root"`
63+ }
64+
65+ func loadSpec (bundle string ) (* hookSpec , error ) {
66+ f , err := os .Open (filepath .Join (bundle , "config.json" ))
67+ if err != nil {
68+ return nil , err
69+ }
70+ defer f .Close ()
71+ var s hookSpec
72+ if err := json .NewDecoder (f ).Decode (& s ); err != nil {
73+ return nil , err
74+ }
75+ return & s , nil
76+ }
77+
5578func loadHookState (r io.Reader ) (* specs.State , error ) {
5679 var s specs.State
5780 if err := json .NewDecoder (r ).Decode (& s ); err != nil {
@@ -60,9 +83,10 @@ func loadHookState(r io.Reader) (*specs.State, error) {
6083 return & s , nil
6184}
6285
63- func newTemplateContext (state * specs.State ) * templateContext {
86+ func newTemplateContext (state * specs.State , spec * hookSpec ) * templateContext {
6487 t := & templateContext {
6588 state : state ,
89+ root : spec .Root .Path ,
6690 }
6791 t .funcs = template.FuncMap {
6892 "id" : t .id ,
@@ -77,6 +101,7 @@ func newTemplateContext(state *specs.State) *templateContext {
77101
78102type templateContext struct {
79103 state * specs.State
104+ root string
80105 funcs template.FuncMap
81106}
82107
@@ -89,7 +114,10 @@ func (t *templateContext) bundle() string {
89114}
90115
91116func (t * templateContext ) rootfs () string {
92- return filepath .Join (t .state .Bundle , "rootfs" )
117+ if filepath .IsAbs (t .root ) {
118+ return t .root
119+ }
120+ return filepath .Join (t .state .Bundle , t .root )
93121}
94122
95123func (t * templateContext ) pid () int {
0 commit comments