Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform Health check in a docker console app

I have a .net 2.2 core console app that is running permanently as a HostedService in a docker container. It is not using ASPNet.Core and it's not an API, it's a pure .net-core application.

When started, it performs a number of healthchecks and when starts running.

I'm trying to write a cake build script and to deploy in docker, and run some mocha integration tests. However, the integration step doesn't wait for the console app to complete its health checks and the integration fails.

All the health check guides I read are for an API. I don't have an API and there are no endpoints. How can I make docker wait for the console app to be ready?

Thanks in advance

like image 766
Nick Avatar asked Apr 18 '19 09:04

Nick


1 Answers

You can use the docker-compose tool and, in particular, its healthcheck option to wait for a container to spin up and do its setup work before proceeding with the integration tests.

You can add a healthcheck block to your app service definition:

myapp:
  image: ...
  healthcheck:
    test:
      ["CMD", "somescript.sh", "--someswitch", "someparam"]
    interval: 30s
    timeout: 10s
    retries: 4

The command you specify in the test property should verify whether the setup work of the app is completely done. It can be some custom script that is added to myapp container just for the sake of its health check.

Now, you can add some fake service - just to check the app service is healthy. Depending on your particular case, this responsibility can be handed to the container with integration tests. Anyway, this other service should have a depends_on block and mention the app service in it:

wait-for-app-setup:
  image: ...
  depends_on:
    myapp:
      condition: service_healthy

As a result, docker-compose will take care of the correct order and proper wait periods for the stuff to start and set up correctly.

like image 95
Yan Sklyarenko Avatar answered Sep 20 '22 18:09

Yan Sklyarenko