Compare commits

..

No commits in common. "43191f99a99505753a6ae92ad24fac6a635d018b" and "41dea632432bbe541b4a044811bb2bec33cded9f" have entirely different histories.

4 changed files with 28 additions and 27 deletions

View File

@ -16,11 +16,9 @@ services:
networks: networks:
- configurator - configurator
deploy: deploy:
mode: replicated mode: global
restart_policy: restart_policy:
condition: any condition: any
placement:
constraints: [node.labels.stage == development]
update_config: update_config:
parallelism: 1 parallelism: 1
order: start-first order: start-first

View File

@ -2,29 +2,44 @@ version: "3.4"
services: services:
certupdater: worker:
image: mathwave/sprint-repo:certupdater image: mathwave/sprint-repo:pizda-bot
command: worker command: worker
environment: environment:
MINIO_HOST: "minio.sprinthub.ru"
MINIO_SECRET_KEY: $MINIO_SECRET_KEY_PROD
MONGO_HOST: "mongo.sprinthub.ru" MONGO_HOST: "mongo.sprinthub.ru"
MONGO_PASSWORD: $MONGO_PASSWORD_PROD MONGO_PASSWORD: $MONGO_PASSWORD_PROD
STAGE: "production" STAGE: "production"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks: networks:
- queues
- configurator - configurator
deploy: deploy:
mode: replicated mode: replicated
restart_policy: restart_policy:
condition: any condition: any
placement: update_config:
constraints: [node.labels.stage == production] parallelism: 1
order: start-first
pizda-bot-nginx:
image: mathwave/sprint-repo:pizda-bot
command: api
environment:
MONGO_HOST: "mongo.sprinthub.ru"
MONGO_PASSWORD: $MONGO_PASSWORD_PROD
networks:
- common-infra-nginx
deploy:
mode: replicated
restart_policy:
condition: any
update_config: update_config:
parallelism: 1 parallelism: 1
order: start-first order: start-first
networks: networks:
common-infra-nginx:
external: true
queues:
external: true
configurator: configurator:
external: true external: true

View File

@ -40,5 +40,4 @@ jobs:
- name: deploy - name: deploy
env: env:
MONGO_PASSWORD_PROD: ${{ secrets.MONGO_PASSWORD_PROD }} MONGO_PASSWORD_PROD: ${{ secrets.MONGO_PASSWORD_PROD }}
MINIO_SECRET_KEY_PROD: ${{ secrets.MINIO_SECRET_KEY_PROD }} run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-prod.yaml pizda-bot
run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-prod.yaml certupdater

17
main.py
View File

@ -1,6 +1,5 @@
import datetime import datetime
import io import io
import os
import subprocess import subprocess
import time import time
from configurator import configurator from configurator import configurator
@ -28,16 +27,13 @@ def get_hosts() -> list[str]:
def update_host(host: str) -> bool: def update_host(host: str) -> bool:
if os.getenv("STAGE") == "development": container_id_run = call(f"echo $(docker ps -q -f name=infra-development_nginx)")
container_id_run = call(f"echo $(docker ps -q -f name=infra-development_nginx)")
else:
container_id_run = call(f"echo $(docker ps -q -f name=infra_nginx)")
if container_id_run.code != 0: if container_id_run.code != 0:
print(f"something wrong {container_id_run.err}") print(f"something wrong {container_id_run.err}")
return False return False
container_name = container_id_run.out.strip() container_name = container_id_run.out.strip()
if not container_name: if not container_name:
print("No nginx container") print("Not correct node")
return False return False
gen_command = f"docker exec {container_name} certbot --nginx --email emmtvv@gmail.com --agree-tos --non-interactive -d \"{host}\"" gen_command = f"docker exec {container_name} certbot --nginx --email emmtvv@gmail.com --agree-tos --non-interactive -d \"{host}\""
@ -70,17 +66,10 @@ def update_host(host: str) -> bool:
while True: while True:
now = datetime.datetime.now() now = datetime.datetime.now()
mongo_hosts = mongo.hosts mongo_hosts = mongo.hosts
updated = False
for host in get_hosts(): for host in get_hosts():
if now + datetime.timedelta(days=14) > mongo_hosts.get(host, {"expire_time": datetime.datetime.fromtimestamp(1)})["expire_time"]: if now + datetime.timedelta(days=14) > mongo_hosts.get(host, {"expire_time": datetime.datetime.fromtimestamp(1)})["expire_time"]:
success = update_host(host) success = update_host(host)
if success: if success:
print(f"Host {host} updated") print(f"Host {host} updated")
mongo.update_date(host) mongo.update_date(host)
updated = True time.sleep(5 * 60)
if updated:
if os.getenv("STAGE") == "development":
call("docker service update --force infra-development_nginx")
else:
call("docker service update --force infra_nginx")
time.sleep(30)