Skip to content
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

Make DockerCompose.get_service_info public #239

Closed
csikb opened this issue Aug 28, 2022 · 6 comments
Closed

Make DockerCompose.get_service_info public #239

csikb opened this issue Aug 28, 2022 · 6 comments
Labels
✅ close on merge Issue that will be closed by an open pull request 🚀 enhancement 📦 package: compose

Comments

@csikb
Copy link

csikb commented Aug 28, 2022

Return a touple with the host and the port

def get_service_info(self, service, port):
    """
    Returns the host and the port for one of the services.

    Parameters
    ----------
    service: str
        Name of the docker compose service
    port: int
        The internal port to get the host for

    Returns
    -------
    (str, str):
        The hostname for the service, The port for the service
    """
    port_cmd = self.docker_compose_command() + ["port", service, str(port)]
    output = subprocess.check_output(port_cmd, cwd=self.filepath).decode("utf-8")
    result = str(output).rstrip().split(":")
    if len(result) != 2 or not all(result):
        raise NoSuchPortExposed(f"port {port} is not exposed for service {service}")
    return result[0], result[1]
# old approach
host = compose.get_service_host("hub", 4444)
port = compose.get_service_port("hub", 4444)
# new approach
host, port = compose.get_service_info("hub", 4444)
@tillahoffmann
Copy link
Collaborator

Sounds good. Fancy sending a PR?

@csikb
Copy link
Author

csikb commented Aug 28, 2022

Sure, I alredy did the coding part, let me look trough it if everything is OK with it.

@tillahoffmann
Copy link
Collaborator

Should just require removing the underscore in compose.py, right?

@csikb
Copy link
Author

csikb commented Aug 28, 2022

And adding a test case

@csikb
Copy link
Author

csikb commented Aug 28, 2022

#240

@totallyzen
Copy link
Collaborator

this is now obsolete! see the new docker compose v2 implementation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✅ close on merge Issue that will be closed by an open pull request 🚀 enhancement 📦 package: compose
Projects
None yet
Development

No branches or pull requests

3 participants