You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hooks/docs: Add oci-hooks.5 and per-package man page building
This allows us to reference the hooks docs from podman(1) in a way
that will survive system installation. The downside is that the
GitHub rendered pages become less usable, now that we can no longer
embed links as freely as we could before.
I've followed the "Sections within a manual page" suggestions from
[1].
locale(7) is [2], which is Linux-specific. Even section numbering is
platform-dependent [3], so it's unlikely that these external man
references are particularly portable. Platform packagers can adjust
our local references to match their target system, but that leaves the
GitHub rendering in an awkward place. For now, I think a
Linux-centric GitHub rendering without clickable links may be the best
we can do without moving away from go-md2man.
As far as I can tell, there's not a nice way to get go-md2man to wrap
the links in SEE ALSO without sometimes hyphenating a URL (which makes
it harder for man-page readers to copy/paste those links into their
browser).
I've also fixed some "extention" -> "extension" typos.
[1]: http://man7.org/linux/man-pages/man7/man-pages.7.html
[2]: http://man7.org/linux/man-pages/man7/locale.7.html
[3]: https://en.wikipedia.org/wiki/Man_page#Manual_sections
Signed-off-by: W. Trevor King <[email protected]>
Closes: #772
Approved by: mheon
Copy file name to clipboardExpand all lines: pkg/hooks/README.md
+1-160Lines changed: 1 addition & 160 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,170 +11,11 @@ For example the [oci-systemd-hook][] only executes if the command is `init` or `
11
11
This means if we automatically enabled all hooks, every container would have to execute `oci-systemd-hook`, even if they don't run systemd inside of the container.
12
12
Performance would also suffer if we exectuted each hook at each stage ([pre-start][], [post-start][], and [post-stop][]).
13
13
14
-
## Notational Conventions
14
+
The hooks configuration is documented in [`oci-hooks.5`][docs/oci-hooks.5.md].
15
15
16
-
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" are to be interpreted as described in [RFC 2119][rfc2119].
17
-
18
-
## JSON Definition
19
-
20
-
This package reads all [JSON][] files (ending with a `.json` extention) from a series of hook directories.
21
-
For both `crio` and `podman`, hooks are read from `/usr/share/containers/oci/hooks.d/*.json`.
22
-
23
-
For `crio`, hook JSON is also read from `/etc/containers/oci/hooks.d/*.json`.
24
-
If files of with the same name exist in both directories, the one in `/etc/containers/oci/hooks.d` takes precedence.
25
-
26
-
Hooks MUST be injected in the JSON filename case- and width-insensitive collation order.
27
-
Collation order depends on your locale, as set by [`LC_ALL`][LC_ALL], [`LC_COLLATE`][LC_COLLATE], or [`LANG`][LANG] (in order of decreasing precedence).
28
-
For example, in the [POSIX locale][LC_COLLATE-POSIX], a matching hook defined in `01-my-hook.json` would be injected before matching hooks defined in `02-another-hook.json` and `01-UPPERCASE.json`.
29
-
30
-
Each JSON file should contain an object with the following properties:
31
-
32
-
### 1.0.0 Hook Schema
33
-
34
-
***`version`** (REQUIRED, string) Sets the hook-definition version.
35
-
For this schema version, the value MUST be 1.0.0.
36
-
***`hook`** (REQUIRED, object) The hook to inject, with the [hook-entry schema][spec-hooks] defined by the 1.0.1 OCI Runtime Specification.
37
-
***`when`** (REQUIRED, object) Conditions under which the hook is injected.
38
-
The following properties can be specified:
39
-
40
-
***`always`** (OPTIONAL, boolean) If set `true`, this condition matches.
41
-
***`annotations`** (OPTIONAL, object) If all `annotations` key/value pairs match a key/value pair from the [configured annotations][spec-annotations], this condition matches.
42
-
Both keys and values MUST be [POSIX extended regular expressions][POSIX-ERE].
43
-
***`commands`** (OPTIONAL, array of strings) If the configured [`process.args[0]`][spec-process] matches an entry, this condition matches.
44
-
Entries MUST be [POSIX extended regular expressions][POSIX-ERE].
45
-
***`hasBindMounts`** (OPTIONAL, boolean) If `hasBindMounts` is true and the caller requested host-to-container bind mounts (beyond those that CRI-O or libpod use by default), this condition matches.
46
-
***`stages`** (REQUIRED, array of strings) Stages when the hook MUST be injected.
47
-
Entries MUST be chosen from the 1.0.1 OCI Runtime Specification [hook stages][spec-hooks] or from extention stages supported by the package consumer.
48
-
49
-
If *all* of the conditions set in `when` match, then the `hook` MUST be injected for the stages set in `stages`.
50
-
51
-
#### Example
52
-
53
-
The following configuration injects [`oci-systemd-hook`][oci-systemd-hook] in the [pre-start][] and [post-stop][] stages if [`process.args[0]`][spec-process] ends with `/init` or `/systemd`:
The following example injects [`oci-umount --debug`][oci-umount] in the [pre-start][] phase if the container is configured to bind-mount host directories into the container.
70
-
71
-
```console
72
-
$ cat /etc/containers/oci/hooks.d/oci-umount.json
73
-
{
74
-
"version": "1.0.0",
75
-
"hook": {
76
-
"path": "/usr/libexec/oci/hooks.d/oci-umount",
77
-
"args": ["oci-umount", "--debug"],
78
-
}
79
-
"when": {
80
-
"hasBindMounts": true,
81
-
},
82
-
"stages": ["prestart"]
83
-
}
84
-
```
85
-
86
-
The following example injects [`nvidia-container-runtime-hook prestart`][nvidia-container-runtime-hook] with particular environment variables in the [pre-start][] phase if the container is configured with an `annotations` entry whose key matches `^com\.example\.department$` and whose value matches `.*fluid-dynamics.*`.
Previous versions of CRI-O and libpod supported the 0.1.0 hook schema:
111
-
112
-
***`hook`** (REQUIRED, string) Sets [`path`][spec-hooks] in the injected hook.
113
-
***`arguments`** (OPTIONAL, array of strings) Additional arguments to pass to the hook.
114
-
The injected hook's [`args`][spec-hooks] is `hook` with `arguments` appended.
115
-
***`stages`** (REQUIRED, array of strings) Stages when the hook MUST be injected.
116
-
`stage` is an allowed synonym for this property, but you MUST NOT set both `stages` and `stage`.
117
-
Entries MUST be chosen from the 1.0.1 OCI Runtime Specification [hook stages][spec-hooks] or from extention stages supported by the package consumer.
118
-
***`cmds`** (OPTIONAL, array of strings) The hook MUST be injected if the configured [`process.args[0]`][spec-process] matches an entry.
119
-
`cmd` is an allowed synonym for this property, but you MUST NOT set both `cmds` and `cmd`.
120
-
Entries MUST be [POSIX extended regular expressions][POSIX-ERE].
121
-
***`annotations`** (OPTIONAL, array of strings) The hook MUST be injected if an `annotations` entry matches a value from the [configured annotations][spec-annotations].
122
-
`annotation` is an allowed synonym for this property, but you MUST NOT set both `annotations` and `annotation`.
123
-
Entries MUST be [POSIX extended regular expressions][POSIX-ERE].
124
-
***`hasbindmounts`** (OPTIONAL, boolean) The hook MUST be injected if `hasBindMounts` is true and the caller requested host-to-container bind mounts (beyond those that CRI-O or libpod use by default).
125
-
126
-
#### Example
127
-
128
-
The following configuration injects [`oci-systemd-hook`][oci-systemd-hook] in the [pre-start][] and [post-stop][] stages if [`process.args[0]`][spec-process] ends with `/init` or `/systemd`:
The following example injects [`oci-umount --debug`][oci-umount] in the [pre-start][] phase if the container is configured to bind-mount host directories into the container.
140
-
141
-
```console
142
-
$ cat /etc/containers/oci/hooks.d/oci-umount.json
143
-
{
144
-
"hook": "/usr/libexec/oci/hooks.d/oci-umount",
145
-
"arguments": ["--debug"],
146
-
"hasbindmounts": true,
147
-
"stages": ["prestart"]
148
-
}
149
-
```
150
-
151
-
The following example injects [`nvidia-container-runtime-hook prestart`][nvidia-container-runtime-hook] in the [pre-start][] phase if the container is configured with an `annotations` entry whose value matches `.*fluid-dynamics.*`.
Provides a way for users to configure the intended hooks for Open Container Initiative containers so they will only be executed for containers that need their functionality, and then only for the stages where they're needed.
16
+
17
+
## Directories
18
+
19
+
Hooks are configured with JSON files (ending with a `.json` extension) in a series of hook directories.
20
+
The default directory is `/usr/share/containers/oci/hooks.d`, but tools consuming this format may change that default, include additional directories, or provide their callers with ways to adjust the configuration directories.
21
+
22
+
Hooks are injected in the JSON filename case- and width-insensitive collation order.
23
+
Collation order depends on your locale, as set by `LC_ALL`, `LC_COLLATE`, or `LANG` (in order of decreasing precedence).
24
+
For more information, see `locale(7)`.
25
+
For example, in the POSIX locale, a matching hook defined in `01-my-hook.json` would be injected before matching hooks defined in `02-another-hook.json` and `01-UPPERCASE.json`.
26
+
27
+
Each JSON file should contain an object with one of the following schemas.
28
+
29
+
## 1.0.0 Hook Schema
30
+
31
+
`version` (required string)
32
+
Sets the hook-definition version. For this schema version, the value be `1.0.0`.
33
+
34
+
`hook` (required object)
35
+
The hook to inject, with the hook-entry schema defined by the 1.0.1 OCI Runtime Specification.
36
+
37
+
`when` (required object)
38
+
Conditions under which the hook is injected. The following properties can be specified, and at least one must be specified:
39
+
40
+
*`always` (optional boolean)
41
+
If set `true`, this condition matches.
42
+
*`annotations` (optional object)
43
+
If all `annotations` key/value pairs match a key/value pair from the configured annotations, this condition matches.
44
+
Both keys and values must be POSIX extended regular expressions.
45
+
*`commands` (optional array of strings)
46
+
If the configured `process.args[0]` matches an entry, this condition matches.
47
+
Entries must be POSIX extended regular expressions.
48
+
*`hasBindMounts` (optional boolean)
49
+
If `hasBindMounts` is true and the caller requested host-to-container bind mounts, this condition matches.
50
+
51
+
`stages` (required array of strings)
52
+
Stages when the hook must be injected. Entries must be chosen from the 1.0.1 OCI Runtime Specification hook stages or from extension stages supported by the package consumer.
53
+
54
+
If *all* of the conditions set in `when` match, then the `hook` must be injected for the stages set in `stages`.
55
+
56
+
## 0.1.0 Hook Schema
57
+
58
+
`hook` (required string)
59
+
Sets `path` in the injected hook.
60
+
61
+
`arguments` (optional array of strings)
62
+
Additional arguments to pass to the hook. The injected hook's `args` is `hook` with `arguments` appended.
63
+
64
+
`stages` (required array of strings)
65
+
Stages when the hook must be injected. `stage` is an allowed synonym for this property, but you must not set both `stages` and `stage`. Entries must be chosen from the 1.0.1 OCI Runtime Specification hook stages or from extension stages supported by the package consumer.
66
+
67
+
`cmds` (optional array of strings)
68
+
The hook must be injected if the configured `process.args[0]` matches an entry. `cmd` is an allowed synonym for this property, but you must not set both `cmds` and `cmd`. Entries must be POSIX extended regular expressions.
69
+
70
+
`annotations` (optional array of strings)
71
+
The hook must be injected if an `annotations` entry matches a value from the configured annotations. `annotation` is an allowed synonym for this property, but you must not set both `annotations` and `annotation`. Entries must be POSIX extended regular expressions.
72
+
73
+
`hasbindmounts` (optional boolean)
74
+
The hook must be injected if `hasBindMounts` is true and the caller requested host-to-container bind mounts.
75
+
76
+
# EXAMPLE
77
+
78
+
## 1.0.0 Hook Schema
79
+
80
+
The following configuration injects `oci-systemd-hook` in the pre-start and post-stop stages if `process.args[0]` ends with `/init` or `/systemd`:
The following example injects `oci-umount --debug` in the pre-start stage if the container is configured to bind-mount host directories into the container.
97
+
98
+
```console
99
+
$ cat /etc/containers/oci/hooks.d/oci-umount.json
100
+
{
101
+
"version": "1.0.0",
102
+
"hook": {
103
+
"path": "/usr/libexec/oci/hooks.d/oci-umount",
104
+
"args": ["oci-umount", "--debug"],
105
+
}
106
+
"when": {
107
+
"hasBindMounts": true,
108
+
},
109
+
"stages": ["prestart"]
110
+
}
111
+
```
112
+
113
+
The following example injects `nvidia-container-runtime-hook prestart` with particular environment variables in the pre-start stage if the container is configured with an `annotations` entry whose key matches `^com\.example\.department$` and whose value matches `.*fluid-dynamics.*`.
The following example injects `oci-umount --debug` in the pre-start stage if the container is configured to bind-mount host directories into the container.
149
+
150
+
```console
151
+
$ cat /etc/containers/oci/hooks.d/oci-umount.json
152
+
{
153
+
"hook": "/usr/libexec/oci/hooks.d/oci-umount",
154
+
"arguments": ["--debug"],
155
+
"hasbindmounts": true,
156
+
"stages": ["prestart"]
157
+
}
158
+
```
159
+
160
+
The following example injects `nvidia-container-runtime-hook prestart` in the pre-start stage if the container is configured with an `annotations` entry whose value matches `.*fluid-dynamics.*`.
0 commit comments