tilt icon indicating copy to clipboard operation
tilt copied to clipboard

[docker-compose] Restart containers if a file/folder that is part of volumes has changed

Open fkaleo opened this issue 5 years ago • 12 comments

When using a docker-compose.yml that defines a container with volumes, it would be really great if the container was automatically restarted if a file/folder used as source in the volumes section of that container changed. For example if mycool_file_or_folder changes in the following example docker-compose.yml, the container should be restarted:

version: '2'

services:
  mycontainer:
    image: myimage
    volumes:
      - mycool_file_or_folder:/usr/bin/

fkaleo avatar May 16 '19 15:05 fkaleo

Have you considered using live_update to sync mycool_file_or_folder into the container?

A lot of the reason we built live_update is because local volume mounts have lots of problems -- lack of flexibility, bugginess, and performance overhead. We've been trying to convince the community to move away from them and towards sync-based solutions, rather than trying to build new features on a kind of shaky foundation.

nicks avatar May 16 '19 16:05 nicks

I have not tried to use live_update in this case yet. I'm sure it would work. But in this specific case I don't even want to do any docker_build, only a docker_compose if possible.

In any event it feels like the feature would be valid in its own right.

fkaleo avatar May 16 '19 17:05 fkaleo

While trying to convince a team to move from docker-compose to Tilt I would argue that it should work out of the box as much as possible. I would go as far as saying that if Tilt could detect the presence of a docker-compose.yml file in the current folder, it should behave as if there was a Tiltfile when there isn't one: a Tiltfile with a single line in it docker_compose('docker-compose.yml').

fkaleo avatar May 16 '19 17:05 fkaleo

oh, yes, I agree that this is a valid feature request!

I wanted to make sure I understood the problem. If there was a reason live_update wouldn't work in this case, that'd be good to know.

A couple features we've talked about that kind of get at this:

  1. Auto-converting volume mounts to live-updates
  2. Add the ability to set up your own file system watches in the Tiltfile and execute local commands / container restarts when something changes (i.e., something a bit more flexible than live update)

nicks avatar May 16 '19 17:05 nicks

  1. Auto-converting volume mounts to live-updates

would be fantastic!

  1. too but another ticket I guess :)

And yeah so the reason live_update doesn't apply here is the lack of docker_build in my Tiltfile.

fkaleo avatar May 16 '19 17:05 fkaleo

Can I ask why there's no docker_build in your Tiltfile? Is there a reason it wouldn't work to have Tilt take care of your image building for you, or just b/c of out-of-the-box-ness (i.e. docker compose can take care of the building, and is already set up to do that, so you shouldn't have to tell Tilt about how to do the builds, it should Just Work™)?

maiamcc avatar May 16 '19 22:05 maiamcc

There is no docker_build in my Tiltfile for 'out-of-the-box-ness' indeed.

It would work to have Tilt take care of the image building. Although in this very particular setup the docker-compose.yml itself does not itself have a build directive either, it simply pulls pre-existing images. But that specificity can be safely ignored I guess.

fkaleo avatar May 17 '19 09:05 fkaleo

Hi @fkaleo, following up from your recent PR to put Tiltfiles in Metrictank (thank you!!) -- I'll talk to the team about this feature and how much work it would take/how to prioritize it. I agree that our Docker Compose support OUGHT to behave this way; but how hard would it be for you to configure Tilt to take care of your image building in order to use live_update syncs to solve your problem? I suspect it'll be 15 minutes of config file changes, and that might very well be faster than us fixing this issue on our end (plus you get the benefit of Tilt's efficient image building!). What do you think?

maiamcc avatar Jun 18 '19 20:06 maiamcc

Hi @fkaleo, following up from your recent PR to put Tiltfiles in Metrictank (thank you!!) -- I'll talk to the team about this feature and how much work it would take/how to prioritize it. I agree that our Docker Compose support OUGHT to behave this way; but how hard would it be for you to configure Tilt to take care of your image building in order to use live_update syncs to solve your problem? I suspect it'll be 15 minutes of config file changes, and that might very well be faster than us fixing this issue on our end (plus you get the benefit of Tilt's efficient image building!). What do you think?

Yeah I can and I did experimentally (see https://github.com/grafana/metrictank/blob/7fe8765526f03e0801a2301115217dff66092979/docker/docker-dev-custom-cfg-kafka/Tiltfile). However it changes the workflow the team is used to that involves no image building.

fkaleo avatar Jun 19 '19 08:06 fkaleo

any news on this?

Dieterbe avatar Nov 16 '19 17:11 Dieterbe

You should be able to wire this up right now with a local_resource that looks something like this:

local_resource('restart-metrictank', cmd='./restart-metricktank.sh',
   deps = ['./path/to/dir'],
   auto_init=False
)

for more info, see, https://docs.tilt.dev/local_resource.html. Try that and let us know if it works?

It's definitely not super-intuitive right now, and we need to figure out better ways for people to abstract out + share this kind of logic.

This workflow will require some kind of configuration (since not everyone wants their containers restarted when files changed, e.g., js developers)

nicks avatar Dec 02 '19 16:12 nicks

Still missing this feature

askolesov avatar Feb 16 '24 13:02 askolesov