Skip to content

Commit

Permalink
add agent image to image history
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaiPetukhov committed Jan 16, 2024
1 parent 9c4b7a4 commit fff104f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion agent/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@


def parse_envs():
args_req = {x: os.environ[x] for x in constants.get_required_settings()}
args_req = {
x: constants._VALUES[x] if x in constants._VALUES else os.environ[x]
for x in constants.get_required_settings()
}
args_opt = {
x: constants.read_optional_setting(x) for x in constants.get_optional_defaults().keys()
}
Expand Down
24 changes: 24 additions & 0 deletions agent/worker/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from concurrent.futures import ThreadPoolExecutor, wait
from typing import Dict, List
from pathlib import Path
from filelock import FileLock
from datetime import datetime

import supervisely_lib as sly

Expand Down Expand Up @@ -87,6 +89,28 @@ def __init__(self):
self.agent_connect_initially()
self.logger.info("Agent connected to server.")

self._history_file = None
if constants.CROSS_AGENT_DATA_DIR() is not None:
self._history_file = os.path.join(
constants.CROSS_AGENT_DATA_DIR(),
f"docker-images-history-{constants.TOKEN()[:8]}.json",
)
self._history_file_lock = FileLock(f"{self._history_file}.lock")

cur_date = datetime.utcnow().strftime("%Y-%m-%dT%H:%M")

with self._history_file_lock:
if sly.fs.file_exists(self._history_file):
with open(self._history_file, "r") as json_file:
images_stat = json.load(json_file)
else:
images_stat = {}

images_stat[self.agent_info["agent_image"]] = cur_date

with open(self._history_file, "w") as json_file:
json.dump(images_stat, json_file, indent=4)

@classmethod
def _restart(cls, envs: list = None, volumes: dict = None, runtime: str = None):
docker_api = docker.from_env()
Expand Down

0 comments on commit fff104f

Please sign in to comment.