|
1 | 1 | # Sarus Hooks - OCI hooks for HPC use cases |
2 | 2 |
|
3 | | -## Build |
| 3 | +## Building the hooks |
4 | 4 | 1. Ensure the `dep/rapidjson` Git submodule is correctly initialized |
5 | 5 | 2. Enter one of the Dev Containers, either through a supporting tool (e.g. VSCode) or by starting the container manually |
6 | 6 | 3. Install libsarus headers and library in paths visible to build tools (e.g. `/usr/include` and `/usr/lib` respectively) |
|
10 | 10 | make -j |
11 | 11 | ``` |
12 | 12 |
|
| 13 | + |
| 14 | +## Usage Tips |
| 15 | + |
| 16 | +Hooks are configured via a configuration json, each hook has its own configuration file and it allows it to control when and how the hook is executed for containers that require the functionality within the lifecycle stage of the container. |
| 17 | + |
| 18 | +Hook configuration are kept in a common directory, the Hook configuration files (ending in .json) are executed in order by json file. Using file names that facilitate ordering is recommended (e.g. 01-mount.json, 02-ldcache.json, ...) |
| 19 | + |
| 20 | +### 1.0.0 Hook Schema (ref: https://github.com/containers/common/blob/main/pkg/hooks/docs/oci-hooks.5.md#100-hook-schema) |
| 21 | + |
| 22 | +- **version** (required string) – Sets the hook-definition version. For this schema version, the value should be `1.0.0`. |
| 23 | +- **hook** (required object) – The hook to inject, with the hook-entry schema defined by the 1.0.2 OCI Runtime Specification. |
| 24 | +- **when** (required object) – Conditions under which the hook is injected. At least one of the following properties must be specified: |
| 25 | + - **always** (optional boolean) – If set true, this condition matches. |
| 26 | + - **annotations** (optional object) – If all annotations key/value pairs match a key/value pair from the configured annotations, this condition matches. Both keys and values must be POSIX extended regular expressions. |
| 27 | + - **commands** (optional array of strings) – If the configured `process.args[0]` matches an entry, this condition matches. Entries must be POSIX extended regular expressions. |
| 28 | + - **hasBindMounts** (optional boolean) – If `hasBindMounts` is true and the caller requested host-to-container bind mounts, this condition matches. |
| 29 | +- **stages** (required array of strings) – Stages when the hook must be injected. Entries must be chosen from the 1.0.2 OCI Runtime Specification hook stages or from extension stages supported by the package consumer. |
| 30 | + |
| 31 | +If all of the conditions set in when match, then the hook must be injected for the stages set in stages. |
| 32 | + |
| 33 | +### Example |
| 34 | +~~~ |
| 35 | +{ |
| 36 | + "version": "1.0.0", |
| 37 | + "hook": { |
| 38 | + "path": "/scratch/local/podman-hooks/bin/mount_hook", |
| 39 | + "args": ["mount_hook", |
| 40 | + "--mount=type=bind,src=${HOME},dst=/mnt/hostbind,readonly" |
| 41 | + ], |
| 42 | + "env": [ |
| 43 | + "LDCONFIG_PATH=/sbin/ldconfig" |
| 44 | + ] |
| 45 | + }, |
| 46 | + "when": { |
| 47 | + "always": true |
| 48 | + }, |
| 49 | + "stages": ["createContainer"] |
| 50 | +} |
| 51 | +~~~ |
| 52 | + |
| 53 | +### Debug Hooks in Podman |
| 54 | + |
| 55 | +Hooks can generate log output at different debug levels. Moreover, the crun container runtime has mechanisms that allow to recover the stdout and stderr of hooks via annotations, this can be done with podman as follows, assuming that we keep the hook configuration json under a dir TMP_HOOKS_DIR: |
| 56 | + |
| 57 | +~~~ |
| 58 | + podman --runtime="crun" \ |
| 59 | + --hooks-dir "${TMP_HOOKS_DIR}" \ |
| 60 | + run --rm \ |
| 61 | + --annotation com.hooks.logging.level=0 \ |
| 62 | + --annotation run.oci.hooks.stdout="/tmp/hook.out" \ |
| 63 | + --annotation run.oci.hooks.stderr="/tmp/hook.err" \ |
| 64 | + ubuntu:22:04 bash -lc "ls /" |
| 65 | +~~~ |
| 66 | + |
13 | 67 | ## TODO |
14 | 68 | - Fix build of unit tests |
15 | 69 | - Fix build of Dropbear |
16 | 70 | - Fix installation directory |
17 | 71 | - Build with static libsarus |
18 | 72 | - Integration tests |
19 | | - |
20 | | - |
|
0 commit comments