-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Allow scaling services that have port binding of the form host_ip::container_port
#1659
Conversation
ae1e9d5
to
db52ee2
Compare
dccf151
to
4fd875f
Compare
Thanks.
|
946c623
to
65e1cab
Compare
@@ -679,7 +679,8 @@ def labels(self, one_off=False): | |||
|
|||
def can_be_scaled(self): | |||
for port in self.options.get('ports', []): | |||
if ':' in str(port): | |||
external = split_port(port)[1] | |||
if external and not (type(external) == tuple and external[1] == None): |
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 think that if you're checking that type(external) == tuple
, then checking it for truthiness is unnecessary. And I think isinstance is better than comparing types. So this can just be:
if isinstance(external, tuple) and external[1] == None:
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.
Oh, and PEP 8 says to use is None
, not == None
.
Comparisons to singletons like None should always be done with is or is not , never the equality operators
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.
then checking it for truthiness is unnecessary
You mean external[1] == None
is not required? I think it is, external[1]
corresponds to host port, if its specified can_be_scaled
should fail, else succeed.
f02b5ab
to
b60ee3a
Compare
# TODO: this function should ideally move to docker.utils.ports | ||
# get rid of it once its accepted into docker-py | ||
def has_external_port(external_binding): | ||
if external_binding is None: |
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.
We don't need to check this at all IMO because docker-py's split_port
never returns a list with None
elements as the 2nd return value (it's either a just None
, or a list of strings or tuples).
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.
If it's going to be a public function in docker-py, it needs to be able to handle all valid port bindings, not just the subset created by split_port()
.
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.
If we do what I have proposed in https://github.com/docker/compose/pull/1659/files#r34191487 then we don't need this has_external_port()
function at all, because my proposed function simplifies readability. The whole reason for having this function in the first place was it was a little complex from readability standpoint.
I think we might also need (unit?) tests covering port ranges for |
b60ee3a
to
454b52f
Compare
Rebased with latest master, seems like the CI build failed due to docker errors.
|
454b52f
to
520d29a
Compare
Resolves #1102 |
'foo', | ||
image='foo', | ||
ports=["127.0.0.1:1000:2000"]) | ||
self.assertEqual(service.specifies_host_port(), True) |
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.
Minor nit, now that we're using py.test
we actually get better error messages if you use assert service.specifies_host_port()
or assert not ...
.
Would you mind changing the assertions to use bare assert
?
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.
Rest of the service_test.py still uses self.assertEqual
, I don't want to break the convention. What you're suggesting could go in as a separate PR that updates all tests IMO.
520d29a
to
ae3c66b
Compare
Oops, bad push closed this, reopening. |
c00e710
to
9158a1f
Compare
…host port Signed-off-by: Viranch Mehta <viranch.mehta@gmail.com>
9158a1f
to
258c8bc
Compare
host_ip::container_port
Rebased with latest master. |
…st IP but no host port
LGTM |
LGTM. Thanks @viranch 👍 |
Allow scaling services that have port binding of the form `host_ip::container_port`
Compose gives up scaling if a service has a port binding of the form:
192.168.1.2::80
(bind to a specific host IP but a random host port, for the container port 80) with the error:Compose wrongly assumes that a host port is specified because there's a
:
in the port binding.This PR fixes this.