-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IMP guess url of the services with docker inspect (#132)
* IMP guess url of the services with docker inspect * IMP guessing url with docker py lib instead of docker inspect
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# @author Sébastien BEAU <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import docker | ||
from compose.project import OneOffFilter | ||
from compose.cli import command | ||
from compose.config.errors import ComposeFileNotFound | ||
|
@@ -42,16 +43,43 @@ def get_containers(self, service=None): | |
return self.project.containers(**kwargs) | ||
|
||
def display_service_tooltip(self): | ||
infos = self._get_services_info() | ||
for service in self.project.services: | ||
labels = service.options.get('labels', {}) | ||
if labels.get('docky.access.help'): | ||
# TODO remove after some versions | ||
logger.warning( | ||
"'docky.access.help' is replaced by 'docky.help'. " | ||
"Please update this key in your docker files.") | ||
if infos.get(service.name): | ||
# some applications provide extra parameters to access resource | ||
infos[service.name] += labels.get("docky.url_suffix", "") | ||
logger.info(infos[service.name]) | ||
if labels.get('docky.help'): | ||
logger.info(labels.get('docky.help')) | ||
|
||
def _get_services_info(self): | ||
""" Search IP and Port for each services | ||
""" | ||
client = docker.from_env() | ||
services = (x for x in client.containers.list() | ||
if self.project.name in x.attrs["Name"]) | ||
infos = {} | ||
for serv in services: | ||
local = "%s_local" % self.project.name | ||
ip = serv.attrs["NetworkSettings"]["Networks"][local].get("IPAddress", "") | ||
info = { | ||
"name": serv.attrs["Config"]["Labels"].get( | ||
"com.docker.compose.service", ""), | ||
"ip": ip, | ||
"port": [x for x in serv.attrs["NetworkSettings"].get("Ports", "")] | ||
} | ||
info["port"] = info["port"] and info["port"][0].replace("/tcp", "") or "" | ||
if info["name"] != "db": | ||
# There is no web app to access 'db' service: try adminer for that | ||
infos[info["name"]] = "%(name)s http://%(ip)s:%(port)s" % (info) | ||
return infos | ||
|
||
def create_volume(self): | ||
"""Mkdir volumes if they don't exist yet. | ||
|