diff --git a/README.md b/README.md index 51f7352..203cfbe 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,15 @@ Run this version with: docker-compose -f docker-compose.cuda.yml up -d --build ``` +### Running Healthchecks + +You can enable healthchecks by including this in your docker-compose.yml file: + +``` +healthcheck: + test: ['CMD-SHELL', './venv/bin/python healthcheck.py'] +``` + ## Arguments | Argument | Description | Default | Env. name | diff --git a/docker-compose.yml b/docker-compose.yml index 63bd509..a634356 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,8 @@ services: restart: unless-stopped ports: - "5000:5000" + healthcheck: + test: ['CMD-SHELL', './venv/bin/python healthcheck.py'] ## Uncomment above command and define your args if necessary # command: --ssl --ga-id MY-GA-ID --req-limit 100 --char-limit 500 ## Uncomment this section and the `volumes` section if you want to backup your API keys diff --git a/healthcheck.py b/healthcheck.py new file mode 100644 index 0000000..cd62b4f --- /dev/null +++ b/healthcheck.py @@ -0,0 +1,11 @@ +import requests +response = requests.post( + url='http://0.0.0.0:5000/translate', + headers={'Content-Type': 'application/json'}, + json={ + 'q': 'Hello World!', + 'source': 'en', + 'target': 'en' + } +) +# if server unavailable then requests with raise exception and healthcheck will fail