add healthcheck

This commit is contained in:
Michael Grote 2023-04-14 12:17:08 +02:00
parent 2caf356288
commit b91cf9fc50
3 changed files with 21 additions and 1 deletions

View File

@ -6,7 +6,7 @@ ENV DEBIAN_FRONTEND=noninteractive
# hadolint ignore=DL3008,DL3028,DL4006
RUN apt-get update && \
apt-get -y --no-install-recommends install \
python3-pip && \
python3-pip curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /var/tmp/* /tmp/*
@ -20,6 +20,8 @@ RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 5000
HEALTHCHECK --interval=5s --timeout=3s \
CMD curl -f http://localhost:5000/health || exit 1
#CMD [ "python3", "-m" , "flask", "run", "--port", "5000", "--host", "0.0.0.0"]
CMD [ "python3", "-m" , "gunicorn", "app:app", "-c", "gunicorn_config.py"]

View File

@ -88,3 +88,17 @@ curl -X DELETE -H "token: myuploadtoken" http://docker10.host.lan:5040/delete/fi
"success": "File 'file' successfully deleted"
}
```
### /health
#### input
```bash
curl -H "token: myuploadtoken" http://docker10.host.lan:5040/health
```
#### output
```bash
OK
```

4
app.py
View File

@ -15,6 +15,10 @@ AUTH_TOKEN = os.environ.get('AUTH_TOKEN', 'myuploadtoken')
def is_valid_filename(filename):
return bool(re.match(VALID_FILENAME_REGEX, filename))
@app.route('/health', methods=['GET'])
def health_check():
return 'OK'
@app.route('/upload', methods=['POST'])
def upload_file():
if 'file' not in request.files: