diff --git a/agent/worker/agent.py b/agent/worker/agent.py index 4a0728d..82a6450 100644 --- a/agent/worker/agent.py +++ b/agent/worker/agent.py @@ -112,7 +112,6 @@ def _update_net_client(self, dc: docker.DockerClient): return net_container_name = "supervisely-net-client-{}".format(constants.TOKEN()) - sly_net_hub_name = "supervisely/sly-net-client:latest" sly_net_container = None for container in dc.containers.list(): @@ -126,7 +125,7 @@ def _update_net_client(self, dc: docker.DockerClient): ) self.logger.warn( ( - "Probably you should reastart agent manually using instructions:" + "Probably you should restart agent manually using instructions:" "https://developer.supervisely.com/getting-started/connect-your-computer" ) ) @@ -135,13 +134,14 @@ def _update_net_client(self, dc: docker.DockerClient): # pull if update too old agent if need_update_env is None: need_update = check_and_pull_sly_net_if_needed( - dc, sly_net_container, self.logger, sly_net_hub_name + dc, sly_net_container, self.logger ) if need_update is False: return network = "supervisely-net-{}".format(constants.TOKEN()) + sly_net_client_image_name = sly_net_container.image.tags[0] command = sly_net_container.attrs.get("Args") volumes = sly_net_container.attrs["HostConfig"]["Binds"] cap_add = sly_net_container.attrs["HostConfig"]["CapAdd"] @@ -162,7 +162,7 @@ def _update_net_client(self, dc: docker.DockerClient): sly_net_container.remove(force=True) dc.containers.run( - image=sly_net_hub_name, + image=sly_net_client_image_name, name=net_container_name, command=command, network=network, diff --git a/agent/worker/task_app.py b/agent/worker/task_app.py index 0e1099d..2e6723f 100644 --- a/agent/worker/task_app.py +++ b/agent/worker/task_app.py @@ -266,14 +266,6 @@ def read_dockerimage_from_config(self): ) ) self.info["docker_image"] = constants.APP_DEBUG_DOCKER_IMAGE() - if constants.SLY_APPS_DOCKER_REGISTRY() is not None: - self.logger.info( - "NON DEFAULT DOCKER REGISTRY: docker image {!r} is replaced with {!r}".format( - self.info["docker_image"], f"{constants.SLY_APPS_DOCKER_REGISTRY()}/{self.info['docker_image']}" - ) - ) - self.info["docker_image"] = f"{constants.SLY_APPS_DOCKER_REGISTRY()}/{self.info['docker_image']}" - except KeyError as e: requirements_path = self.get_requirements_path() version = "latest" @@ -286,6 +278,17 @@ def read_dockerimage_from_config(self): f'Dockerimage not found in config.json, so it is set to default: {self.info["docker_image"]}' ) + if constants.SLY_APPS_DOCKER_REGISTRY() is not None: + self.logger.info( + "NON DEFAULT DOCKER REGISTRY: docker image {!r} is replaced with {!r}".format( + self.info["docker_image"], + f"{constants.SLY_APPS_DOCKER_REGISTRY()}/{self.info['docker_image']}", + ) + ) + self.info[ + "docker_image" + ] = f"{constants.SLY_APPS_DOCKER_REGISTRY()}/{self.info['docker_image']}" + def is_isolate(self): if self.app_config is None: raise RuntimeError("App config is not initialized") diff --git a/agent/worker/task_update.py b/agent/worker/task_update.py index ce66d95..50c6752 100644 --- a/agent/worker/task_update.py +++ b/agent/worker/task_update.py @@ -65,7 +65,6 @@ def task_main_func(self): # Pull net-client if needed net_container_name = "supervisely-net-client-{}".format(constants.TOKEN()) - sly_net_hub_name = "supervisely/sly-net-client:latest" sly_net_container = None for container in self._docker_api.containers.list(): @@ -79,7 +78,7 @@ def task_main_func(self): ) else: need_update = check_and_pull_sly_net_if_needed( - self._docker_api, sly_net_container, self.logger, sly_net_hub_name + self._docker_api, sly_net_container, self.logger ) if need_update is True: cur_envs.append("UPDATE_SLY_NET_AFTER_RESTART=1") @@ -124,11 +123,15 @@ def run_shell_command(cmd, print_output=False): def check_and_pull_sly_net_if_needed( dc: docker.DockerClient, cur_container: Container, + sly_net_client_image_name, logger: Logger, - sly_net_hub_name: str = "supervisely/sly-net-client:latest", ) -> bool: ic = ImageCollection(dc) - docker_hub_image_info = ic.get_registry_data(sly_net_hub_name) + + if sly_net_client_image_name is None: + sly_net_client_image_name = cur_container.image.tags[0] + + docker_hub_image_info = ic.get_registry_data(sly_net_client_image_name) name_with_digest: str = cur_container.image.attrs.get("RepoDigests", [""])[0] if name_with_digest.endswith(docker_hub_image_info.id): @@ -136,5 +139,5 @@ def check_and_pull_sly_net_if_needed( return False else: logger.info("Found new version of sly-net-client. Pulling...") - sly.docker_utils._docker_pull_progress(dc, sly_net_hub_name, logger) + sly.docker_utils._docker_pull_progress(dc, sly_net_client_image_name, logger) return True