- Notifications
You must be signed in to change notification settings - Fork 98
Display Docker build errors when builds fail (Fixes #35) #347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits Select commit Hold shift + click to select a range
ffaa925 Display Docker build errors when builds fail (Fixes #35)
T-Rajeev30 8d53b10 Show docker build errors while preserving return behavior
T-Rajeev30 a0da121 Enable overriding the output_callback for an instance.
tfoote ef242e7 Add a unit test to validate the build failure detection behavior and …
tfoote File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -306,3 +306,74 @@ def test_docker_cmd_nocleanup(self): | |
| self.assertIn('--rm', dig.generate_docker_cmd(nocleanup='')) | ||
| | ||
| self.assertNotIn('--rm', dig.generate_docker_cmd(nocleanup='true')) | ||
| | ||
| | ||
| | ||
| class BrokenBuildSnippet(RockerExtension): | ||
| @staticmethod | ||
| def get_name(): | ||
| return 'broken_snippet' | ||
| | ||
| def __init__(self): | ||
| self._env_subs = None | ||
| self.name = BrokenBuildSnippet.get_name() | ||
| | ||
| | ||
| def get_environment_subs(self): | ||
| if not self._env_subs: | ||
| self._env_subs = {} | ||
| return self._env_subs | ||
| | ||
| def get_preamble(self, cliargs): | ||
| return '' | ||
| | ||
| def get_snippet(self, cliargs): | ||
| snippet = "BAD KEYWORD for a dockerfile" | ||
| return snippet #empy_expand(snippet, self.get_environment_subs()) | ||
| | ||
| @staticmethod | ||
| def register_arguments(parser, defaults): | ||
| parser.add_argument(name_to_argument(BrokenBuildSnippet.get_name()), | ||
| action='store_true', | ||
| default=defaults.get('broken_snippet', None), | ||
| help="test a broken snippet") | ||
| | ||
| class BrokenBuiildTest(unittest.TestCase): | ||
| | ||
| def setUp(self): | ||
| # Work around interference between empy Interpreter | ||
| # stdout proxy and test runner. empy installs a proxy on stdout | ||
| # to be able to capture the information. | ||
| # And the test runner creates a new stdout object for each test. | ||
| # This breaks empy as it assumes that the proxy has persistent | ||
| # between instances of the Interpreter class | ||
| # empy will error with the exception | ||
| # "em.Error: interpreter stdout proxy lost" | ||
| em.Interpreter._wasProxyInstalled = False | ||
| | ||
| @pytest.mark.docker | ||
| def test_broken_snippet_extension(self): | ||
| | ||
| # # Test build args | ||
| # mock_cliargs = {'shm_size_build': '2g'} | ||
| # build_args = p.get_build_args(mock_cliargs) | ||
| # self.assertEqual(build_args, {'shm_size': '2g'}) | ||
| | ||
| extension_manager = RockerExtensionManager() | ||
| extension_manager.available_plugins = {'broken_snippet': BrokenBuildSnippet} | ||
| active_extensions = extension_manager.get_active_extensions({'user': True, 'broken_snippet': BrokenBuildSnippet, 'extension_blacklist': ['ssh']}) | ||
| self.assertTrue(active_extensions) | ||
| | ||
| # Confirm successful build baseline | ||
| mock_cli_args = {'broken_snippet': False} | ||
| dig = DockerImageGenerator([], mock_cli_args, 'ubuntu:bionic') | ||
| self.assertNotIn('BAD KEYWORD', dig.dockerfile) | ||
| self.assertEqual(dig.build(), 0) | ||
| | ||
| # Add broken build which breaks | ||
| mock_cli_args = {'broken_snippet': True} | ||
| dig = DockerImageGenerator(active_extensions, mock_cli_args, 'ubuntu:bionic') | ||
| # dig.output_callback = lambda output: print("OVERRIDE build > %s" % output) | ||
| self.assertIn('BAD KEYWORD', dig.dockerfile) | ||
| self.assertEqual(dig.build(), 1) | ||
| # TODO(tfoote) capture the console output by passing in a custom output_callback and assert we see the error there | ||
| Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make sure that the error message can be confirmed in the console output by overriding the output_callback. | ||
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I quickly mocked overriding the output callback but it doesn't appear to be working.