forked from mozilla-conduit/autoland-transplant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy
executable file
·82 lines (71 loc) · 2.67 KB
/
deploy
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
#!/usr/bin/env python2
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import argparse
import datetime
import os
import subprocess
import sys
DEBUG = bool(os.getenv('DEBUG'))
ROOT = os.path.abspath(os.path.dirname(__file__))
def main():
parser = argparse.ArgumentParser(description='deploy autoland-transplant')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--production', '--prod', action='store_true',
help='deploy to production')
group.add_argument('--development', '--dev', action='store_true',
help='deploy to development')
parser.add_argument('--seed', action='store_true',
help='seed secrets instead of a full deploy')
parser.add_argument('--secrets-repo-path',
help='path to secrets repository')
parser.add_argument('--verbose', '-v', action='store_true',
help='verbose output')
args = parser.parse_args()
start = datetime.datetime.now()
try:
os.chdir(os.path.join(ROOT, 'ansible'))
cmd = ['ansible-playbook']
if args.verbose:
cmd.append('-v')
if args.seed:
action = 'Seeding Secrets'
cmd.append('autoland-seed-secrets.yml')
if args.secrets_repo_path:
cmd.extend(['-e', 'secrets_repo_path=%s'
% args.secrets_repo_path])
cmd.append('--ask-vault-pass')
else:
action = 'Deploying'
cmd.append('autoland-ec2-provision.yml')
if args.production:
target = 'Production'
cmd.extend(['-i', 'hosts_autoland_prod'])
else:
target = 'Development'
cmd.extend(['-i', 'hosts_autoland_dev'])
print('%s to %s...' % (action, target))
if DEBUG:
print(cmd)
subprocess.check_call(cmd)
except KeyboardInterrupt:
pass
except Exception as e:
if DEBUG:
raise
print(e)
sys.exit(1)
finally:
seconds = (datetime.datetime.now() - start).total_seconds()
if seconds > 5:
hours, seconds = divmod(seconds, 3600)
minutes, seconds = divmod(seconds, 60)
if hours > 0:
duration = '%dh%dm%ds' % (hours, minutes, seconds)
elif minutes > 0:
duration = '%dm%ds' % (minutes, seconds)
else:
duration = '%ds' % seconds
print('Elapsed: %s' % duration)
main()