Skip to content

Commit

Permalink
update sly-net for old agent
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoLisin committed Nov 20, 2023
1 parent 27204ac commit c99b20d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
7 changes: 7 additions & 0 deletions agent/worker/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import supervisely_lib as sly

from worker.agent_utils import TaskDirCleaner, AppDirCleaner
from worker.task_update import check_and_pull_sly_net

warnings.filterwarnings(action="ignore", category=UserWarning)

Expand Down Expand Up @@ -126,6 +127,12 @@ def _update_net_client(self, dc: docker.DockerClient):
)
)
return
else:
# pull if update to old agent
agnet_checked_sly_net = os.getenv("AGNET_CHECKED_SLY_NET", None)
cur_id = sly_net_container.attrs.get("Image", None)
if agnet_checked_sly_net is None:
check_and_pull_sly_net(dc, cur_id, self.logger, sly_net_hub_name)

network = "supervisely-net-{}".format(constants.TOKEN())
command = sly_net_container.attrs.get("Args")
Expand Down
30 changes: 21 additions & 9 deletions agent/worker/task_update.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# coding: utf-8

from logging import Logger
import os
import json
import supervisely_lib as sly
Expand Down Expand Up @@ -61,9 +62,11 @@ def task_main_func(self):
new_envs.append(val)
cur_envs = new_envs
cur_envs.append("REMOVE_OLD_AGENT={}".format(cur_container_id))
cur_envs.append("AGNET_CHECKED_SLY_NET=1")

# 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():
Expand All @@ -76,15 +79,8 @@ def task_main_func(self):
"Something goes wrong: can't find sly-net-client attached to this agent"
)
else:
ic = ImageCollection(self._docker_api)
sly_net_hub_name = "supervisely/sly-net-client:latest"
docker_hub_image_info = ic.get_registry_data(sly_net_hub_name)

if sly_net_container.attrs.get("Image", None) == docker_hub_image_info.id:
self.logger.info("sly-net-client is already updated")
else:
self.logger.info("Found new version of sly-net-client. Pulling...")
sly.docker_utils._docker_pull_progress(self._docker_api, sly_net_hub_name, self.logger)
cur_id = sly_net_container.attrs.get("Image", None)
check_and_pull_sly_net(self._docker_api, cur_id, self.logger, sly_net_hub_name)

# start new agent
container = self._docker_api.containers.run(
Expand Down Expand Up @@ -119,3 +115,19 @@ def run_shell_command(cmd, print_output=False):
if print_output:
print(clean_line)
return res


def check_and_pull_sly_net(
dc: docker.DockerClient,
cur_id: str,
logger: Logger,
sly_net_hub_name: str = "supervisely/sly-net-client:latest",
):
ic = ImageCollection(dc)
docker_hub_image_info = ic.get_registry_data(sly_net_hub_name)

if cur_id == docker_hub_image_info.id:
logger.info("sly-net-client is already updated")
else:
logger.info("Found new version of sly-net-client. Pulling...")
sly.docker_utils._docker_pull_progress(dc, sly_net_hub_name, logger)

0 comments on commit c99b20d

Please sign in to comment.