From b4d92128df9a0a19124b2da946b6550424ebe2e0 Mon Sep 17 00:00:00 2001 From: jblu Date: Mon, 19 Jun 2023 18:46:37 -0500 Subject: [PATCH 1/4] added supercronic --- Dockerfile | 1 + crontab | 1 - entrypoint.sh | 9 +++++++-- 3 files changed, 8 insertions(+), 3 deletions(-) delete mode 100644 crontab diff --git a/Dockerfile b/Dockerfile index 1464315..a43a41d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM python:alpine3.18 WORKDIR / COPY . opt +RUN apk add --no-cache supercronic RUN pip install requests RUN crontab /opt/crontab RUN chmod +x /opt/entrypoint.sh diff --git a/crontab b/crontab deleted file mode 100644 index 257e14f..0000000 --- a/crontab +++ /dev/null @@ -1 +0,0 @@ -*/5 * * * * . /etc/environment; python /opt/crane.py >> /logfile \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index ca10c91..2f8c173 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,5 +1,10 @@ #!/bin/sh +CRON_CONFIG_FILE="/opt/crontab" -printenv | grep -v "no_proxy" >> /etc/environment +# CRON +get_env CRON +CRON="${CRON:-"5 * * * *"}" -crond -f \ No newline at end of file +echo "${CRON} python /opt/crane.py" >> "${CRON_CONFIG_FILE}" + +exec supercronic -passthrough-logs -quiet "${CRON_CONFIG_FILE}" \ No newline at end of file -- 2.45.2 From b16875da2979abfa9d4fc626eaca837f7be00dcb Mon Sep 17 00:00:00 2001 From: Jonathan Branan Date: Fri, 23 Jun 2023 03:06:59 -0500 Subject: [PATCH 2/4] included supercronic --- .drone.yml | 16 +++++++++++++++- entrypoint.sh | 9 +++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.drone.yml b/.drone.yml index fe15c96..87d4e72 100644 --- a/.drone.yml +++ b/.drone.yml @@ -15,4 +15,18 @@ steps: - latest when: branch: - - main \ No newline at end of file + - main +- name: docker-test + image: plugins/docker + settings: + registry: git.jbranan.com + dry_run: false + username: jblu + password: + from_secret: gittea_drone + repo: git.jbranan.com/jblu/crane + tags: + - dev + when: + branch: + - dev* \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index 2f8c173..4f59928 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,10 +1,7 @@ #!/bin/sh + CRON_CONFIG_FILE="/opt/crontab" -# CRON -get_env CRON -CRON="${CRON:-"5 * * * *"}" +echo "${CRON} python /opt/crane.py" > $CRON_CONFIG_FILE -echo "${CRON} python /opt/crane.py" >> "${CRON_CONFIG_FILE}" - -exec supercronic -passthrough-logs -quiet "${CRON_CONFIG_FILE}" \ No newline at end of file +exec supercronic -passthrough-logs -quiet $CRON_CONFIG_FILE \ No newline at end of file -- 2.45.2 From f66a42a84a5f3786183c72e68c92e1b132da9bed Mon Sep 17 00:00:00 2001 From: Jonathan Branan Date: Fri, 23 Jun 2023 03:08:36 -0500 Subject: [PATCH 3/4] removed crontab from dockerfile --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a43a41d..38a1694 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,5 @@ WORKDIR / COPY . opt RUN apk add --no-cache supercronic RUN pip install requests -RUN crontab /opt/crontab RUN chmod +x /opt/entrypoint.sh CMD ["/opt/entrypoint.sh"] \ No newline at end of file -- 2.45.2 From ff8136bf0ca9e11d64156024bf76345d0a2b1f6e Mon Sep 17 00:00:00 2001 From: Jonathan Branan Date: Fri, 23 Jun 2023 03:49:55 -0500 Subject: [PATCH 4/4] updated test --- cclient.py | 1 - test_crane.py | 4 ++-- test_pushover.py | 12 ------------ test_toml.py | 6 ------ 4 files changed, 2 insertions(+), 21 deletions(-) delete mode 100644 test_pushover.py delete mode 100644 test_toml.py diff --git a/cclient.py b/cclient.py index 3036b7d..a25ee5d 100644 --- a/cclient.py +++ b/cclient.py @@ -5,7 +5,6 @@ def c_get_containers(req_obj, host, port, access_token, endpoint): def c_get_filtered_containers(req_obj, j_obj, host, port, access_token, endpoint, containers, statuses): filter_string = j_obj.dumps({"name":containers,"status":statuses}) - # url = 'https://192.168.4.11:9443/api/endpoints/1/docker/containers/json?filters={"name": ["restic","qbittorrent"],"status": ["paused","dead","created","exited","removing","restarting","created"]}' url = f'https://{host}:{port}/api/endpoints/{endpoint}/docker/containers/json?filters={filter_string}' c_get_containers_response = req_obj.get(url, headers={"X-API-Key": access_token}, verify=False) return c_get_containers_response.json() diff --git a/test_crane.py b/test_crane.py index 823a760..63d10ec 100644 --- a/test_crane.py +++ b/test_crane.py @@ -2,7 +2,7 @@ import unittest import requests import json from tomllib import load -from cclient import c_get_filtered_containers, c_start_container, c_stop_container, c_get_filtered_containers +from cclient import c_get_filtered_containers, c_start_container, c_stop_container from cprocess import process_cont_list # unittest.TestLoader.sortTestMethodsUsing = None @@ -17,7 +17,7 @@ class TestCrane(unittest.TestCase): self.cid = 'ef8fee86e02b2b82acbddf6f0da1ff023f60bfe52c0b4087cac29c1686ccbac4' self.req_obj = requests self.j_obj = json - self.hypercare_containers = ['restic','qbittorrent'] + self.hypercare_containers = ['hello-world'] self.status_filters = ["paused","dead","created","exited","removing","restarting","created"] self.cont_obj = c_get_filtered_containers(self.req_obj,self.j_obj, self.host, self.port, self.access_token, self.endpoint,self.hypercare_containers,self.status_filters) diff --git a/test_pushover.py b/test_pushover.py deleted file mode 100644 index dc1f72f..0000000 --- a/test_pushover.py +++ /dev/null @@ -1,12 +0,0 @@ -import pushover -from tomllib import load - -with open('./config.toml', mode="rb") as c: - config = load(c) - -po_key = config["pushover"]["po_key"] -po_token = config["pushover"]["po_token"] - -message = "hello" - -# pushover.Pushover(po_token).message(po_key, message, title="--- crane summary ---") \ No newline at end of file diff --git a/test_toml.py b/test_toml.py deleted file mode 100644 index cd08b26..0000000 --- a/test_toml.py +++ /dev/null @@ -1,6 +0,0 @@ -from tomllib import load - -with open('./config.toml', mode="rb") as c: - config = load(c) - -print(config["containers"].values()) \ No newline at end of file -- 2.45.2