commit
43191f99a9
@ -16,9 +16,11 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- configurator
|
- configurator
|
||||||
deploy:
|
deploy:
|
||||||
mode: global
|
mode: replicated
|
||||||
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
|
||||||
|
@ -2,44 +2,29 @@ version: "3.4"
|
|||||||
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
worker:
|
certupdater:
|
||||||
image: mathwave/sprint-repo:pizda-bot
|
image: mathwave/sprint-repo:certupdater
|
||||||
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
|
||||||
update_config:
|
placement:
|
||||||
parallelism: 1
|
constraints: [node.labels.stage == production]
|
||||||
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
|
||||||
|
@ -40,4 +40,5 @@ jobs:
|
|||||||
- name: deploy
|
- name: deploy
|
||||||
env:
|
env:
|
||||||
MONGO_PASSWORD_PROD: ${{ secrets.MONGO_PASSWORD_PROD }}
|
MONGO_PASSWORD_PROD: ${{ secrets.MONGO_PASSWORD_PROD }}
|
||||||
run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-prod.yaml pizda-bot
|
MINIO_SECRET_KEY_PROD: ${{ secrets.MINIO_SECRET_KEY_PROD }}
|
||||||
|
run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-prod.yaml certupdater
|
||||||
|
15
main.py
15
main.py
@ -1,5 +1,6 @@
|
|||||||
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
|
||||||
@ -27,13 +28,16 @@ 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("Not correct node")
|
print("No nginx container")
|
||||||
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}\""
|
||||||
@ -66,10 +70,17 @@ 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)
|
||||||
time.sleep(5 * 60)
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user