added docker support

This commit is contained in:
Lu Baumann 2024-01-02 12:13:21 +01:00
parent d76a295bb3
commit 120e9f9c5b
4 changed files with 29 additions and 3 deletions

21
Dockerfile Normal file
View File

@ -0,0 +1,21 @@
FROM docker:cli
ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 py3-pip && ln -sf python3 /usr/bin/python
COPY requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt --break-system-packages --no-cache-dir
COPY docker-healthcheck.py /app/docker-healthcheck.py
RUN chmod +x /app/docker-healthcheck.py
RUN apk add --no-cache cronie
COPY docker-healthcheck-cron /etc/cron.d/docker-healthcheck-cron
RUN chmod 0644 /etc/cron.d/docker-healthcheck-cron
RUN mkdir -p /root/.cache
RUN crontab /etc/cron.d/docker-healthcheck-cron
RUN touch /var/log/docker-healthcheck.log
ENTRYPOINT [ "sh", "-c", "crond & tail -f /var/log/docker-healthcheck.log" ]

1
docker-healthcheck-cron Normal file
View File

@ -0,0 +1 @@
*/5 * * * * /app/docker-healthcheck.py /config/checks.yaml >> /var/log/docker-healthcheck.log 2>&1

View File

@ -1,13 +1,17 @@
# /usr/bin/env python3 #! /usr/bin/env python3
import requests import requests
import yaml import yaml
import docker import docker
import docker.errors import docker.errors
import sys
def read_checks() -> dict: def read_checks() -> dict:
with open("./checks.yaml") as f: if len(sys.argv) < 2:
print("You need to specify a config by path")
sys.exit(1)
with open(sys.argv[1]) as f:
checks = yaml.safe_load(f) checks = yaml.safe_load(f)
return checks return checks

View File

@ -1,3 +1,3 @@
requests requests
PyYAML PyYAML
docker docker