-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
executable file
·83 lines (67 loc) · 2.17 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import invoke
import kubesae
import yaml
from colorama import init
init(autoreset=True)
@invoke.task
def staging(c):
c.config.env = "staging"
c.config.namespace = "trafficstops-staging"
@invoke.task
def production(c):
c.config.env = "production"
c.config.namespace = "trafficstops-production"
@invoke.task
def pod_stats(c):
"""Report total pods vs pod capacity."""
nodes = yaml.safe_load(c.run("kubectl get nodes -o yaml", hide="out").stdout)
pod_capacity = sum([int(item["status"]["capacity"]["pods"]) for item in nodes["items"]])
pod_total = c.run(
"kubectl get pods --all-namespaces | grep Running | wc -l", hide="out"
).stdout.strip()
print(f"Running pods: {pod_total}")
print(f"Maximum pods: {pod_capacity}")
print(f"Total nodes: {len(nodes['items'])}")
@invoke.task
def ansible_playbook(c, name, extra="", verbosity=1):
with c.cd("deploy/"):
c.run(f"ansible-playbook {name} {extra} -{'v'*verbosity}")
@invoke.task
def deploy_html_notebooks(c, dir_name):
"""Upload html exports of Jupyter Notebooks to S3"""
c.run(
"aws s3 sync --acl public-read --exclude '*' --include '*.html' "
f"nc/notebooks/{dir_name}/ s3://nccopwatch-share/{dir_name}/"
)
ns = invoke.Collection()
ns.add_collection(kubesae.image)
ns.add_collection(kubesae.aws)
ns.add_collection(kubesae.deploy)
ns.add_collection(kubesae.pod)
ns.add_collection(kubesae.info)
ns.add_collection(kubesae.utils)
ns.add_task(staging)
ns.add_task(production)
ns.add_task(pod_stats)
ns.add_task(ansible_playbook, "playbook")
ns.add_task(deploy_html_notebooks)
ns.configure(
{
"app": "trafficstops_app",
"app_build_target": "deploy",
"aws": {
"region": "us-east-2",
},
"cluster": "trafficstops-stack-cluster",
"container_name": "app",
"hosting_services_backup_folder": "trafficstops",
"repository": "606178775542.dkr.ecr.us-east-2.amazonaws.com/traff-appli-gvyudgfsjhrz",
"run": {
"echo": True,
"pty": True,
"env": {
"COMPOSE_FILE": "docker-compose.yml:docker-compose.deploy.yml",
},
},
}
)