Skip to content
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

Respect depends_on conditions from docker-compose #2239

Open
fgallese opened this issue Sep 22, 2019 · 4 comments
Open

Respect depends_on conditions from docker-compose #2239

fgallese opened this issue Sep 22, 2019 · 4 comments
Labels
enhancement New feature or request

Comments

@fgallese
Copy link

For reference, this issue was raised in #2210.

When using a docker compose file with one or more depends_on including conditions service_healthy, tilt does not check those conditions.

depends_on is a condition added in v2, and in v2.1 a condition service_healthy was added to it.

Example configuration:

services:
  myServiceA:
    extends:
      file: docker-compose.base.yml
      service: myServiceA_base
    depends_on:
      mariadb:
        condition: **service_healthy**
      mongodb:
        condition: **service_healthy**
      myServiceB:
        condition: service_started
    command: ["npm", "run", "dev"]

  mariadb:
    image: mariadb:10.1.30
    healthcheck:
      test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
      timeout: 20s
      retries: 10

  mongodb:
    image: mongo:4.0
    healthcheck:
      test: echo 'db.runCommand("ping").ok' | mongo mongodb:27017/test --quiet
      interval: 10s
      timeout: 10s
      retries: 5

  myServiceB:
    extends:
      file: docker-compose.base.yml
      service: myServiceB_base
    depends_on:
      mariadb:
        condition: **service_healthy**
      mongodb:
        condition: **service_healthy**
    command: ["npm", "run", "dev"]

With this configuration, mariadb and mongodb should be started first, then myServiceB and at last myServiceA.

Tilt is not respecting this, as it is not checking the service_healthy conditions.

In docker compose v3 format, depends_on condition was removed altogether, but many companies are still using it, specially the ones that don't make use of Docker Swarm, so I think this should be supported by Tilt.

@nicks nicks added the enhancement New feature or request label Sep 23, 2019
@ShadowLNC
Copy link

Just to add - the Compose Spec (which supersedes previous v2 and v3 formats) not only supports this, but requires it for compliance with the spec. We have some database migrations which rely on this feature, and they outright fail (and are not restarted as they're only meant to run once) because Tilt isn't waiting for the database to be healthy 😞

@Aryess
Copy link

Aryess commented Nov 21, 2023

I encountered this today as well, and got a minimal sample to reproduce the issue.

With the following docker-compose.yml:

---
version: "3"

services:
  slow:
    image: debian:stable-slim
    command: bash -c "echo 'Hi from slow container' && sleep 5 && echo 'Ok slow is ready now'"

  fast:
    image: debian:stable-slim
    command: "echo 'Hi from fast, this should be last'"
    depends_on:
      slow:
        condition: service_completed_successfully

And a Tiltfile containing just docker_compose('docker-compose.yml'), when doing docker compose up we get as expected:

tilt-depends-on|⇒ docker compose up
[+] Running 3/2
 ✔ Network tilt-depends-on_default   Created                                                                                         0.1s 
 ✔ Container tilt-depends-on-slow-1  Created                                                                                         0.0s 
 ✔ Container tilt-depends-on-fast-1  Created                                                                                         0.0s 
Attaching to tilt-depends-on-fast-1, tilt-depends-on-slow-1
tilt-depends-on-slow-1  | Hi from slow container
tilt-depends-on-slow-1  | Ok slow is ready now
tilt-depends-on-slow-1 exited with code 0
tilt-depends-on-fast-1  | Hi from fast, this should be last
tilt-depends-on-fast-1 exited with code 0

But when doing tilt up, we get:

Loading Tiltfile at: /tmp/tilt-depends-on/Tiltfile
Successfully loaded Tiltfile (73.417794ms)
         slow │ 
         slow │ Initial Build
         slow │ STEP 1/1 — Deploying
         slow │  Container tilt-depends-on-slow-1  Created
         slow │  Container tilt-depends-on-slow-1  Starting
         slow │  Container tilt-depends-on-slow-1  Started
         fast │ 
         fast │ Initial Build
         fast │ STEP 1/1 — Deploying
         fast │  Container tilt-depends-on-fast-1  Recreate
         slow │ Hi from slow container
         slow │ 
         slow │      Step 1 - 0.58s (Deploying)
         slow │      DONE IN: 0.58s 
         slow │ 
         fast │  Container tilt-depends-on-fast-1  Recreated
         fast │  Container tilt-depends-on-fast-1  Starting
         fast │  Container tilt-depends-on-fast-1  Started
         fast │ Hi from fast, this should be last
         fast │ 
         fast │      Step 1 - 0.88s (Deploying)
         fast │      DONE IN: 0.88s 
         fast │ 
         slow │ Ok slow is ready now

and we can see that the depends_on was not respected.
Clearly, the current docker version (tested on docker 24.0.7 with compose 2.21.0) DOES support this. Looking at the documentation, it seems like "The depends_on option is ignored when deploying a stack in swarm mode". Is that what Tilt is doing? Would it be as simple as calling docker compose differently? I'm not sure, but that's all I could find on my end

@emersonfoni
Copy link

Just posting to try to keep this issue alive. We use Docker Compose and Tilt and have healthchecks, but resources fail to start because their dependencies aren't healthy yet, as "Tilt doesn’t currently observe docker-compose health checks". Engineers then have to repeatedly hit the reload button until the failed resources turns green.

Any chance this issue gets some love @nicks ?

kinland added a commit to kinland/tilt-dockerfix that referenced this issue Mar 5, 2024
…se (tilt-dev#2239)

Signed-off-by: Kinland <16787581+kinland@users.noreply.github.com>
@kinland
Copy link
Contributor

kinland commented Mar 5, 2024

I took a stab at this and opened a PR - it's probably not the solution that the maintainers would want, but as far as I can tell (well, at the level of energy for testing I have at 3am anyway), it solves this problem without side effects.

kinland added a commit to kinland/tilt-dockerfix that referenced this issue Mar 5, 2024
…se (tilt-dev#2239)

Signed-off-by: Kinland <16787581+kinland@users.noreply.github.com>
kinland added a commit to kinland/tilt-dockerfix that referenced this issue Mar 13, 2024
Signed-off-by: Kinland <16787581+kinland@users.noreply.github.com>
nicks pushed a commit that referenced this issue Mar 13, 2024
…se (#2239) (#6329)

* dockercompose: add wait_for_healthy optional argument to docker_compose (#2239)

Signed-off-by: Kinland <16787581+kinland@users.noreply.github.com>

* dockercompose: fix codegen / protobuf from previous commit

Signed-off-by: Kinland <16787581+kinland@users.noreply.github.com>

* rename wait_for_healthy to wait (#2239)

Signed-off-by: Kinland <16787581+kinland@users.noreply.github.com>

---------

Signed-off-by: Kinland <16787581+kinland@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants