/
make.py
executable file
路195 lines (150 loc) 路 5.12 KB
/
make.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env python
# http://stackoverflow.com/a/14050282
def check_antipackage():
from sys import version_info
sys_version = version_info[:2]
found = True
if sys_version < (3, 0):
# 'python 2'
from pkgutil import find_loader
found = find_loader('antipackage') is not None
elif sys_version <= (3, 3):
# 'python <= 3.3'
from importlib import find_loader
found = find_loader('antipackage') is not None
else:
# 'python >= 3.4'
from importlib import util
found = util.find_spec('antipackage') is not None
if not found:
print('Install missing package "antipackage"')
print('Example: pip install git+https://github.com/ellisonbg/antipackage.git#egg=antipackage')
from sys import exit
exit(1)
check_antipackage()
# ref: https://github.com/ellisonbg/antipackage
import antipackage
from github.appscode.libbuild import libbuild, pydotenv
import os
import os.path
import subprocess
import sys
from os.path import expandvars, join, dirname
libbuild.REPO_ROOT = expandvars('$GOPATH') + '/src/github.com/appscode/voyager'
BUILD_METADATA = libbuild.metadata(libbuild.REPO_ROOT)
libbuild.BIN_MATRIX = {
'voyager': {
'type': 'go',
'go_version': True,
'use_cgo': False,
'distro': {
'linux': ['amd64']
}
}
}
libbuild.BUCKET_MATRIX = {
'prod': 'gs://appscode-cdn',
'dev': 'gs://appscode-dev'
}
def call(cmd, stdin=None, cwd=libbuild.REPO_ROOT):
print(cmd)
return subprocess.call([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd)
def die(status):
if status:
sys.exit(status)
def check_output(cmd, stdin=None, cwd=libbuild.REPO_ROOT):
print(cmd)
return subprocess.check_output([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd)
def version():
# json.dump(BUILD_METADATA, sys.stdout, sort_keys=True, indent=2)
for k in sorted(BUILD_METADATA):
print(k + '=' + BUILD_METADATA[k])
def fmt():
libbuild.ungroup_go_imports('cmd', 'pkg', 'test')
die(call('goimports -w cmd pkg test'))
call('gofmt -s -w cmd pkg test')
def vet():
call('go vet ./cmd/... ./pkg/... ./test/...')
def lint():
call('golint ./cmd/... ./test/...')
call('golint ./pkg/... ./test/...')
def gen():
return
def build_cmd(name):
cfg = libbuild.BIN_MATRIX[name]
if cfg['type'] == 'go':
if 'distro' in cfg:
for goos, archs in cfg['distro'].items():
for goarch in archs:
libbuild.go_build(name, goos, goarch, main='cmd/{}/*.go'.format(name))
else:
libbuild.go_build(name, libbuild.GOHOSTOS, libbuild.GOHOSTARCH, main='cmd/{}/*.go'.format(name))
def build_cmds():
gen()
for name in libbuild.BIN_MATRIX:
build_cmd(name)
def build(name=None):
if name:
cfg = libbuild.BIN_MATRIX[name]
if cfg['type'] == 'go':
gen()
build_cmd(name)
else:
build_cmds()
def push(name=None):
if name:
bindir = libbuild.REPO_ROOT + '/dist/' + name
push_bin(bindir)
else:
dist = libbuild.REPO_ROOT + '/dist'
for name in os.listdir(dist):
d = dist + '/' + name
if os.path.isdir(d):
push_bin(d)
def push_bin(bindir):
call('rm -f *.md5', cwd=bindir)
call('rm -f *.sha1', cwd=bindir)
for f in os.listdir(bindir):
if os.path.isfile(bindir + '/' + f):
libbuild.upload_to_cloud(bindir, f, BUILD_METADATA['version'])
def update_registry():
libbuild.update_registry(BUILD_METADATA['version'])
def install():
die(call('GO15VENDOREXPERIMENT=1 ' + libbuild.GOC + ' install ./cmd/...'))
def test(type, *args):
die(call(libbuild.GOC + ' install ./cmd/...'))
pydotenv.load_dotenv(join(dirname(__file__), 'configs/.env'))
if type == 'unit':
unit_test()
elif type == 'e2e':
e2e_test(args)
elif type == 'minikube':
e2e_test_minikube(args)
elif type == 'integration' or type == 'intg':
integration(args)
elif type == 'clean':
e2e_test_clean()
else:
print '{test unit|minikube|e2e}'
def unit_test():
die(call(libbuild.GOC + ' test -v ./cmd/... ./pkg/... -args -v=3 -verbose=true -mode=unit'))
def e2e_test(args):
st = ' '.join(args)
die(call(libbuild.GOC + ' test -v ./test/e2e/... -timeout 10h -args -v=3 -verbose=true -mode=e2e ' + st))
def e2e_test_minikube(args):
st = ' '.join(args)
die(call(libbuild.GOC + ' test -v ./test/e2e/... -timeout 10h -args -v=3 -verbose=true -mode=e2e -cloud-provider=minikube -cluster-name=minikube ' + st))
def integration(args):
st = ' '.join(args)
die(call(libbuild.GOC + ' test -v ./test/integration/... -timeout 10h -args -v=3 -verbose=true -mode=e2e -in-cluster=true ' + st))
def default():
gen()
fmt()
die(call('GO15VENDOREXPERIMENT=1 ' + libbuild.GOC + ' install ./cmd/...'))
if __name__ == "__main__":
if len(sys.argv) > 1:
# http://stackoverflow.com/a/834451
# http://stackoverflow.com/a/817296
globals()[sys.argv[1]](*sys.argv[2:])
else:
default()