9

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

Nick
  • 2,745
  • 1
  • 27
  • 53
  • Tried to implement a Health check service as mentioned [here](https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/monitor-app-health), but with no luck – RX100 Nov 13 '20 at 05:07

1 Answers1

0

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.

Tomerikoo
  • 12,112
  • 9
  • 27
  • 37
Yan Sklyarenko
  • 29,347
  • 24
  • 104
  • 125