diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e09fe3d --- /dev/null +++ b/Dockerfile @@ -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" ] diff --git a/docker-healthcheck-cron b/docker-healthcheck-cron new file mode 100644 index 0000000..411db15 --- /dev/null +++ b/docker-healthcheck-cron @@ -0,0 +1 @@ +*/5 * * * * /app/docker-healthcheck.py /config/checks.yaml >> /var/log/docker-healthcheck.log 2>&1 diff --git a/docker-healthcheck.py b/docker-healthcheck.py index 1e9dc35..d421503 100644 --- a/docker-healthcheck.py +++ b/docker-healthcheck.py @@ -1,13 +1,17 @@ -# /usr/bin/env python3 +#! /usr/bin/env python3 import requests import yaml import docker import docker.errors +import sys 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) return checks diff --git a/requirements.txt b/requirements.txt index d24c50c..5fae204 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ requests PyYAML -docker \ No newline at end of file +docker