Compare commits

...

18 Commits

Author SHA1 Message Date
5692346b0d Merge pull request 'fix' (#58) from master into dev
Reviewed-on: #58
2025-09-15 01:33:57 +03:00
Egor Matveev
40907f9d07 fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 1m16s
Deploy Dev / Push (pull_request) Successful in 21s
Deploy Dev / Deploy dev (pull_request) Successful in 10s
Deploy Prod / Build (pull_request) Successful in 5s
Deploy Prod / Push (pull_request) Successful in 10s
Deploy Prod / Deploy prod (pull_request) Successful in 11s
2025-09-15 01:33:01 +03:00
23cb51985c Merge pull request 'fix' (#56) from master into dev
Reviewed-on: #56
2025-06-12 12:28:44 +03:00
Egor Matveev
4c0bafa7cf fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 9s
Deploy Dev / Deploy dev (pull_request) Successful in 8s
Deploy Prod / Build (pull_request) Successful in 5s
Deploy Prod / Push (pull_request) Successful in 9s
Deploy Prod / Deploy prod (pull_request) Successful in 6s
2025-06-12 12:28:21 +03:00
0c5ce6c1eb Merge pull request 'fix' (#55) from master into dev
Reviewed-on: #55
2025-06-12 02:46:02 +03:00
Egor Matveev
4daae8d2a0 fix
All checks were successful
Deploy Dev / Deploy dev (pull_request) Successful in 9s
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 9s
2025-06-12 02:45:41 +03:00
a0e06d3ef8 Merge pull request 'fix' (#54) from master into dev
Reviewed-on: #54
2025-06-12 02:39:41 +03:00
Egor Matveev
c25796c5e0 fix
All checks were successful
Deploy Dev / Deploy dev (pull_request) Successful in 10s
Deploy Dev / Build (pull_request) Successful in 4s
Deploy Dev / Push (pull_request) Successful in 9s
2025-06-12 02:39:08 +03:00
f191d7c07a Merge pull request 'fix' (#53) from master into dev
Reviewed-on: #53
2025-06-12 02:35:21 +03:00
Egor Matveev
eed31426b2 fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 10s
Deploy Dev / Deploy dev (pull_request) Successful in 10s
2025-06-12 02:35:03 +03:00
8863b7f7ab Merge pull request 'fix' (#52) from master into dev
Reviewed-on: #52
2025-06-12 02:25:31 +03:00
Egor Matveev
1822a24442 fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 9s
Deploy Dev / Deploy dev (pull_request) Successful in 8s
2025-06-12 02:25:17 +03:00
41080370c5 Merge pull request 'fix' (#51) from master into dev
Reviewed-on: #51
2025-06-12 02:19:28 +03:00
Egor Matveev
52ec293aaf fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 4s
Deploy Dev / Push (pull_request) Successful in 10s
Deploy Dev / Deploy dev (pull_request) Successful in 7s
2025-06-12 02:19:13 +03:00
ff2fbba1aa Merge pull request 'fix' (#50) from master into dev
Reviewed-on: #50
2025-06-12 02:16:02 +03:00
Egor Matveev
627f044b08 fix
All checks were successful
Deploy Dev / Push (pull_request) Successful in 9s
Deploy Dev / Deploy dev (pull_request) Successful in 8s
Deploy Dev / Build (pull_request) Successful in 5s
2025-06-12 02:15:47 +03:00
6b9b6cb3b8 Merge pull request 'fix' (#49) from master into dev
Reviewed-on: #49
2025-06-12 02:10:14 +03:00
Egor Matveev
bfb417f70b fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 10s
Deploy Dev / Deploy dev (pull_request) Successful in 7s
2025-06-12 02:09:47 +03:00
7 changed files with 58 additions and 133 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@@ -6,9 +6,7 @@ services:
image: mathwave/sprint-repo:certupdater image: mathwave/sprint-repo:certupdater
command: worker command: worker
environment: environment:
MINIO_HOST: "minio.develop.sprinthub.ru"
MINIO_SECRET_KEY: $MINIO_SECRET_KEY_DEV MINIO_SECRET_KEY: $MINIO_SECRET_KEY_DEV
MONGO_HOST: "mongo.develop.sprinthub.ru"
MONGO_PASSWORD: $MONGO_PASSWORD_DEV MONGO_PASSWORD: $MONGO_PASSWORD_DEV
STAGE: "development" STAGE: "development"
volumes: volumes:
@@ -16,6 +14,8 @@ services:
networks: networks:
- configurator - configurator
- queues-development - queues-development
- minio-development
- mongo-development
deploy: deploy:
mode: replicated mode: replicated
restart_policy: restart_policy:
@@ -31,3 +31,7 @@ networks:
external: true external: true
queues-development: queues-development:
external: true external: true
minio-development:
external: true
mongo-development:
external: true

View File

@@ -6,9 +6,7 @@ services:
image: mathwave/sprint-repo:certupdater image: mathwave/sprint-repo:certupdater
command: worker command: worker
environment: environment:
MINIO_HOST: "minio.sprinthub.ru"
MINIO_SECRET_KEY: $MINIO_SECRET_KEY_PROD MINIO_SECRET_KEY: $MINIO_SECRET_KEY_PROD
MONGO_HOST: "mongo.sprinthub.ru"
MONGO_PASSWORD: $MONGO_PASSWORD_PROD MONGO_PASSWORD: $MONGO_PASSWORD_PROD
STAGE: "production" STAGE: "production"
volumes: volumes:
@@ -16,6 +14,8 @@ services:
networks: networks:
- configurator - configurator
- queues - queues
- minio
- mongo
deploy: deploy:
mode: replicated mode: replicated
restart_policy: restart_policy:
@@ -31,3 +31,7 @@ networks:
external: true external: true
queues: queues:
external: true external: true
minio:
external: true
mongo:
external: true

View File

@@ -1,7 +1,7 @@
import os import os
from minio import Minio from minio import Minio
MINIO_HOST = os.getenv("MINIO_HOST", "localhost") + ":9000" MINIO_HOST = "minio:9000"
MINIO_ACCESS_KEY = os.getenv("MINIO_ACCESS_KEY", "serviceminioadmin") MINIO_ACCESS_KEY = os.getenv("MINIO_ACCESS_KEY", "serviceminioadmin")
MINIO_SECRET_KEY = os.getenv("MINIO_SECRET_KEY", "minioadmin") MINIO_SECRET_KEY = os.getenv("MINIO_SECRET_KEY", "minioadmin")

View File

@@ -1,88 +0,0 @@
import json
import os
import urllib.parse
from threading import Thread
from time import sleep
from requests import get
class ConfiguratorClient:
def __init__(self, app_name: str, stage: str, need_poll: bool = True):
self.app_name = app_name
self.stage = stage
self.endpoint = 'http://configurator/'
self.fetch_url = urllib.parse.urljoin(self.endpoint, '/api/v1/fetch')
self.config_storage = {}
self.experiment_storage = {}
self.staff_storage = {}
self.poll_data()
if need_poll:
self.poll_data_in_thread()
def poll_data_in_thread(self):
def inner():
while True:
sleep(30)
self.fetch()
Thread(target=inner, daemon=True).start()
def poll_data(self):
self.fetch(with_exception=True)
def request_with_retries(self, url, params, with_exception=False, retries_count=3):
exception_to_throw = None
for _ in range(retries_count):
try:
response = get(
url,
params=params
)
if response.status_code == 200:
return response.json()
print(f'Failed to request {url}, status_code={response.status_code}')
exception_to_throw = Exception('Not 200 status')
except Exception as exc:
print(exc)
exception_to_throw = exc
sleep(1)
print(f'Failed fetching with retries: {url}, {params}')
if with_exception:
raise exception_to_throw
def fetch(self, with_exception=False):
if self.stage == 'local':
local_platform = json.loads(open('local_platform.json', 'r').read())
self.config_storage = local_platform['configs']
self.experiment_storage = local_platform['experiments']
self.staff_storage = {
key: set(value)
for key, value in local_platform['platform_staff'].items()
}
return
response_data = self.request_with_retries(self.fetch_url, {
'project': self.app_name,
'stage': self.stage,
}, with_exception)
self.config_storage = response_data['configs']
self.experiment_storage = response_data['experiments']
self.staff_storage = {
key: set(value)
for key, value in response_data['platform_staff'].items()
}
def is_staff(self, **kwargs):
for key, value in kwargs.items():
if value in self.staff_storage[key]:
return True
return False
def get_config(self, name):
return self.config_storage[name]
def get_experiment(self, name):
return self.experiment_storage[name]
configurator = ConfiguratorClient("certupdater", os.getenv("STAGE"))

22
main.py
View File

@@ -4,8 +4,7 @@ import os
import subprocess import subprocess
import time import time
from requests import post from requests import get, post
from configurator import configurator
from mongo import mongo from mongo import mongo
from blob import minio from blob import minio
@@ -49,10 +48,11 @@ def call(command: str) -> Response:
def get_hosts() -> list[str]: def get_hosts() -> list[str]:
if os.getenv("STAGE") == "development": response = get(
return list(set(list(configurator.get_config("hosts")))) f"http://configurator/api/v1/fetch?project=certupdater&stage={os.getenv("STAGE")}"
else: ).json()
return list(set(list(configurator.get_config("hosts")))) hosts = response["configs"]["hosts"]
return list(hosts)
def update_host(host: str) -> str | None: def update_host(host: str) -> str | None:
@@ -104,11 +104,14 @@ def update_host(host: str) -> str | None:
return None return None
while True: if __name__ == "__main__":
while True:
now = datetime.datetime.now() now = datetime.datetime.now()
mongo_hosts = mongo.hosts mongo_hosts = mongo.hosts
hosts = get_hosts()
print(f"got hosts {hosts}")
updated = False updated = False
for host in get_hosts(): for host in hosts:
if ( if (
now + datetime.timedelta(days=14) now + datetime.timedelta(days=14)
> mongo_hosts.get( > mongo_hosts.get(
@@ -117,6 +120,7 @@ while True:
): ):
success = update_host(host) success = update_host(host)
if success: if success:
print(success)
send_notification( send_notification(
f"host {host} was not updated with an error: {success}" f"host {host} was not updated with an error: {success}"
) )
@@ -124,6 +128,8 @@ while True:
mongo.update_date(host) mongo.update_date(host)
updated = True updated = True
send_notification(f"host {host} updated") send_notification(f"host {host} updated")
else:
print(f"Host {host} does not need to be updated")
if updated: if updated:
if os.getenv("STAGE") == "development": if os.getenv("STAGE") == "development":
container_id_run = call( container_id_run = call(

View File

@@ -4,12 +4,11 @@ import os
MONGO_USER = os.getenv("MONGO_USER", "mongo") MONGO_USER = os.getenv("MONGO_USER", "mongo")
MONGO_PASSWORD = os.getenv("MONGO_PASSWORD", "password") MONGO_PASSWORD = os.getenv("MONGO_PASSWORD", "password")
MONGO_HOST = os.getenv("MONGO_HOST", "localhost")
class Mongo: class Mongo:
def __init__(self): def __init__(self):
url = f"mongodb://{MONGO_USER}:{MONGO_PASSWORD}@{MONGO_HOST}:27017/" url = f"mongodb://{MONGO_USER}:{MONGO_PASSWORD}@mongo:27017/"
self.client: pymongo.MongoClient = pymongo.MongoClient(url) self.client: pymongo.MongoClient = pymongo.MongoClient(url)
self.database = self.client.get_database("certupdater") self.database = self.client.get_database("certupdater")
self.hosts_collection.create_index([ self.hosts_collection.create_index([