tilt-dev / tilt

Define your dev environment as code. For microservice apps on Kubernetes.
https://tilt.dev/
Apache License 2.0
7.58k stars 298 forks source link

Add possibility to select services in docker_compose() #6423

Open GiorgioBullo opened 1 month ago

GiorgioBullo commented 1 month ago

Describe the Feature You Want

When using the function docker_compose() it would be good to select which services to deploy

Current Behavior

doker_compose('docker-compose.yml') deploys all the services defined in the docker-compose.yaml file and there is no easy way to select which service to deploy. However, if I am using only docker-compose, without Tilt, assuming the docker-compose.yml contains 3 services (svcs1, svcs2, svc3), I can easily select which one to spin up using docker-compose up svcs2 svcs3.

Why Do You Want This?

The docker-compose file may contain some services that are not needed in Tilt, moreover it feels like Tilt should expose this docker-compose feature.

Sometimes docker-compose and Tilt are used together even though they overlap a bit on their scope. That's why in the docker-compose file you may have services that you may not want in Tilt.

nicks commented 1 month ago

i just tried this and it worked like i expected?

  1. Checkout https://github.com/tilt-dev/tilt-example-docker-compose
  2. Run tilt up redis
  3. Observe: redis starts, app does not

What am i missing?

Here are the docs: https://docs.tilt.dev/disable_resources

GiorgioBullo commented 1 month ago

Following my previous example, I was thinking about something like the following, in the Tiltfile:

docker_compose('./docker-compose.yml', services=['svcs2','svcs3'])

yamlDeploy = helm(
  './path/to/svcs1-helm-chart',
  name='svcs1',
  values=['./path/to/svcs1-helm-values.yaml']
)

k8s_yaml(yamlDeploy)

So, when I run tilt up, svcs1 and svcs3 are deployed from docker-compose and svcs1 is ignored, but then installed using helm chart by Tilt. Without specifying the services=['svcs2','svcs3'] in the docker_compose() command, I would get an error because svcs1 is defined 2 times.

I understand that this could be solved by removing svcs1 from the docker-compose.yml, however I would prefer not to and I was wondering why docker_compose() doesn't provide that option.

Let me know if I got something wrong.

nicks commented 1 month ago

i think you can do this with something like:

dc_resource('app', new_name='unused')
k8s_yaml('app.yaml')
config.set_enabled_resources(['redis', 'app'])
GiorgioBullo commented 1 month ago

it doesn't look like a feasible solution, because to disable a couple of resources I need to rename them (which could be fine), but then I need to enable everything else, that, in some cases I am working on, it could go up to 15 resources or more, that are not coming from the docker-compose file. It is true that the same holds for docker-compose up svcs2 svcs3 svcs4 svc5 ... if I want to disable only svcs1, however for tilt it is even worse, because I don't only have resources coming from docker-compose, but many comes from helm yaml manifests. Moreover, the approach you mention still shows the resources in the UI.

I wonder whether it exists a config.set_disabled_resources(), in this way I could "surgically" disable the few resources I don't need.

nicks commented 1 month ago

i guess you could also use docker-compose overrides to accomplish this:

Tiltfile:

docker_compose([
    'docker-compose.yaml',
    'docker-compose.override.yaml',
    ])

docker-compose.override.yaml

services:
  app: !reset null
GiorgioBullo commented 1 month ago

Good, I guess the solutions you provided will satisfy most of the people out there 💪. I'll leave it to you whether you want to close this or not.