diff --git a/setup.py b/setup.py index eed93e9..dc834f2 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ setuptools.setup( name="d2_docker", - version="1.0.8", + version="1.0.9", description="Dockers for DHIS2 instances", long_description=open("README.md", encoding="utf-8").read(), keywords=["python"], diff --git a/src/d2_docker/commands/list_.py b/src/d2_docker/commands/list_.py index 68e9579..ef5fce3 100644 --- a/src/d2_docker/commands/list_.py +++ b/src/d2_docker/commands/list_.py @@ -17,7 +17,7 @@ def run(args): def get_images_info(running_containers): - """Get a list of images info: "{NAME} STOPPED" or "{NAME} RUNNING[port={N}]".""" + """Get a list of images info: "{NAME} STOPPED" or "{NAME} RUNNING[port={N},deploy_path={PATH}]".""" cmd_image = ["docker", "image", "ls", "--format={{.Repository}} {{.Tag}}"] result_image = utils.run(cmd_image, capture_output=True) lines_parts = [line.split() for line in result_image.stdout.decode("utf-8").splitlines()] @@ -33,9 +33,22 @@ def get_images_info(running_containers): image_name = repo + ":" + tag if utils.DHIS2_DATA_IMAGE in repo: - port = running_containers.get(image_name, None) - state = "RUNNING[port={}]".format(port) if port else "STOPPED" - value = {"port": port, "text": "{} {}".format(image_name, state)} + info = running_containers.get(image_name, None) or {} + port = info.get("port", None) + + if port: + deploy_path = info.get("deploy_path", None) + extra_info = ",".join(filter(bool, [ + "port={}".format(port), + "deploy_path={}".format(deploy_path) if deploy_path else None, + ])) + state = "RUNNING[{}]".format(extra_info) + else: + state = "STOPPED" + value = { + "port": port, + "text": "{} {}".format(image_name, state), + } data_image_names.append(value) return data_image_names @@ -43,15 +56,19 @@ def get_images_info(running_containers): def get_running_containers(): """Return dictionary of {DATA_IMAGE_NAME: PORT} of active d2-docker instances.""" - lines = utils.run_docker_ps(['--format={{.Label "com.eyeseetea.image-name"}} {{.Ports}}']) - lines_parts_ps = [line.split(None, 1) for line in lines] + lines = utils.run_docker_ps(['--format={{.Label "com.eyeseetea.image-name"}} {{.Ports}} {{.Label "com.eyeseetea.deploy-path"}}']) + lines_parts_ps = [line.split(None, 2) for line in lines] running_containers = {} for entry in lines_parts_ps: - if len(entry) != 2: + if len(entry) == 2: + image_name, ports = entry + deploy_path = "" + elif len(entry) == 3: + image_name, ports, deploy_path = entry + else: continue - image_name, ports = entry port = utils.get_port_from_docker_ports(ports) if port: - running_containers[image_name] = port + running_containers[image_name] = dict(port=port, deploy_path=deploy_path) return running_containers diff --git a/src/d2_docker/docker-compose.yml b/src/d2_docker/docker-compose.yml index 1a4f18f..2106b71 100644 --- a/src/d2_docker/docker-compose.yml +++ b/src/d2_docker/docker-compose.yml @@ -36,6 +36,7 @@ services: image: "jwilder/nginx-proxy:alpine" labels: - "com.eyeseetea.image-name=${DHIS2_DATA_IMAGE}" + - "com.eyeseetea.deploy-path=${DEPLOY_PATH}" ports: - "${DHIS2_CORE_PORT:-8080}:80" volumes: