Skip to content

Commit

Permalink
Pass bundle dir as the workdir for hooks exec run function
Browse files Browse the repository at this point in the history
Signed-off-by: Fang-Pen Lin <[email protected]>
  • Loading branch information
fangpenlin committed Jun 28, 2023
1 parent 6589be3 commit 66d5fe4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions run_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ rootless=%d
}

// Setup OCI hooks
_, err = b.setupOCIHooks(spec, (len(options.Mounts) > 0 || len(volumes) > 0))
_, err = b.setupOCIHooks(spec, path, (len(options.Mounts) > 0 || len(volumes) > 0))
if err != nil {
return fmt.Errorf("unable to setup OCI hooks: %w", err)
}
Expand Down Expand Up @@ -379,8 +379,8 @@ rootless=%d
return err
}

func (b *Builder) setupOCIHooks(config *specs.Spec, hasVolumes bool) (map[string][]specs.Hook, error) {
allHooks := make(map[string][]specs.Hook)
func (b *Builder) setupOCIHooks(config *specs.Spec, bundlePath string, hasVolumes bool) (map[string][]specs.Hook, error) {
allHooks := make(map[string][]spec.Hook)
if len(b.CommonBuildOpts.OCIHooksDir) == 0 {
if unshare.IsRootless() {
return nil, nil
Expand Down Expand Up @@ -416,7 +416,15 @@ func (b *Builder) setupOCIHooks(config *specs.Spec, hasVolumes bool) (map[string
}
}

hookErr, err := hooksExec.RuntimeConfigFilter(context.Background(), allHooks["precreate"], config, hooksExec.DefaultPostKillTimeout) //nolint:staticcheck
hookErr, err := hooksExec.RuntimeConfigFilterWithOptions(
context.Background(),
hooksExec.RuntimeConfigFilterOptions{
Hooks: allHooks["precreate"],
Dir: bundlePath,
Config: config,
PostKillTimeout: hooksExec.DefaultPostKillTimeout,
},
)
if err != nil {
logrus.Warnf("Container: precreate hook: %v", err)
if hookErr != nil && hookErr != err {
Expand Down

0 comments on commit 66d5fe4

Please sign in to comment.