tilt icon indicating copy to clipboard operation
tilt copied to clipboard

Tilt is ignoring Dockerfile, entrypoint.sh and other files when using docker_compose

Open klutzer opened this issue 2 years ago • 6 comments

Expected Behavior

When executing docker_compose command, some important files (which are supposed to be watched) are in fact ignored. This happens when we have a docker-compose.yml file with some container using a build parameter with a custom Dockerfile. For those cases, no rebuild is triggered when changing the Dockerfile.

Current Behavior

We can identify the problem using the Tiltfile of this repository: https://github.com/mathulbrich/cqrs-app. After running tilt up we have the following: image

Even with the watchedPaths, we have the precedence of ignored ones (basePaths). I've tried to force the regex !docker on .dockerignore or .tiltignore (https://docs.tilt.dev/file_changes.html) but it doesn't work as well.

Steps to Reproduce

  1. Clone the repository https://github.com/mathulbrich/cqrs-app
  2. tilt up
  3. Change docker/Dockerfile or docker/entrypoint.sh file
  4. No rebuild is triggered

Context

tilt doctor Output

➜  dev-env git:(master) tilt doctor                                           
Tilt: v0.32.0, built 2023-03-13
System: linux-amd64
---
Docker
- Host: unix:///var/run/docker.sock
- Server Version: 23.0.3
- API Version: 1.42
- Builder: 2
- Compose Version: v2.17.2
---
Kubernetes
- Env: 
- Context: 
- Cluster Name: Unknown
- Namespace: default
- Container Runtime: unknown
- Version: Error: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
- Cluster Local Registry: none
---
Thanks for seeing the Tilt Doctor!
Please send the info above when filing bug reports. 💗

About Your Use Case

The example below is a simple one, but when we have some docker-compose.yml with a bunch of different services, each one with its own Dockerfile, we have to trigger the build manually for each changed service (Dockerfile, entrypoint.sh or any other file used by the image)

klutzer avatar Apr 12 '23 20:04 klutzer

thanks for the report!

So I understand the problem. But I'm not sure how we should fix it or what the correct behavior should be.

When you mount a local directory in a container, Tilt assumes that you don't want changes to that directory to trigger Tilt's reload logic. After all, the container can watch the mounted dir, and can reload itself. This is usually the right behavior for, .e.g, NodeJS and flask apps that reload their source.

In your case, https://github.com/mathulbrich/cqrs-app/blob/d73d8ebdbf663206c34669e9e7220641240e3135/docker/docker-compose.yml#L22, you're mounting the whole repo in the container. So Tilt assumes your inner scripts will handle the reloads.

There are probably ways to workaround this. e.g., add a local_resource('tilt trigger [name', deps=['./exactly/the/deps/you/want']) to the tiltfile. Otherwise I'm not sure how Tilt would distinguish in this case which files should trigger its reload vs which ones the container should reload itself.

[edited because i misread the dockerfile]

nicks avatar Apr 13 '23 12:04 nicks

Thanks for the reply @nicks .

The problem isn't related to the source directory, for those cases you're right and each developer should handle the auto-reload for their apps, as using nodemon, tsc --watch modes and so on (I'm in fact using nest start --watch as well). The problem here is related to docker-compose files, regardless the application language/platform: If I change the docker-compose.yml file, for instance, the rebuild is triggered (this is correct), but it's not the case if I change the Dockerfile or entrypoint.sh, used inside it.

klutzer avatar Apr 13 '23 12:04 klutzer

yep, that's what i'd expect, because you're mounting those files into the container itself under volumes

nicks avatar Apr 13 '23 12:04 nicks

I'm just mounting the whole directory because we're using the container to make it easier developers work without even the need of installing anything because all code operations could be executed inside container.

In fact, you're sure, we don't need to mount the docker files. But still, even if I change to exclude docker folder from the mounting, the Dockerfile is still ignored by default on the tilt filewatch.

klutzer avatar Apr 13 '23 13:04 klutzer

I think Tilt is doing the right thing, except for the Dockerfile, which should identify changes and trigger a rebuild, instead of explicitly ignoring it on tilt get filewatches (even changing the volumes).

klutzer avatar Apr 17 '23 19:04 klutzer

Having something similar..

Tiltfile has:

docker_compose('./graphql-schema-registry/docker-compose.dev2.yml',project_name="gratheon")

docker-compose has:

  gql-schema-registry:
    build:
      dockerfile: dev.Dockerfile

tilt up produces:

STEP 1/1 — Building & deploying
#1 [internal] load build definition from dev.Dockerfile
#1 transferring dockerfile:
#1 transferring dockerfile: 2B 0.3s done
#1 DONE 0.3s

#2 [internal] load .dockerignore
#2 transferring context: 2B 0.3s done
#2 DONE 0.3s
failed to solve: failed to read dockerfile: open /tmp/buildkit-mount1084375370/dev.Dockerfile: no such file or directory

Changing dockerfile path to absolute,ex. /Users/artjom/git/graphql-schema-registry/dev.Dockerfile helps. But I would expect tilt to handle relative paths from docker-compose to Dockerfile

tot-ra avatar Aug 16 '23 10:08 tot-ra