-
Notifications
You must be signed in to change notification settings - Fork 52
/
tasks.py
100 lines (75 loc) · 2.48 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
from invoke import task
import datetime
import os
import shutil
def start_docker_db(c):
# turn on docker database if not already on
if shutil.which("docker-compose"):
c.run("docker-compose --profile db up -d db")
else:
c.run("docker compose --profile db up -d db")
os.environ[
"DATABASE_URL"
] = "postgres://openstates:openstates@localhost:5405/openstatesorg"
def get_next_tag(c):
prefix = datetime.datetime.today().strftime("%Y.%m")
release_num = 1
last_tag = c.run("git tag", hide="out").stdout.splitlines()[-1]
print("last tag is", last_tag)
while f"{prefix}.{release_num}" <= last_tag:
release_num += 1
return f"{prefix}.{release_num:02}"
def poetry_install(c):
c.run("poetry install")
@task
def test(c, args="", docker_db=True):
if docker_db:
start_docker_db(c)
c.run("poetry run pytest --ds web.test_settings --reuse-db " + args, pty=True)
@task
def lint(c):
c.run(
"poetry run flake8 --show-source --statistics",
pty=True,
)
c.run("poetry run black --check --diff .", pty=True)
@task
def runserver(c, docker_db=True):
if docker_db:
start_docker_db(c)
c.run("poetry run ./manage.py runserver", pty=True)
@task
def deploy(c):
# for ansible on OSX
os.environ["OBJC_DISABLE_INITIALIZE_FORK_SAFETY"] = "YES"
NEWRELIC_APP_ID = c.run(
"aws ssm get-parameter --name /site/NEWRELIC_OPENSTATES_APP_ID --with-decryption | jq -r .Parameter.Value",
hide="out",
).stdout.strip()
NEWRELIC_API_KEY = c.run(
"aws ssm get-parameter --name /site/NEWRELIC_API_KEY --with-decryption | jq -r .Parameter.Value",
hide="out",
).stdout.strip()
with c.cd("ansible"):
c.run("ansible-playbook -D openstates.yml -i inventory/", pty=True)
# tag the release in git and newrelic
next_tag = get_next_tag(c)
c.run(
f"""curl -X POST \
"https://api.newrelic.com/v2/applications/{NEWRELIC_APP_ID}/deployments.json" \
-H "X-Api-Key:{NEWRELIC_API_KEY}" -i \
-H "Content-Type: application/json" \
-d \
'{{ "deployment": {{ "revision": "{next_tag}", "changelog": "", "description": "", "user": "" }} }}'
"""
)
c.run(f"git tag {next_tag}")
c.run("git push --tags")
# npm stuff: not sure these provide any value right now...
@task
def npm_build(c):
"""build node scripts"""
c.run("npm run build", pty=True)
@task
def npm_watch(c):
c.run("npm run start", pty=True)