Skip to content
This repository was archived by the owner on May 26, 2023. It is now read-only.

Commit aa45e22

Browse files
committed
New buildstep_inspect plugin
Signed-off-by: Tim Waugh <twaugh@redhat.com>
1 parent 246d497 commit aa45e22

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,29 @@ to each inspector function specified in `inspector_funk`.
4747

4848
The `plugins` argument is a list, so one can specify multiple plugins to
4949
inspect.
50+
51+
For inspecting the workflow state at the build-step phase, the
52+
`build_inspect.py` plugin is provided. This can be told whether to
53+
succeed or fail by passing arguments as appropriate when it is
54+
declared in the buildstep plugins section. A failing declaration would
55+
be:
56+
57+
```json
58+
{
59+
"name": "buildstep_inspect",
60+
"args": {
61+
"fail_reason": "insufficient memory"
62+
}
63+
}
64+
```
65+
66+
A succeeding declaration would be:
67+
68+
```json
69+
{
70+
"name": "buildstep_inspect",
71+
"args": {
72+
"image_id": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
73+
}
74+
}
75+
```

‎buildstep_inspect.py‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""
2+
Copyright (c) 2017 Red Hat, Inc
3+
All rights reserved.
4+
5+
This software may be modified and distributed under the terms
6+
of the BSD license. See the LICENSE file for details.
7+
"""
8+
9+
from __future__ import unicode_literals
10+
from __future__ import print_function
11+
12+
from atomic_reactor.plugin import BuildStepPlugin
13+
from atomic_reactor.build import BuildResult
14+
15+
16+
class BuildStepInspectPlugin(BuildStepPlugin):
17+
"""
18+
Log the inputs to the build-step plugin
19+
"""
20+
21+
key = 'buildstep_inspect'
22+
is_allowed_to_fail = True
23+
24+
def __init__(self, tasker, workflow, fail_reason=None, image_id=None):
25+
"""
26+
"""
27+
super(BuildStepInspectPlugin, self).__init__(tasker, workflow)
28+
29+
logs = [
30+
"Step 1 : FROM sha256:<...>",
31+
"---> <...>",
32+
"Step 2 : CMD /bin/bash",
33+
"---> Running in <...>",
34+
"---> <...>",
35+
"Removing intermediate container <...>",
36+
]
37+
38+
if image_id is not None:
39+
final_line = "Successfully built {}".format(image_id)
40+
else:
41+
final_line = "Build failed"
42+
43+
logs.append(final_line)
44+
self.build_result = BuildResult(logs=logs,
45+
fail_reason=fail_reason,
46+
image_id=image_id)
47+
48+
def run(self):
49+
"""
50+
Run plugin, logging self.workflow.builder information
51+
"""
52+
53+
for line in [
54+
"Build directory: {}".format(self.workflow.builder.df_dir),
55+
"Dockerfile path: {}".format(self.workflow.builder.df_path),
56+
"Image to build: {}".format(self.workflow.builder.image),
57+
]:
58+
self.log.info(line)
59+
60+
return self.build_result

0 commit comments

Comments
 (0)