forked from tilt-dev/tilt-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tiltfile
150 lines (138 loc) · 4.96 KB
/
Tiltfile
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
#!/usr/bin/env python
def kubectl_build(ref, context, build_args={}, dockerfile=None,
dockerfile_contents=None, live_update=[],
match_in_env_vars=False, ignore=[],
entrypoint=[], target=None, ssh=None, secret=None,
extra_tag=None, cache_from=[], cache_to=[],
pull=False, registry_secret=None, push=False,
namespace=None, builder=None, platform=None):
# incompatible parameters with docker_build:
# only
# container_args
# network
if not kubectl_build_enable():
# just run the standard docker_build
kwargs = {}
if ref != None:
kwargs["ref"] = ref
if context != None:
kwargs["context"] = context
if build_args != None:
kwargs["build_args"] = build_args
if dockerfile != None:
kwargs["dockerfile"] = dockerfile
if live_update != None:
kwargs["live_update"] = live_update
if match_in_env_vars != None:
kwargs["match_in_env_vars"] = match_in_env_vars
if ignore != None:
kwargs["ignore"] = ignore
if entrypoint != None:
kwargs["entrypoint"] = entrypoint
if target != None:
kwargs["target"] = target
if ssh != None:
kwargs["ssh"] = ssh
if secret != None:
kwargs["secret"] = secret
if extra_tag != None:
kwargs["extra_tag"] = extra_tag
if cache_from != None:
kwargs["cache_from"] = cache_from
if pull != None:
kwargs["pull"] = pull
if platform != None:
kwargs["platform"] = platform
docker_build(**kwargs)
return
pre_command = ""
if dockerfile_contents != None and dockerfile != None:
fail(
"Cannot specify both dockerfile and dockerfile_contents keyword arguments"
)
elif dockerfile != None:
dockerfile_path = dockerfile
elif dockerfile_contents != None:
pre_command += "echo {} | ".format(shlex.quote(dockerfile_contents))
dockerfile_path = '-'
else:
dockerfile_path = context + '/Dockerfile'
registry_secret = registry_secret or kubectl_build_registry_secret()
command = ['kubectl', 'build', '--context', k8s_context()]
command += ['-f', dockerfile_path]
if registry_secret:
command += ['--registry-secret', registry_secret]
if namespace:
command += ['--namespace', namespace]
if builder:
command += ['--builder', builder]
for arg, value in build_args.items():
command += ['--build-arg', arg + '=' + value]
if target:
command += ['--target', target]
if extra_tag:
if type(extra_tag) == 'string':
command += ['-t', extra_tag]
else:
for t in extra_tag:
command += ['-t', t]
if pull:
command += ['--pull']
if push:
command += ['--push']
for c in cache_from:
command += ['--cache-from', c]
for c in cache_to:
command += ['--cache-to', c]
if ssh:
if type(ssh) == 'string':
command += ['--ssh', ssh]
else:
for s in ssh:
command += ['--ssh', s]
if secret:
if type(secret) == 'string':
command += ['--secret', secret]
else:
for s in secret:
command += ['--secret', s]
if platform:
command += ['--platform', platform]
command = [shlex.quote(c) for c in command]
is_windows = True if os.name == "nt" else False
if is_windows:
command += ['-t', '%EXPECTED_REF%']
else:
command += ['-t', '$EXPECTED_REF']
command += [shlex.quote(context)]
command = pre_command + ' '.join(command)
deps = [context]
if dockerfile_path != '-':
deps.append(dockerfile_path)
custom_build(ref, command, deps, disable_push=True, skips_local_docker=True, live_update=live_update,
match_in_env_vars=match_in_env_vars, ignore=ignore, entrypoint=entrypoint)
def image_build(*args, **kwargs):
"""kubectl_build with a less kubectl build obvious name"""
kubectl_build(*args, **kwargs)
def kubectl_build_enable(v=None):
"""Activate kubectl build"""
if v != None:
os.environ['KUBECTL_BUILD_ENABLE'] = str(v)
return to_bool(v)
else:
return to_bool(os.environ.get('KUBECTL_BUILD_ENABLE', 'on'))
def kubectl_build_registry_secret(v=None):
"""Set/Get kubectl build registry secret"""
if v != None:
os.environ['KUBECTL_BUILD_REGISTRY_SECRET'] = str(v)
return str(v)
else:
return os.environ.get('KUBECTL_BUILD_REGISTRY_SECRET', 'docker-registry')
def to_bool(value):
"""Convert a string to a boolean"""
v = str(value).strip().lower()
if v in ['on', 'true', 'yes', '1']:
return True
if v in ['off', 'false', 'no', '0']:
return False
fail('Unsupported boolean values: ' + str(value))