Compare commits
28 Commits
prod
...
a0e06d3ef8
| Author | SHA1 | Date | |
|---|---|---|---|
| a0e06d3ef8 | |||
| f191d7c07a | |||
| 8863b7f7ab | |||
| 41080370c5 | |||
| ff2fbba1aa | |||
| 6b9b6cb3b8 | |||
| 9e3becfc17 | |||
| 96a9bd8fc8 | |||
| 75a8a5e307 | |||
| 5dd11e1fc8 | |||
| d0c26f15e2 | |||
| 560d21c9fe | |||
| 4f0571ec02 | |||
| ad5a22e985 | |||
| d288a8a883 | |||
| 78eeea9e08 | |||
| 1f7cef1f4b | |||
| 6cedf34b8e | |||
| df0af634d6 | |||
| 41072ac03f | |||
| 43191f99a9 | |||
| 41dea63243 | |||
| ee9c363b56 | |||
| 1ad823a301 | |||
| ded08985b5 | |||
| cb847f8b8f | |||
| a7b082dc7a | |||
| 741eed066c |
@@ -6,7 +6,9 @@ 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:
|
||||
@@ -14,8 +16,6 @@ services:
|
||||
networks:
|
||||
- configurator
|
||||
- queues-development
|
||||
- minio-development
|
||||
- mongo-development
|
||||
deploy:
|
||||
mode: replicated
|
||||
restart_policy:
|
||||
@@ -31,7 +31,3 @@ networks:
|
||||
external: true
|
||||
queues-development:
|
||||
external: true
|
||||
minio-development:
|
||||
external: true
|
||||
mongo-development:
|
||||
external: true
|
||||
|
||||
@@ -6,7 +6,9 @@ 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:
|
||||
@@ -14,8 +16,6 @@ services:
|
||||
networks:
|
||||
- configurator
|
||||
- queues
|
||||
- minio
|
||||
- mongo
|
||||
deploy:
|
||||
mode: replicated
|
||||
restart_policy:
|
||||
@@ -31,7 +31,3 @@ 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 = "minio:9000"
|
||||
MINIO_HOST = os.getenv("MINIO_HOST", "localhost") + ":9000"
|
||||
MINIO_ACCESS_KEY = os.getenv("MINIO_ACCESS_KEY", "serviceminioadmin")
|
||||
MINIO_SECRET_KEY = os.getenv("MINIO_SECRET_KEY", "minioadmin")
|
||||
|
||||
|
||||
74
main.py
74
main.py
@@ -104,47 +104,45 @@ 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 hosts:
|
||||
if (
|
||||
now + datetime.timedelta(days=14)
|
||||
> mongo_hosts.get(
|
||||
host, {"expire_time": datetime.datetime.fromtimestamp(1)}
|
||||
)["expire_time"]
|
||||
):
|
||||
success = update_host(host)
|
||||
if success:
|
||||
print(success)
|
||||
send_notification(
|
||||
f"host {host} was not updated with an error: {success}"
|
||||
)
|
||||
else:
|
||||
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(
|
||||
"echo $(docker ps -q -f name=infra-development_nginx)"
|
||||
while True:
|
||||
now = datetime.datetime.now()
|
||||
mongo_hosts = mongo.hosts
|
||||
hosts = get_hosts()
|
||||
print(f"got hosts {hosts}")
|
||||
updated = False
|
||||
for host in hosts:
|
||||
if (
|
||||
now + datetime.timedelta(days=14)
|
||||
> mongo_hosts.get(
|
||||
host, {"expire_time": datetime.datetime.fromtimestamp(1)}
|
||||
)["expire_time"]
|
||||
):
|
||||
success = update_host(host)
|
||||
if success:
|
||||
send_notification(
|
||||
f"host {host} was not updated with an error: {success}"
|
||||
)
|
||||
else:
|
||||
container_id_run = call("echo $(docker ps -q -f name=infra_nginx)")
|
||||
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(
|
||||
"echo $(docker ps -q -f name=infra-development_nginx)"
|
||||
)
|
||||
else:
|
||||
container_id_run = call("echo $(docker ps -q -f name=infra_nginx)")
|
||||
|
||||
print(container_id_run.code, container_id_run.out, container_id_run.err)
|
||||
print(container_id_run.code, container_id_run.out, container_id_run.err)
|
||||
|
||||
command = f"docker exec {container_id_run.out.strip()} ./refre.sh"
|
||||
print(command)
|
||||
command = f"docker exec {container_id_run.out.strip()} ./refre.sh"
|
||||
print(command)
|
||||
|
||||
restart = call(command)
|
||||
print(restart.code, restart.out, restart.err)
|
||||
send_notification(f"Balancer for {os.getenv("STAGE")} was restarted")
|
||||
restart = call(command)
|
||||
print(restart.code, restart.out, restart.err)
|
||||
send_notification(f"Balancer for {os.getenv("STAGE")} was restarted")
|
||||
|
||||
time.sleep(30)
|
||||
time.sleep(30)
|
||||
|
||||
3
mongo.py
3
mongo.py
@@ -4,11 +4,12 @@ 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:27017/"
|
||||
url = f"mongodb://{MONGO_USER}:{MONGO_PASSWORD}@{MONGO_HOST}: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