forked from allenai/pawls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubeconf
executable file
·70 lines (67 loc) · 2.63 KB
/
kubeconf
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
from os import path, getlogin, devnull
from argparse import ArgumentParser
from subprocess import check_call, check_output
def configure(env, api, proxy, message, silent = False):
builder_image = "gcr.io/ai2-reviz/jsonnet"
stdout = open(devnull) if silent == True else None
check_call(["docker", "pull", builder_image ], stdout=stdout)
root = path.abspath(path.join(path.dirname(__file__), ".."))
sha = check_output([ "git", "rev-parse", "HEAD" ]).decode("utf-8").strip()
branch = check_output([ "git", "rev-parse", "--abbrev-ref", "HEAD" ]).decode("utf-8").strip()
cmd = [
"docker",
"run",
"--rm",
"-it",
"-v", "%s:/workspace" % root,
builder_image,
"eval",
"-y",
"--output-file", "/workspace/.skiff/webapp.yaml",
"--tla-str", "proxyImage=%s" % proxy,
"--tla-str", "apiImage=%s" % api,
"--tla-str", "cause=%s" % message,
"--tla-str", "env=%s" % env,
"--tla-str", "sha=%s" % sha,
"--tla-str", "branch=%s" % branch,
"/workspace/.skiff/webapp.jsonnet"
]
# The docker run command needs a valid stdout to write to, which means
# if the silent flag is enabled we need to capture and discard the output
if silent == True:
check_output(cmd)
else:
check_call(cmd)
config = path.abspath(path.join(root, ".skiff", "webapp.yaml"))
return config
if __name__ == "__main__":
parser = ArgumentParser(prog="kubeconf",
description="Utility for generating the kubernetes manifest for a given environment")
parser.add_argument("--env", "-e", default="staging", type=str,
help="The value of the $_ENV cloudbuild variable")
parser.add_argument("--api", "-a", type=str,
help="The target API image.", required=True)
parser.add_argument("--proxy", "-p", type=str,
help="The target Proxy image.", required=True)
parser.add_argument("--message", "-m", type=str,
help="The reason behind the deployment", required=True)
formats = set([ "text", "json" ])
parser.add_argument("--output", "-o", type=str, choices=formats,
help="The output format.", default="text")
parser.add_argument("-s", "--silent", action="store_true", default=False,
help="If specified verbose output is disabled.")
args = parser.parse_args()
output = configure(
args.env,
args.api,
args.proxy,
args.message,
args.silent
)
if args.output == "text":
print("✨ successfully wrote %s" % output)
else:
print(json.dumps(output))