|
| 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