-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: Remove attach_api and replace with docker library calls #1552
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
Changes from all commits
546a41b
6b606e2
615bbf7
309d5c7
13f3b73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,6 @@ | |
|
|
||
| import docker | ||
|
|
||
| from samcli.local.docker.attach_api import attach | ||
| from .utils import to_posix_path | ||
|
|
||
| LOG = logging.getLogger(__name__) | ||
|
|
@@ -200,7 +199,7 @@ def wait_for_logs(self, stdout=None, stderr=None): | |
| real_container = self.docker_client.containers.get(self.id) | ||
|
|
||
| # Fetch both stdout and stderr streams from Docker as a single iterator. | ||
| logs_itr = attach(self.docker_client, container=real_container, stdout=True, stderr=True, logs=True) | ||
| logs_itr = real_container.attach(stream=True, logs=False, demux=True) | ||
|
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. Setting
Contributor
Author
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. @thomas-fossati What behavior. I have asked a similar question on #1566. It is not clear to me what you are @setrofim are referring to. Please be more specific. 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. Apologies for the extreme terseness of my previous comment. If the lambda business logics completes before SAM attaches to the container, the lambda's output will only be available through the logs. So if you don't ask for the logs to be forwarded on attach, you might end up seeing no output, including the bits that SAM cares about (ie.,
Contributor
Author
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. @setrofim had a small back and forth here: #1566 (comment) I think I understand the reasoning more. It was intentionally 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. Sounds like a good plan to me, thanks! |
||
|
|
||
| self._write_container_output(logs_itr, stdout=stdout, stderr=stderr) | ||
|
|
||
|
|
@@ -238,25 +237,13 @@ def _write_container_output(output_itr, stdout=None, stderr=None): | |
| Stream writer to write stderr data from the Container into | ||
| """ | ||
|
|
||
| # Iterator returns a tuple of (frame_type, data) where the frame type determines which stream we write output | ||
| # to | ||
| for frame_type, data in output_itr: | ||
|
|
||
| if frame_type == Container._STDOUT_FRAME_TYPE and stdout: | ||
| # Frame type 1 is stdout data. | ||
| stdout.write(data) | ||
|
|
||
| elif frame_type == Container._STDERR_FRAME_TYPE and stderr: | ||
| # Frame type 2 is stderr data. | ||
| stderr.write(data) | ||
|
|
||
| else: | ||
| # Either an unsupported frame type or stream for this frame type is not configured | ||
| LOG.debug( | ||
| "Dropping Docker container output because of unconfigured frame type. " "Frame Type: %s. Data: %s", | ||
| frame_type, | ||
| data, | ||
| ) | ||
| # Iterator returns a tuple of (stdout, stderr) | ||
| for stdout_data, stderr_data in output_itr: | ||
| if stdout_data and stdout: | ||
| stdout.write(stdout_data) | ||
|
|
||
| if stderr_data and stderr: | ||
| stderr.write(stderr_data) | ||
|
|
||
| @property | ||
| def network_id(self): | ||
|
|
||
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.
Is this with the latest version of docker? do we need any version bumps?
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.
This was released in 3.7 (looking at docker/docker-py#1952). We are on 4.0 or greater, so we should be covered and not need any bump.