Skip to content
This repository was archived by the owner on May 26, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,29 @@ to each inspector function specified in `inspector_funk`.

The `plugins` argument is a list, so one can specify multiple plugins to
inspect.

For inspecting the workflow state at the build-step phase, the
`build_inspect.py` plugin is provided. This can be told whether to
succeed or fail by passing arguments as appropriate when it is
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this useful?

declared in the buildstep plugins section. A failing declaration would
be:

```json
{
"name": "buildstep_inspect",
"args": {
"fail_reason": "insufficient memory"
}
}
```

A succeeding declaration would be:

```json
{
"name": "buildstep_inspect",
"args": {
"image_id": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
}
}
```
65 changes: 65 additions & 0 deletions buildstep_inspect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""
Copyright (c) 2017 Red Hat, Inc
All rights reserved.

This software may be modified and distributed under the terms
of the BSD license. See the LICENSE file for details.
"""

from __future__ import unicode_literals
from __future__ import print_function

from atomic_reactor.plugin import BuildStepPlugin, InappropriateBuildStepError
from atomic_reactor.build import BuildResult


class BuildStepInspectPlugin(BuildStepPlugin):
"""
Log the inputs to the build-step plugin
"""

key = 'buildstep_inspect'

def __init__(self, tasker, workflow, fail_reason=None, image_id=None,
inappropriate=False):
"""
"""
super(BuildStepInspectPlugin, self).__init__(tasker, workflow)

logs = [
"Step 1 : FROM sha256:<...>",
"---> <...>",
"Step 2 : CMD /bin/bash",
"---> Running in <...>",
"---> <...>",
"Removing intermediate container <...>",
]

if image_id is not None:
final_line = "Successfully built {}".format(image_id)
else:
final_line = "Build failed"

logs.append(final_line)
self.build_result = BuildResult(logs=logs,
fail_reason=fail_reason,
image_id=image_id)
self.inappropriate = inappropriate

def run(self):
"""
Run plugin, logging self.workflow.builder information
"""

for line in [
"Build directory: {}".format(self.workflow.builder.df_dir),
"Dockerfile path: {}".format(self.workflow.builder.df_path),
"Image to build: {}".format(self.workflow.builder.image),
]:
self.log.info(line)

if self.inappropriate:
self.log.info("Raising InappropriateBuildStepError")
raise InappropriateBuildStepError

return self.build_result