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

Enhance healthcheck blocking dependent behavior like lifecyle #10580

Open
loynoir opened this issue May 18, 2023 · 1 comment
Open

Enhance healthcheck blocking dependent behavior like lifecyle #10580

loynoir opened this issue May 18, 2023 · 1 comment

Comments

@loynoir
Copy link

loynoir commented May 18, 2023

Description

Problem

I found postgres image can't block dependent startup, which make dependent start up too early.

Actual

If dependent accept client at early time, dependent failed.

Expected

After postgres ready, dependent should not startup and accept client.

Try

I found .depends_on.X.condition works, but not very graceful to solve wait-for-container-x-before-starting-y.

  • If .interval big, run .healthcheck.test late, startdependent late, not very ideal.

  • If .interval small, run .healthcheck.test too many times, not very graceful.

Workaround

Below is my workaround.

  foo:
    ...
    depends_on:
      bar:
        condition: service_healthy
    ...
 
  bar:
    ...
    tmpfs:
      - /tmp
    healthcheck:
      test: 'if [ -e /tmp/first_run ]; then sleep 24h; else touch /tmp/first_run; bash /script/wait.sh; fi'
      timeout: 25h
      interval: 1s

Feat

Above workaround I still don't think very ideal, so I opened a feat.

Enhance healthcheck behavior like lifecyle.

  foo:
    ...
    depends_on:
      bar:
        condition: service_lifecycle_bootstrap
    ...
 
  bar:
    ...
    lifecycle:
        bootstrap: 'bash /script/wait.sh'

Related

Additional

Are there lifecyle support within container ecosystem?

Yes, vscode devcontainer support lifecycle.

https://github.com/devcontainers/spec/blob/main/schemas/devContainerFeature.schema.json#L106-L206

  • initializeCommand
  • onCreateCommand
  • updateContentCommand
  • postCreateCommand
  • postStartCommand
  • postAttachCommand
@loynoir loynoir changed the title Enhance healthcheck behavior like lifecyle Enhance healthcheck blocking dependent behavior like lifecyle May 18, 2023
@ndeloof
Copy link
Contributor

ndeloof commented May 22, 2023

the devcontainer feature you're listing here is about command hooks to run during container lifecycle, not about dependency management.

IIUC your needs, you have to wait for postgres to be running and accept connexion before your client code get started, otherwise connexion fails. This is exactly what condition: service_healthy is designed for: client container won't get started before their dependency is reported as "healthy" by the container runtime, which is easy to setup as postgres ilmage includes utility tool pg_isready.

healthcheck interval and health status unfortunately is managed by container runtime, not docker compose, so we can't tweak the interval to avoid unnecessary runs once service is started
AFAICT you're looking for readyness check which isn't supported by docker engine (see moby/moby#30860) - maybe we should introduce this feature directly in Docker Compose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants