-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
154 lines (115 loc) · 3.66 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
151
152
153
154
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 = "data_pipeline_practice"
AWS_PROFILE = "default"
AWS_REGION = "us-east-1"
# Must separate these by spaces and indicate directories with trailing /
BLACK_FILEPATH_STR = f"{APP}/ containers/ tests/"
@task
def clean(c):
"""Delete unused code."""
c.run(r"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},
)
klaxon(title=app, subtitle="deployed CDK stack")
else:
print("Please provide a stack to deploy")
@task
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},
)
klaxon(title=app, subtitle="destroyed CDK stack")
else:
print("Please provide a stack to deploy")
@task(optional=["stack"])
def diff(c, profile=AWS_PROFILE, region=AWS_REGION, stack=None):
"""Compare current CDK stack to what was previously deployed."""
if stack:
c.run(
f"cdk diff --profile={profile} {stack}",
pty=True,
env={"AWS_DEFAULT_REGION": region},
)
else:
print("Please provide a stack to deploy")
@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:
print("Please provide a stack to deploy")
@task
def test(c):
"""Runs test suite before committing code"""
c.run("pytest", pty=True)
@task
def s3_bucket_sync(
c, profile=AWS_PROFILE, source_bucket=None, sink_bucket=None
):
"""Sync an S3 bucket with another S3 bucket"""
if not source_bucket or sink_bucket:
source_bucket = "s3://deutsche-boerse-eurex-pds/2017-05-27/"
sink_bucket = "s3://nutrien-blake-enyart-dev/dbg_pds_RAW/"
c.run(f"aws --profile {profile} s3 sync {source_bucket}* {sink_bucket}*")