-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
introduce up --wait condition #8777
Conversation
Wondering why this should not be the default for |
we hardly can change the existing behavior |
So, it currently already waits for things to be created, and started. Are there any cases where the Looking at available options; what does |
"service_started" indeed is the default condition.
First, service might not define a healthcheck. Other than that, this is just how things used to be, aka "Legacy" |
Do we need any unit tests, integration tests, E2E tests? |
For that case, we should consider "running" to be the equivalent of "healthcheck==ok". Healthcheck during startup is just a more customized "readiness" check. If there's no customized one, then "container running" means it's ready. Curious; what's the current behavior in this PR if I would pass a |
I don't think we should assume healthy == running, better detect container has no healthcheck configuration (by ContainerInspect.Config.Healthcheck) and report an error |
we actually already return error when service/docker image doesn't define a |
8f0605c
to
e1e2d06
Compare
@ulyssessouza any thoughts? |
The point is that the general design for healthchecks was to (during startup) be a readiness check; in that design "no healthcheck" implicitly means "no readiness checck, so
So, what are the other options?
I'm personally still in favor of making this part of the standard behavior; we'e already printing the steps taken to bring up the stack, so it would be one more output to that list
The UX would be more logical for |
There's indeed no distinction in docker between "ready" and "healthy", but I think we can assume actual usages based on this. Better reject a --wait when no healthcheck is set than pretending to be clever.
Then this flag is not needed.
this is what's implemented here
yep. Basically, init container.
This is all about backward compatibilty, can't just change the behavior for a command used by thousands (millions?) because is looks niceer |
4bc573f
to
5df5f77
Compare
I'm not sure what you mean with this "assume actual usages"
For both cases, the
I think we're waaaay past "backward compatiblity" when we did #8655. We could still use the
It's not "looking nicer"; I think the current behavior could be considered a bug; the expectation of a |
#8655 changes container names, but doesn't prevent most users to |
seems we hardly can find a consensus here. Here is my last proposal, reducing the scope: |
implemented the proposed "simpler" --wait boolean flag. Please reconsider |
09976f7
to
61d63cd
Compare
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Looks like I missed your comment. Yes, I think that's a good middle-ground for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
dep, config := dep, config | ||
eg.Go(func() error { | ||
ticker := time.NewTicker(500 * time.Millisecond) | ||
defer ticker.Stop() | ||
for { | ||
<-ticker.C | ||
switch config.Condition { | ||
case ServiceConditionRuningOrHealthy: | ||
healthy, err := s.isServiceHealthy(ctx, project, dep, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(just thinking out loud); perhaps we need to have a look at the events API, and see if we can improve it enough so that compose can (more easily) use that. We already have a health_status
event, but perhaps that alone is not sufficient, but we could look at enhancing it. (that way compose wouldn't have to poll docker inspect
calls)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would ne a nice addition to the event stream indeed
Sorry, but is there any timeout for waiting? I've set my health check to "exit 1" with 5 retries every 1 second, but docker compose up -d --wait waits for several minutes already and seems like it will go forever. I've thought it should fail if any of services is unhealthy, isn't it? |
The previous code would wait for dependencies to become healthy forever, even if they'd become unhealthy in the meantime. I can't find an issue report for this bug, but it was described in a comment on the PR that introduced the `--wait` flag [0]. [0]: docker#8777 (comment)
The previous code would wait for dependencies to become healthy forever, even if they'd become unhealthy in the meantime. I can't find an issue report for this bug, but it was described in a comment on the PR that introduced the `--wait` flag [0]. [0]: docker#8777 (comment) Signed-off-by: Nikhil Benesch <nikhil.benesch@gmail.com>
The previous code would wait for dependencies to become healthy forever, even if they'd become unhealthy in the meantime. I can't find an issue report for this bug, but it was described in a comment on the PR that introduced the `--wait` flag [0]. [0]: #8777 (comment) Signed-off-by: Nikhil Benesch <nikhil.benesch@gmail.com>
The previous code would wait for dependencies to become healthy forever, even if they'd become unhealthy in the meantime. I can't find an issue report for this bug, but it was described in a comment on the PR that introduced the `--wait` flag [0]. [0]: #8777 (comment) Signed-off-by: Nikhil Benesch <nikhil.benesch@gmail.com>
…r.yml. Checks - Add Django checks - Add PYTHONWARNINGS check - Remove diff-cover check Move build step to Docker workflow - Remove permissions section - Remove CI=True POSTGRES_HOST=127.0.0.1 DOMAIN_URL=http://127.0.0.1/api environment variables - Use --wait instead of sleep 60 docker/compose#8777 - Use default values for API_PREFIX, POSTGRES_DB, POSTGRES_USER, JOB_FILES_TIMEOUT - Move if-statement for SKIP_TEST Refactor test workflow - Move Transifex upload to new job - Remove coverage thresholds (defer to coveralls) - Remove CI=True DEBUG=True environment variables - Remove fetch-depth: 0 - Use default values for API_PREFIX, POSTGRES_DB, POSTGRES_USER - Change service ports - Change PostgreSQL credentials Remove pytest configuration from setup.cfg - Add --cov spoonbill_web - Allow auto-discovery of DJANGO_SETTINGS_MODULE - Use default for python_files (test_*.py) and testpaths (all) - Remove norecursedirs = .git Other changes - Delete .envrc - Remove ALLOWED_HOSTS from docker-compose.test.yaml - Change settings defaults to require fewer overrides: - API_PREFIX - CELERY_BACKEND - CELERY_BROKER - DB_HOST - POSTGRES_DB - POSTGRES_PASSWORD - POSTGRES_USER
The previous code would wait for dependencies to become healthy forever, even if they'd become unhealthy in the meantime. I can't find an issue report for this bug, but it was described in a comment on the PR that introduced the `--wait` flag [0]. [0]: docker#8777 (comment) Signed-off-by: Nikhil Benesch <nikhil.benesch@gmail.com>
How long does this wait? |
@noorul wait until dependent service reports a healthy state, as configured by HEALTHCHECK |
@ndeloof I think a timeout option will add value here instead of waiting forever. |
This enables starting lms services and the dev server by running `make services && make dev`, without encountering errors due to the DB not being ready. nb. The `--wait` flag is missing from the docs but see docker/compose#8777.
This enables starting apps with `make services dev` without potentially running into errors from the app due to services not being ready when the web server tries to connect. Services must define a healthcheck [1] in `docker-compose.yml` for this to work. The `--wait` flag is missing from the Docker Compose docs, but see docker/compose#8777. [1] https://docs.docker.com/compose/compose-file/05-services/#healthcheck
This enables starting apps with `make services dev` without potentially running into errors from the app due to services not being ready when the web server tries to connect. Services must define a healthcheck [1] in `docker-compose.yml` for this to work. The `--wait` flag is missing from the Docker Compose docs, but see docker/compose#8777. [1] https://docs.docker.com/compose/compose-file/05-services/#healthcheck
@ndeloof Thanks for the useful feature Do you have a proposal how to avoid the issue with init containers that exit with services:
db:
image: mysql:8.0
init-db:
image: mysql:8.0
command: ./init-db.sh
environment:
<<: *cenv
volumes:
- ./init-db.sh:./init-db.sh
depends_on:
db:
condition: service_started docker compose up -d --wait |
What I did
introduced
compose up --wait
to run detached BUT wait for services to reach staterunning
orhealthy
(for those with a Healthcheck defined).Typical usage is to have some backend services (let's say postgres database) ran by compose, and user need to wait for service to be actually up so he can apply database migrations and start an happy coding day.
Related issue
#8351
(not mandatory) A picture of a cute animal, if possible in relation with what you did