Skip to content

Commit ea41561

Browse files
wkingrh-atomic-bot
authored andcommitted
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
1 parent 3b02a13 commit ea41561

File tree

5 files changed

+184
-165
lines changed

5 files changed

+184
-165
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ binaries: varlink_generate podman python-podman
154154

155155
test-binaries: test/bin2img/bin2img test/copyimg/copyimg test/checkseccomp/checkseccomp
156156

157-
MANPAGES_MD ?= $(wildcard docs/*.md)
157+
MANPAGES_MD ?= $(wildcard docs/*.md pkg/*/docs/*.md)
158158
MANPAGES ?= $(MANPAGES_MD:%.md=%)
159159

160160
$(MANPAGES): %: %.md .gopathok

contrib/spec/podman.spec.in

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ providing packages with %{import_path} prefix.
361361
%prep
362362
%autosetup -Sgit -n podman-%{shortcommit}
363363
sed -i '/\/bin\/env/d' completions/bash/%{name}
364-
mv pkg/hooks/README.md pkg/hooks/README-hooks.md
365364

366365
%build
367366
mkdir _build
@@ -459,7 +458,7 @@ export GOPATH=%{buildroot}/%{gopath}:$(pwd)/vendor:%{gopath}
459458

460459
%files
461460
%license LICENSE
462-
%doc README.md CONTRIBUTING.md pkg/hooks/README-hooks.md install.md code-of-conduct.md transfer.md
461+
%doc README.md CONTRIBUTING.md install.md code-of-conduct.md transfer.md
463462
%{_bindir}/%{name}
464463
%{_mandir}/man1/*.1*
465464
%{_mandir}/man5/*.5*
@@ -477,14 +476,14 @@ export GOPATH=%{buildroot}/%{gopath}:$(pwd)/vendor:%{gopath}
477476
%if 0%{?with_devel}
478477
%files -n libpod-devel -f devel.file-list
479478
%license LICENSE
480-
%doc README.md CONTRIBUTING.md pkg/hooks/README-hooks.md install.md code-of-conduct.md transfer.md
479+
%doc README.md CONTRIBUTING.md install.md code-of-conduct.md transfer.md
481480
%dir %{gopath}/src/%{provider}.%{provider_tld}/%{project}
482481
%endif
483482

484483
%if 0%{?with_unit_test} && 0%{?with_devel}
485484
%files unit-test-devel -f unit-test-devel.file-list
486485
%license LICENSE
487-
%doc README.md CONTRIBUTING.md pkg/hooks/README-hooks.md install.md code-of-conduct.md transfer.md
486+
%doc README.md CONTRIBUTING.md install.md code-of-conduct.md transfer.md
488487
%endif
489488

490489
%changelog

pkg/hooks/README.md

Lines changed: 1 addition & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -11,170 +11,11 @@ For example the [oci-systemd-hook][] only executes if the command is `init` or `
1111
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.
1212
Performance would also suffer if we exectuted each hook at each stage ([pre-start][], [post-start][], and [post-stop][]).
1313

14-
## Notational Conventions
14+
The hooks configuration is documented in [`oci-hooks.5`][docs/oci-hooks.5.md].
1515

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`:
54-
55-
```console
56-
$ cat /etc/containers/oci/hooks.d/oci-systemd-hook.json
57-
{
58-
"version": "1.0.0",
59-
"hook": {
60-
"path": "/usr/libexec/oci/hooks.d/oci-systemd-hook"
61-
}
62-
"when": {
63-
"args": [".*/init$" , ".*/systemd$"],
64-
},
65-
"stages": ["prestart", "poststop"]
66-
}
67-
```
68-
69-
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.*`.
87-
88-
```console
89-
$ cat /etc/containers/oci/hooks.d/nvidia.json
90-
{
91-
"hook": {
92-
"path": "/usr/sbin/nvidia-container-runtime-hook",
93-
"args": ["nvidia-container-runtime-hook", "prestart"],
94-
"env": [
95-
"NVIDIA_REQUIRE_CUDA=cuda>=9.1",
96-
"NVIDIA_VISIBLE_DEVICES=GPU-fef8089b"
97-
]
98-
},
99-
"when": {
100-
"annotations": {
101-
"^com\.example\.department$": ".*fluid-dynamics$"
102-
}
103-
},
104-
"stages": ["prestart"]
105-
}
106-
```
107-
108-
### 0.1.0 Hook Schema
109-
110-
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`:
129-
130-
```console
131-
$ cat /etc/containers/oci/hooks.d/oci-systemd-hook.json
132-
{
133-
"cmds": [".*/init$" , ".*/systemd$"],
134-
"hook": "/usr/libexec/oci/hooks.d/oci-systemd-hook",
135-
"stages": ["prestart", "poststop"]
136-
}
137-
```
138-
139-
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.*`.
152-
153-
```console
154-
$ cat /etc/containers/oci/hooks.d/osystemd-hook.json
155-
{
156-
"hook": "/usr/sbin/nvidia-container-runtime-hook",
157-
"arguments": ["prestart"],
158-
"annotations: [".*fluid-dynamics.*"],
159-
"stages": ["prestart"]
160-
}
161-
```
162-
163-
[JSON]: https://tools.ietf.org/html/rfc8259
164-
[LANG]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_02
165-
[LC_ALL]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_02
166-
[LC_COLLATE]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_02
167-
[LC_COLLATE-POSIX]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_02_06
168-
[nvidia-container-runtime-hook]: https://github.com/NVIDIA/nvidia-container-runtime/tree/master/hook/nvidia-container-runtime-hook
16916
[oci-systemd-hook]: https://github.com/projectatomic/oci-systemd-hook
170-
[oci-umount]: https://github.com/projectatomic/oci-umount
171-
[POSIX-ERE]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04
17217
[post-start]: https://github.com/opencontainers/runtime-spec/blob/v1.0.1/config.md#poststart
17318
[post-stop]: https://github.com/opencontainers/runtime-spec/blob/v1.0.1/config.md#poststop
17419
[pre-start]: https://github.com/opencontainers/runtime-spec/blob/v1.0.1/config.md#prestart
175-
[rfc2119]: http://tools.ietf.org/html/rfc2119
176-
[runc]: https://github.com/opencontainers/runc
17720
[runtime-spec]: https://github.com/opencontainers/runtime-spec/blob/v1.0.1/spec.md
178-
[spec-annotations]: https://github.com/opencontainers/runtime-spec/blob/v1.0.1/config.md#annotations
17921
[spec-hooks]: https://github.com/opencontainers/runtime-spec/blob/v1.0.1/config.md#posix-platform-hooks
180-
[spec-process]: https://github.com/opencontainers/runtime-spec/blob/v1.0.1/config.md#process

pkg/hooks/docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.5

pkg/hooks/docs/oci-hooks.5.md

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
% oci-hooks(5) OCI Hooks Configuration
2+
% W. Trevor King
3+
% MAY 2018
4+
5+
# NAME
6+
7+
oci-hooks - OCI hooks configuration directories
8+
9+
# SYNOPSIS
10+
11+
`/usr/share/containers/oci/hooks.d/*.json`
12+
13+
# DESCRIPTION
14+
15+
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`:
81+
82+
```console
83+
$ cat /etc/containers/oci/hooks.d/oci-systemd-hook.json
84+
{
85+
"version": "1.0.0",
86+
"hook": {
87+
"path": "/usr/libexec/oci/hooks.d/oci-systemd-hook"
88+
}
89+
"when": {
90+
"args": [".*/init$" , ".*/systemd$"],
91+
},
92+
"stages": ["prestart", "poststop"]
93+
}
94+
```
95+
96+
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.*`.
114+
115+
```console
116+
$ cat /etc/containers/oci/hooks.d/nvidia.json
117+
{
118+
"hook": {
119+
"path": "/usr/sbin/nvidia-container-runtime-hook",
120+
"args": ["nvidia-container-runtime-hook", "prestart"],
121+
"env": [
122+
"NVIDIA_REQUIRE_CUDA=cuda>=9.1",
123+
"NVIDIA_VISIBLE_DEVICES=GPU-fef8089b"
124+
]
125+
},
126+
"when": {
127+
"annotations": {
128+
"^com\.example\.department$": ".*fluid-dynamics$"
129+
}
130+
},
131+
"stages": ["prestart"]
132+
}
133+
```
134+
135+
## 0.1.0 Hook Schema
136+
137+
The following configuration injects `oci-systemd-hook` in the pre-start and post-stop stages if `process.args[0]` ends with `/init` or `/systemd`:
138+
139+
```console
140+
$ cat /etc/containers/oci/hooks.d/oci-systemd-hook.json
141+
{
142+
"cmds": [".*/init$" , ".*/systemd$"],
143+
"hook": "/usr/libexec/oci/hooks.d/oci-systemd-hook",
144+
"stages": ["prestart", "poststop"]
145+
}
146+
```
147+
148+
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.*`.
161+
162+
```console
163+
$ cat /etc/containers/oci/hooks.d/osystemd-hook.json
164+
{
165+
"hook": "/usr/sbin/nvidia-container-runtime-hook",
166+
"arguments": ["prestart"],
167+
"annotations: [".*fluid-dynamics.*"],
168+
"stages": ["prestart"]
169+
}
170+
```
171+
172+
# SEE ALSO
173+
174+
`oci-systemd-hook(1)`, `oci-umount(1)`, `locale(7)`
175+
176+
* [OCI Runtime Specification, 1.0.1, POSIX-platform hooks](https://github.com/opencontainers/runtime-spec/blob/v1.0.1/config.md#posix-platform-hooks)
177+
* [OCI Runtime Specification, 1.0.1, process](https://github.com/opencontainers/runtime-spec/blob/v1.0.1/config.md#process)
178+
* [POSIX extended regular expressions (EREs)](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04)

0 commit comments

Comments
 (0)