Skip to content

Enhance healthcheck blocking dependent behavior like lifecyle #10580

@loynoir

Description

@loynoir

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions