Compare commits
8 Commits
6b9b6cb3b8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40907f9d07 | ||
|
|
4c0bafa7cf | ||
|
|
4daae8d2a0 | ||
|
|
c25796c5e0 | ||
|
|
eed31426b2 | ||
|
|
1822a24442 | ||
|
|
52ec293aaf | ||
|
|
627f044b08 |
@@ -6,9 +6,7 @@ services:
|
||||
image: mathwave/sprint-repo:certupdater
|
||||
command: worker
|
||||
environment:
|
||||
MINIO_HOST: "minio.develop.sprinthub.ru"
|
||||
MINIO_SECRET_KEY: $MINIO_SECRET_KEY_DEV
|
||||
MONGO_HOST: "mongo.develop.sprinthub.ru"
|
||||
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
|
||||
STAGE: "development"
|
||||
volumes:
|
||||
@@ -16,6 +14,8 @@ services:
|
||||
networks:
|
||||
- configurator
|
||||
- queues-development
|
||||
- minio-development
|
||||
- mongo-development
|
||||
deploy:
|
||||
mode: replicated
|
||||
restart_policy:
|
||||
@@ -31,3 +31,7 @@ networks:
|
||||
external: true
|
||||
queues-development:
|
||||
external: true
|
||||
minio-development:
|
||||
external: true
|
||||
mongo-development:
|
||||
external: true
|
||||
|
||||
@@ -6,9 +6,7 @@ services:
|
||||
image: mathwave/sprint-repo:certupdater
|
||||
command: worker
|
||||
environment:
|
||||
MINIO_HOST: "minio.sprinthub.ru"
|
||||
MINIO_SECRET_KEY: $MINIO_SECRET_KEY_PROD
|
||||
MONGO_HOST: "mongo.sprinthub.ru"
|
||||
MONGO_PASSWORD: $MONGO_PASSWORD_PROD
|
||||
STAGE: "production"
|
||||
volumes:
|
||||
@@ -16,6 +14,8 @@ services:
|
||||
networks:
|
||||
- configurator
|
||||
- queues
|
||||
- minio
|
||||
- mongo
|
||||
deploy:
|
||||
mode: replicated
|
||||
restart_policy:
|
||||
@@ -31,3 +31,7 @@ networks:
|
||||
external: true
|
||||
queues:
|
||||
external: true
|
||||
minio:
|
||||
external: true
|
||||
mongo:
|
||||
external: true
|
||||
|
||||
2
blob.py
2
blob.py
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
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_SECRET_KEY = os.getenv("MINIO_SECRET_KEY", "minioadmin")
|
||||
|
||||
|
||||
11
main.py
11
main.py
@@ -5,7 +5,6 @@ import subprocess
|
||||
import time
|
||||
|
||||
from requests import get, post
|
||||
from configurator import configurator
|
||||
from mongo import mongo
|
||||
from blob import minio
|
||||
|
||||
@@ -51,7 +50,7 @@ def call(command: str) -> Response:
|
||||
def get_hosts() -> list[str]:
|
||||
response = get(
|
||||
f"http://configurator/api/v1/fetch?project=certupdater&stage={os.getenv("STAGE")}"
|
||||
)
|
||||
).json()
|
||||
hosts = response["configs"]["hosts"]
|
||||
return list(hosts)
|
||||
|
||||
@@ -105,11 +104,14 @@ def update_host(host: str) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
while True:
|
||||
now = datetime.datetime.now()
|
||||
mongo_hosts = mongo.hosts
|
||||
hosts = get_hosts()
|
||||
print(f"got hosts {hosts}")
|
||||
updated = False
|
||||
for host in get_hosts():
|
||||
for host in hosts:
|
||||
if (
|
||||
now + datetime.timedelta(days=14)
|
||||
> mongo_hosts.get(
|
||||
@@ -118,6 +120,7 @@ while True:
|
||||
):
|
||||
success = update_host(host)
|
||||
if success:
|
||||
print(success)
|
||||
send_notification(
|
||||
f"host {host} was not updated with an error: {success}"
|
||||
)
|
||||
@@ -125,6 +128,8 @@ while True:
|
||||
mongo.update_date(host)
|
||||
updated = True
|
||||
send_notification(f"host {host} updated")
|
||||
else:
|
||||
print(f"Host {host} does not need to be updated")
|
||||
if updated:
|
||||
if os.getenv("STAGE") == "development":
|
||||
container_id_run = call(
|
||||
|
||||
3
mongo.py
3
mongo.py
@@ -4,12 +4,11 @@ import os
|
||||
|
||||
MONGO_USER = os.getenv("MONGO_USER", "mongo")
|
||||
MONGO_PASSWORD = os.getenv("MONGO_PASSWORD", "password")
|
||||
MONGO_HOST = os.getenv("MONGO_HOST", "localhost")
|
||||
|
||||
|
||||
class Mongo:
|
||||
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.database = self.client.get_database("certupdater")
|
||||
self.hosts_collection.create_index([
|
||||
|
||||
Reference in New Issue
Block a user