Skip to content

Commit 7a733e6

Browse files
committed
ccon-oci: Stub in initial support for hooks
ccon doesn't believe in container IDs, so this still needs some work before it will feed OCI-specified state JSON into the hook's stdin. The hook syntax (with argv[0] in args) doesn't quite match the v0.1.0 docs [1,2], but it does match the phrasing from opencontainers/runtime-spec#255 which was claimed to "clarify, but not change" the semantics [3,4]. I think that the v0.1.0 phrasing wasn't clear enough to decide if #255 was a change or not, but since it wasn't clear, there's no more harm in just going with Qiang and Mrunal's interpretation. [1]: https://github.com/opencontainers/specs/blob/v0.1.1/runtime.md#post-stop [2]: https://groups.google.com/a/opencontainers.org/forum/#!topic/dev/luaaorsya10 Subject: Explicit args[0] for hooks? Date: Sat, 15 Aug 2015 12:15:23 -0700 Message-ID: <[email protected]> [3]: opencontainers/runtime-spec#255 (comment) [4]: opencontainers/runtime-spec#255 (comment)
1 parent ff8d159 commit 7a733e6

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

ccon-oci

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ def _convert_root(basedir, root):
153153
]
154154

155155

156+
def _convert_hook(hook):
157+
h = {
158+
'args': hook.pop('args', [hook['path']]),
159+
}
160+
if hook['path'] != h['args'][0]:
161+
h['path'] = hook['path']
162+
if 'env' in hook:
163+
h['env'] = hook.pop('env')
164+
return h
165+
166+
156167
def convert_config(basedir, config, runtime):
157168
version = config.pop('version')
158169
if version not in ['0.1.0']:
@@ -217,6 +228,21 @@ def convert_config(basedir, config, runtime):
217228
capabilities = config.get('linux', {}).pop('capabilities', None)
218229
if capabilities:
219230
c['process']['capabilities'] = capabilities
231+
hooks = runtime.pop('hooks', None)
232+
if hooks:
233+
pre_start = hooks.pop('prestart', None)
234+
if pre_start:
235+
c['hooks'] = {
236+
'pre-start': [_convert_hook(hook=h) for h in pre_start],
237+
}
238+
post_stop = hooks.pop('poststop', None)
239+
if post_stop:
240+
if 'hooks' not in c:
241+
c['hooks'] = {}
242+
c['hooks']['post-stop'] = [_convert_hook(hook=h) for h in post_stop]
243+
if hooks:
244+
raise NotImplementedError(
245+
'unparsed config.json hooks: {}'.format(hooks))
220246
hostname = config.pop('hostname', None)
221247
# TODO: inject hostname-setting hook
222248
if 'linux' in config and not config['linux']:

examples/good/oci/0.1.0/runtime.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@
66
"options": ["rbind", "rw"]
77
}
88
},
9+
"hooks": {
10+
"prestart": [
11+
{
12+
"path": "/bin/sh",
13+
"args": ["/bin/sh", "-c", "echo 'pre-start'; env; cat"],
14+
"env": [
15+
"PATH=/bin",
16+
"PAGER=less"
17+
]
18+
}
19+
],
20+
"poststop": [
21+
{
22+
"path": "/bin/sh",
23+
"args": ["sh", "-c", "echo 'post-stop'; env;"],
24+
"env": [
25+
"PATH=/bin",
26+
"PAGER=less"
27+
]
28+
}
29+
]
30+
},
931
"linux": {
1032
"namespaces": [
1133
{

0 commit comments

Comments
 (0)