Compare commits

..

12 Commits

Author SHA1 Message Date
75b1ccdeb2 Merge pull request 'fix' (#59) from master into prod
Reviewed-on: #59
2025-09-15 01:37:13 +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
d2f8022910 Merge pull request 'master' (#57) from master into prod
Reviewed-on: #57
2025-06-12 13:30:56 +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
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
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
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
911c6225dc Merge pull request 'master' (#48) from master into prod
Reviewed-on: #48
2025-06-12 01:58:33 +03:00
a85e7d4ee2 Merge pull request 'fix' (#36) from master into prod
Reviewed-on: #36
2025-06-04 21:14:44 +03:00
88fa100c07 Merge pull request 'fix' (#34) from master into prod
Reviewed-on: #34
2025-06-04 03:07:23 +03:00
dba11ffb3d Merge pull request 'fix' (#33) from master into prod
Reviewed-on: #33
2025-06-04 02:56:27 +03:00
55323f1be1 Merge pull request 'master' (#32) from master into prod
Reviewed-on: #32
2025-06-04 02:53:40 +03:00
6 changed files with 52 additions and 40 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")

71
main.py
View File

@@ -52,7 +52,6 @@ def get_hosts() -> list[str]:
f"http://configurator/api/v1/fetch?project=certupdater&stage={os.getenv("STAGE")}" f"http://configurator/api/v1/fetch?project=certupdater&stage={os.getenv("STAGE")}"
).json() ).json()
hosts = response["configs"]["hosts"] hosts = response["configs"]["hosts"]
print(f"got hosts {hosts}")
return list(hosts) return list(hosts)
@@ -105,41 +104,47 @@ def update_host(host: str) -> str | None:
return None return None
while True: if __name__ == "__main__":
now = datetime.datetime.now() while True:
mongo_hosts = mongo.hosts now = datetime.datetime.now()
updated = False mongo_hosts = mongo.hosts
for host in get_hosts(): hosts = get_hosts()
if ( print(f"got hosts {hosts}")
now + datetime.timedelta(days=14) updated = False
> mongo_hosts.get( for host in hosts:
host, {"expire_time": datetime.datetime.fromtimestamp(1)} if (
)["expire_time"] now + datetime.timedelta(days=14)
): > mongo_hosts.get(
success = update_host(host) host, {"expire_time": datetime.datetime.fromtimestamp(1)}
if success: )["expire_time"]
send_notification( ):
f"host {host} was not updated with an error: {success}" 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)"
) )
else: else:
mongo.update_date(host) container_id_run = call("echo $(docker ps -q -f name=infra_nginx)")
updated = True
send_notification(f"host {host} 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" command = f"docker exec {container_id_run.out.strip()} ./refre.sh"
print(command) print(command)
restart = call(command) restart = call(command)
print(restart.code, restart.out, restart.err) print(restart.code, restart.out, restart.err)
send_notification(f"Balancer for {os.getenv("STAGE")} was restarted") send_notification(f"Balancer for {os.getenv("STAGE")} was restarted")
time.sleep(30) time.sleep(30)

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([