Skip to content

Commit

Permalink
Private docker registry (#54)
Browse files Browse the repository at this point in the history
* add private docker registry

* private docker registry for default image

* updated net-client docker image

* updated net-client docker image

* typo

---------

Co-authored-by: Tony Bartsits <[email protected]>
  • Loading branch information
NikolaiPetukhov and tonybart1337 authored Dec 13, 2023
1 parent f024cb3 commit bf7882a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
8 changes: 4 additions & 4 deletions agent/worker/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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"
)
)
Expand All @@ -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"]
Expand All @@ -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,
Expand Down
19 changes: 11 additions & 8 deletions agent/worker/task_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand Down
13 changes: 8 additions & 5 deletions agent/worker/task_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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")
Expand Down Expand Up @@ -124,17 +123,21 @@ 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):
logger.info("sly-net-client is already updated")
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

0 comments on commit bf7882a

Please sign in to comment.