-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
83 lines (67 loc) · 2.43 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 shutil
from invoke import task
from os import getenv as env
from dotenv import load_dotenv
from os.path import join, dirname, exists
load_dotenv(join(dirname(__file__), '.env'))
STACK_NAME = env('STACK_NAME', 'gitwishes')
PACKAGE_BUCKET_NAME = env('PACKAGE_BUCKET_NAME')
AWS_PROFILE = env('AWS_PROFILE')
@task
def build_deps(ctx):
build_path = join(dirname(__file__), 'dist')
function_path = join(dirname(__file__), 'function.py')
req_file = join(dirname(__file__), 'requirements.txt')
cmd = "pip install -U -r {} -t {}".format(req_file, build_path)
ctx.run(cmd)
ctx.run("ln -s -r -t {} {}".format(build_path, function_path))
@task
def package(ctx):
profile = ""
if AWS_PROFILE is not None:
profile = "--profile {}".format(AWS_PROFILE)
cmd = ("aws {} cloudformation package --s3-bucket {} "
"--template-file template.yml --s3-prefix packages "
"--output-template-file serverless-output.yml"
).format(profile, PACKAGE_BUCKET_NAME)
ctx.run(cmd)
@task
def deploy(ctx):
profile = ""
if AWS_PROFILE is not None:
profile = "--profile {}".format(AWS_PROFILE)
template_params = {
'TwitterConsumerKey': env('TWITTER_CONSUMER_KEY'),
'TwitterConsumerSecret': env('TWITTER_CONSUMER_SECRET'),
'TwitterAccessToken': env('TWITTER_ACCESS_TOKEN'),
'TwitterAccessTokenSecret': env('TWITTER_ACCESS_TOKEN_SECRET'),
'ExcludeRepos': env('EXCLUDE_REPOS')
}
param_overrides = " ".join(
["{}={}".format(k, v) for k, v in template_params.items()]
)
cmd = ("aws {} cloudformation deploy "
"--template-file serverless-output.yml "
"--capabilities CAPABILITY_NAMED_IAM --stack-name {} "
"--parameter-overrides {}"
).format(profile, STACK_NAME, param_overrides)
ctx.run(cmd)
@task
def delete(ctx):
profile = ""
if AWS_PROFILE is not None:
profile = "--profile {}".format(AWS_PROFILE)
cmd = ("aws {} cloudformation delete-stack "
"--stack-name {}").format(profile, STACK_NAME)
ctx.run(cmd)
@task
def clean(ctx):
profile = ""
if AWS_PROFILE is not None:
profile = "--profile {}".format(AWS_PROFILE)
cmd = ("aws {} s3 rm --recursive "
"s3://{}/packages").format(profile, PACKAGE_BUCKET_NAME)
ctx.run(cmd)
build_path = join(dirname(__file__), 'dist')
if exists(build_path):
shutil.rmtree(build_path)