-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
150 lines (113 loc) · 3.44 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import configparser
import datetime as dt
import os
import sys
import tempfile
import time
from pathlib import Path
from invoke import task, Responder
from klaxon import klaxon
APP = "text_to_speech_pipeline"
AWS_PROFILE = "default"
AWS_REGION = "us-east-1"
# Must separate these by spaces and indicate directories with trailing /
BLACK_FILEPATH_STR = f"{APP}/ tests/ lambdas/"
@task
def clean(c):
"""Delete unused code."""
c.run("find . -name \*.pyc -delete")
c.run("rm shelves/*", warn=True)
c.run("rm -rf cdk.out/*")
@task
def install_hooks(c):
"""Install git hooks."""
c.run("pre-commit install")
c.run("pre-commit install -t pre-push")
# Optionally install commitizen CLI
try:
c.run("commitizen", hide=True)
except:
c.run("npm install -g commitizen")
@task
def uninstall_hooks(c):
"""Uninstall git hooks."""
c.run("pre-commit uninstall")
c.run("pre-commit uninstall -t pre-push")
@task(aliases=["black"])
def format(c):
"""Auto-format Python modules."""
c.run(f"black *.py {BLACK_FILEPATH_STR}")
@task(aliases=["check-black"])
def check_formatting(c):
"""Check that files conform to black standards."""
c.run(f"black --check *.py {BLACK_FILEPATH_STR}")
@task(optional=["stack"])
def deploy(
c, profile=AWS_PROFILE, region=AWS_REGION, force=False, app=APP, stack=None
):
"""Deploy CDK CloudFormation stack(s)."""
if stack:
c.run(
f"cdk deploy --profile={profile} {stack}"
+ (" --require-approval never" if force else ""),
pty=True,
env={"AWS_DEFAULT_REGION": region},
)
else:
c.run(
f"cdk deploy --profile={profile} '*'"
+ (" --require-approval never" if force else ""),
pty=True,
env={"AWS_DEFAULT_REGION": region},
)
klaxon(title=app, subtitle="deployed CDK stack")
@task(optional=["stack"])
def destroy(
c, profile=AWS_PROFILE, region=AWS_REGION, force=False, app=APP, stack=None
):
"""Tear-down CDK CloudFormation stack(s)."""
responder = Responder(
pattern="Are you sure you want to delete.*", response="y\n"
)
if stack:
c.run(
f"cdk destroy --profile={profile} {stack}",
pty=True,
watchers=[responder] if force else [],
env={"AWS_DEFAULT_REGION": region},
)
else:
c.run(
f"cdk destroy --profile={profile} '*'",
pty=True,
watchers=[responder] if force else [],
env={"AWS_DEFAULT_REGION": region},
)
klaxon(title=app, subtitle="destroyed CDK stack")
@task
def diff(c, profile=AWS_PROFILE, region=AWS_REGION):
"""Compare current CDK stack to what was previously deployed."""
c.run(
f"cdk diff --profile={profile}",
pty=True,
env={"AWS_DEFAULT_REGION": region},
)
@task
def ls(c, profile=AWS_PROFILE):
"""List of CDK stacks that are deployable"""
c.run(f"cdk list --profile {profile}")
@task(optional=["stack"])
def synth(c, profile=AWS_PROFILE, region=AWS_REGION, stack=None):
"""Render cdk cloudformation template."""
if stack:
c.run(
f"cdk synth --profile={profile} {stack}",
pty=True,
env={"AWS_DEFAULT_REGION": region},
)
else:
c.run(
f"cdk synth --profile={profile} -e",
pty=True,
env={"AWS_DEFAULT_REGION": region},
)