forked from nylas/nylas-mail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-it
executable file
·64 lines (56 loc) · 2.37 KB
/
deploy-it
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# deploy-it is the script we use to deploy changes to our Nylas Mail backend systems.
# it tags releases automatically and helps prevent obvious mistakes like
# deploying a non-production branch to our prod infra.
import sys
import subprocess
if len(sys.argv) != 2 or sys.argv[1] in ('-h', '--help'):
print "deploy-it is the script we use to deploy changes to our Nylas Mail backend systems."
print
print "usage: ./deploy-it environment"
print
print "The currently checked out commit will be deployed!"
sys.exit(-1)
environment = sys.argv[1]
level = 'prod'
if 'staging' in environment or 'ei-prod' in environment:
level = 'staging'
elif 'dev' in environment:
level = 'dev'
branch = subprocess.check_output('git rev-parse --abbrev-ref HEAD'.split()).strip()
if level == 'prod' and branch != 'production':
sys.exit("Deploys to production environments must be made from the 'production' "
"branch.")
if level == 'prod':
print "Fetching latest repo data."
# this can fail for all sorts of reasons; best to just let a human
# deal with any errors
try:
subprocess.check_call(['git', 'pull'])
except:
sys.exit("`git pull` failed — can't proceed.")
# Tag the deploy so that we know exactly what has been deployed by whom.
short_commit = subprocess.check_output('git rev-parse --short HEAD'.split()).strip()
username = subprocess.check_output(['whoami']).strip()
tag_name = "{}-{}-{}".format(short_commit, environment, username)
# Check if the tag already exists.
if subprocess.call(['git', 'rev-parse', '-q', '--verify', tag_name]) != 0:
# If not create it.
try:
print "Tagging deploy..."
subprocess.check_call(['git', 'tag', '-a', tag_name, '-m', "'{}'".format(tag_name)])
subprocess.check_call(['git', 'push', 'origin', tag_name])
except:
sys.exit("Unable to create and save tag — won't proceed.")
# Hand things off to `eb deploy`. It will push a tagged release to EB.
try:
print "Handing off to `eb deploy`... (this may take some time!)"
print
print "You can monitor your deploy using the Elastic Beanstalk console:"
print "https://us-west-2.console.aws.amazon.com/elasticbeanstalk/home?region=us-west-2#/applications"
print
subprocess.check_call(['eb', 'deploy', environment])
except:
sys.exit("eb deploy failed!")