tilt
tilt copied to clipboard
[docker-compose] Restart containers if a file/folder that is part of volumes has changed
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/
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.
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.
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')
.
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:
- Auto-converting volume mounts to live-updates
- 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)
- Auto-converting volume mounts to live-updates
would be fantastic!
- 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.
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™)?
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.
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?
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.
any news on this?
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)
Still missing this feature