Compare commits
No commits in common. "43191f99a99505753a6ae92ad24fac6a635d018b" and "41dea632432bbe541b4a044811bb2bec33cded9f" have entirely different histories.
43191f99a9
...
41dea63243
@ -16,11 +16,9 @@ services:
|
||||
networks:
|
||||
- configurator
|
||||
deploy:
|
||||
mode: replicated
|
||||
mode: global
|
||||
restart_policy:
|
||||
condition: any
|
||||
placement:
|
||||
constraints: [node.labels.stage == development]
|
||||
update_config:
|
||||
parallelism: 1
|
||||
order: start-first
|
||||
|
@ -2,29 +2,44 @@ version: "3.4"
|
||||
|
||||
|
||||
services:
|
||||
certupdater:
|
||||
image: mathwave/sprint-repo:certupdater
|
||||
worker:
|
||||
image: mathwave/sprint-repo:pizda-bot
|
||||
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:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
networks:
|
||||
- queues
|
||||
- configurator
|
||||
deploy:
|
||||
mode: replicated
|
||||
restart_policy:
|
||||
condition: any
|
||||
placement:
|
||||
constraints: [node.labels.stage == production]
|
||||
update_config:
|
||||
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:
|
||||
parallelism: 1
|
||||
order: start-first
|
||||
|
||||
networks:
|
||||
common-infra-nginx:
|
||||
external: true
|
||||
queues:
|
||||
external: true
|
||||
configurator:
|
||||
external: true
|
||||
|
@ -40,5 +40,4 @@ jobs:
|
||||
- name: deploy
|
||||
env:
|
||||
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 certupdater
|
||||
run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-prod.yaml pizda-bot
|
||||
|
17
main.py
17
main.py
@ -1,6 +1,5 @@
|
||||
import datetime
|
||||
import io
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
from configurator import configurator
|
||||
@ -28,16 +27,13 @@ def get_hosts() -> list[str]:
|
||||
|
||||
|
||||
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)")
|
||||
else:
|
||||
container_id_run = call(f"echo $(docker ps -q -f name=infra_nginx)")
|
||||
container_id_run = call(f"echo $(docker ps -q -f name=infra-development_nginx)")
|
||||
if container_id_run.code != 0:
|
||||
print(f"something wrong {container_id_run.err}")
|
||||
return False
|
||||
container_name = container_id_run.out.strip()
|
||||
if not container_name:
|
||||
print("No nginx container")
|
||||
print("Not correct node")
|
||||
return False
|
||||
|
||||
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:
|
||||
now = datetime.datetime.now()
|
||||
mongo_hosts = mongo.hosts
|
||||
updated = False
|
||||
for host in get_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(f"Host {host} updated")
|
||||
mongo.update_date(host)
|
||||
updated = True
|
||||
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)
|
||||
time.sleep(5 * 60)
|
Loading…
Reference in New Issue
Block a user