-
Notifications
You must be signed in to change notification settings - Fork 165
/
Tiltfile
60 lines (52 loc) · 1.61 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
# -*- mode: Python -*-
def pack(
name,
path=".",
builder="gcr.io/paketo-buildpacks/builder:base",
buildpacks=[],
env_vars=[],
pull_policy="if-not-present",
deps=[],
**kwargs
):
"""
Build a container image using pack and buildpacks.
Args:
name: name of the image to build.
path: path to application directory, defaults to current working directory.
builder: builder image, defaults to gcr.io/paketo-buildpacks/builder:base
buildpacks: A list of buildpacks to use. (list[str])
env_vars: A list of environment variables. (list[str])
**kwargs: will be passed to the underlying `custom_build` call
"""
# Remove possible tag from image name
name = name.split(":")[0]
envs = list(env_vars)
if not bool([e for e in envs if ('BP_LIVE_RELOAD_ENABLED' in e)]):
envs.append('BP_LIVE_RELOAD_ENABLED=true')
deps_copy = list(deps)
if len(deps_copy) == 0:
deps_copy = [path]
caching_ref = name + ":tilt-build-pack-caching"
pack_build_cmd = " ".join([
"pack build",
caching_ref,
"--path " + path,
"--builder " + builder,
"--pull-policy " + pull_policy,
" ".join(["--buildpack " + s for s in buildpacks]),
" ".join(["--env " + s for s in envs]),
])
isWindows = True if os.name == "nt" else False
expected_ref = "%EXPECTED_REF%" if isWindows else "$EXPECTED_REF"
docker_tag_cmd = " ".join([
"docker tag",
caching_ref,
expected_ref,
])
custom_build(
name,
pack_build_cmd + " && " + docker_tag_cmd,
deps=deps_copy,
**kwargs
)