-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore files to watch but keep them in docker context #6501
Comments
You'd usually use tiltignore for this, see - https://docs.tilt.dev/file_changes |
Could we re-open the issue? The options described in the link shared don't seem to apply to the problem I've described above:
Essentially, I want to tell Tilt to ignore certain files from being watched when building a specific service, I can't specify this globally, since each service will need to ignore its own set of files. How do I accomplish that, what am I missing? |
ya, by design we don't support the use-case of "this file is critical to the build, but i don't want changes to it to trigger rebuilds" -- this would introduce drift. |
I'm not sure I understand that rationale, maybe I'm missing something?
With that said, after spending several days trying to find a solution, I think I've finally found the right incantations to get this behavior so I'll drop it here for other poor souls who might end up dealing with the same issue: def build_image(ref, context, dockerfile, target=None, extra_watch=[], extra_ignore=[], live_update=[]):
command = ['docker', 'build']
command += ['-f', dockerfile]
command += ['-t', '$EXPECTED_REF']
if target:
command += ['--target', target]
command += [shlex.quote(context)]
command = ' '.join(command)
# Unlike with `docker_build()` the Dockerfiles aren't watched by default and don't
# seem to trigger a rebuild when updated, this fixes it
watch_patterns = [dockerfile, dockerfile + '.dockerignore'] + extra_watch
negate_ignores = []
for watch in watch_patterns:
negate_ignores.append('!' + watch)
ignore = dockerignore_patterns(dockerfile) + negate_ignores + extra_ignore
custom_build(
ref,
command=command,
deps=[context],
ignore=ignore,
live_update=live_update,
)
def dockerignore_patterns(dockerfile):
"""
Given the path to a Dockerfile, a list of the ignore
glob patterns (i.e., non-empty, non-comment lines) found in the
corresponding .dockerignore file will be returned.
### For example:
Given: `dockerfile=config/docker/App1.Dockerfile` all
glob patterns found in: `config/docker/App1.Dockerfile.dockerignore`
will be returned.
Args:
dockerfile: A string path to the Dockerfile.
Returns:
A list of strings representing the ignore patterns.
"""
content = str(read_file(dockerfile + '.dockerignore'))
patterns = []
for line in content.split('\n'):
line = line.strip()
# Skip comments (#...) and empty lines.
if not line or line.startswith('#'):
continue
patterns.append(line)
return patterns
build_image(
"app1",
context=".",
dockerfile="config/docker/App1.Dockerfile",
target="dev",
extra_ignore=["apps", "!apps/app1"],
live_update=[
sync('apps/app1', '/app/apps/app1'),
sync('libs', '/app/libs'),
]
)
build_image(
"app2",
context=".",
dockerfile="config/docker/App2.Dockerfile",
target="dev",
extra_ignore=["apps", "!apps/app2"],
live_update=[
sync('apps/app2', '/app/apps/app2'),
sync('libs', '/app/libs'),
]
)
... other apps This feels fragile and really hacky for what I'd consider should be a default available behavior in A bit of explanation on what this does: After reading the documentation more times than I can count now and trying different things, I confirmed that I really couldn't use neither the
So I initially assumed I couldn't use it, but after being desperate enough I tried it anyways and it turns out the documentation seems incorrect! Lastly, the weird
So when passing: All in all, either this is the intended behavior by Tilt for Would Tilt re-consider its stance on not wanting to provide this option for An option in Many thanks for working on this tool, Tilt is awesome and it definitely was worth taking the time to switch from Skaffold! |
How can I specify to a
docker_build
command to not rebuild the image when certain files are changed? We have a Cargo workspace which requires all workspace members to be present in the filesystem in order to build any member. Meaning that we need to include all apps/services within the docker context of each app being built.Given an example workspace such as:
In order to build
app1
, we specify the root directory.
as the context, same forapp2
,app3
, etc.Next, we need to instruct Tilt on how to build
app1
:We now need a way to tell this
docker_build
to not rebuild the image whenapp2
,app3
, etc, are changed because changes to their source files do not affect the build of this app.Tried the
only
option (only=["apps/app1"]
) but it seems to delete all other files from my docker context (why?)This effectively causes all apps to be rebuilt whenever any app is changed, nullifying the benefits of
live_update
I'm new to Tilt so I might have missed it but what is the best way to accomplish this?
The text was updated successfully, but these errors were encountered: