-
Notifications
You must be signed in to change notification settings - Fork 0
/
apply_specs.py
executable file
·64 lines (53 loc) · 1.72 KB
/
apply_specs.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
#!/usr/bin/env python
import os
import sys
import json
import glob
import subprocess
import urllib
sys.path = ["deps/_/stdlib/"] + sys.path
from escape import path
env = os.environ
kubecfg_path = env['INPUT_kubecfg_path']
specs = env['INPUT_kube_spec_files']
kubectl_version = env['INPUT_METADATA_kubectl_version']
specs = "[]" if specs == "" else specs
try:
specs = json.loads(specs)
except Exception, e:
print "Couldn't parse specs."
print e
sys.exit(1)
if specs == []:
for f in glob.glob("*.yaml"):
specs.append(f)
for f in glob.glob("*.yml"):
if f not in ["escape.yml", "circle.yml"]:
specs.append(f)
kubectl_path = "kubectl"
if not path.is_binary_on_path("kubectl"):
print "kubectl binary is not on PATH"
url = "https://storage.googleapis.com/kubernetes-release/release/v"
url += kubectl_version + "/bin/linux/amd64/kubectl"
print "Downloading kubectl from", url
urllib.urlretrieve(url, "kubectl")
os.chmod("kubectl", 0755)
kubectl_path = os.path.realpath("./kubectl")
path.add_binary_to_path(kubectl_path)
else:
print "Found kubectl binary on path. Skipping download"
for spec in specs:
print "Deploying Kubernetes spec", spec
print
sys.stdout.flush()
cmd = [kubectl_path, "--kubeconfig", kubecfg_path, "apply", "-f", spec]
try:
subprocess.check_output(cmd)
except subprocess.CalledProcessError, e:
print "Failed to run '%s'" % " ".join(cmd)
print e
sys.exit(1)
print "Successfully applied", spec
if specs == []:
print "Didn't find any Kubernetes spec files to apply. You can either supply them "
print "in the `kube_spec_files` variable or drop some .yml files in the current directory."