-
Notifications
You must be signed in to change notification settings - Fork 176
/
Copy pathTiltfile
114 lines (97 loc) · 2.66 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
def _quote(v):
if os.name == 'nt':
return v
return shlex.quote(v)
def _env_key(ref):
out = 'NERDCTL_DF_'
for c in ref.elems():
if c.isalnum():
out += c
else:
out += '_'
return out
def nerdctl_build(
ref,
context,
build_args={},
dockerfile=None,
dockerfile_contents=None,
live_update=[],
match_in_env_vars=False,
ignore=[],
entrypoint=[],
target='',
ssh='',
secret='',
extra_tag='',
cache_from=[],
platform='',
):
cmd = ['nerdctl']
cmd += ['--namespace', 'k8s.io']
cmd += ['build']
for arg, value in build_args.items():
cmd += ['--build-arg', arg + '=' + value]
if dockerfile:
cmd += ['-f', dockerfile]
elif dockerfile_contents:
cmd += ['-f', '-']
if target:
cmd += ['--target', target]
if ssh:
cmd += ['--ssh', ssh]
if secret:
cmd += ['--secret', secret]
if platform:
cmd += ['--platform', platform]
if extra_tag:
if type(extra_tag) == 'string':
cmd += ['-t', extra_tag]
else:
for t in extra_tag:
cmd += ['-t', t]
if cache_from:
if type(cache_from) == 'string':
cmd += ['--cache-from', cache_from]
else:
for v in cache_from:
cmd += ['--cache-from', v]
cmd = [_quote(x) for x in cmd]
# add the expected ref arg _after_ quoting since we actually
# want shell expansion here and quoting will turn this into
# a literal
if os.name == 'nt':
cmd += ['-t', '{percent}EXPECTED_REF{percent}'.format(percent='%')]
else:
cmd += ['-t', '"${EXPECTED_REF}"']
# nerdctl only supports context as a positional arg,
# so it needs to go last and be manually quoted
cmd += [_quote(context)]
cmd = ' '.join(cmd)
kwargs = {}
if dockerfile_contents:
# TODO(milas): this should use `env` arg, but custom_build
# doesn't currently support that
env_key = _env_key(ref)
os.putenv(env_key, dockerfile_contents)
base_cmd = cmd
cmd = 'echo "${{{env_key}}}" | {cmd}'.format(
env_key=env_key,
cmd=base_cmd,
)
kwargs['command_bat'] = '(cmd /v:on /c echo !{env_key}!) | {cmd}'.format(
env_key=env_key,
cmd=base_cmd
)
custom_build(
ref=ref,
command=cmd,
deps=[context],
disable_push=True,
skips_local_docker=True,
live_update=live_update,
match_in_env_vars=match_in_env_vars,
ignore=ignore,
entrypoint=entrypoint,
**kwargs
)