From 6ef9696e10ef828d43dee2a8e9adcefc75a2034d Mon Sep 17 00:00:00 2001 From: Roman Steiner Date: Sun, 18 Jul 2021 14:46:38 +0200 Subject: [PATCH] changed to debian container, added logging --- docker-compose.yml | 2 +- image/Dockerfile | 20 +++++++++++++++----- image/collect.sh | 12 ++++++++++-- image/git | 1 + sshkeys/.gitignore | 1 + 5 files changed, 28 insertions(+), 8 deletions(-) create mode 160000 image/git create mode 100644 sshkeys/.gitignore diff --git a/docker-compose.yml b/docker-compose.yml index b260d35..f15b0d3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,5 +7,5 @@ services: restart: always container_name: covid-collector volumes: - - "./data:/root/data" + - "./sshkeys:/root/.ssh" diff --git a/image/Dockerfile b/image/Dockerfile index 0162778..3019e3f 100644 --- a/image/Dockerfile +++ b/image/Dockerfile @@ -1,10 +1,20 @@ -FROM python:3.9-buster +FROM debian:bullseye-slim -RUN apt-get update; apt-get install --no-install-recommends cron +RUN apt-get update; apt-get install -y --no-install-recommends ssh ca-certificates wget cron git -RUN touch /var/log/cron.log +# configure GIT +RUN git config --global user.email "" ;\ + git config --global user.name "automatic covid-collector" ;\ + git config --global pull.rebase true + +# copy preconfigured git repo +COPY git /root/git + +# configure crontab COPY collect.sh /root/collect.sh -RUN echo '*/2 * * * * root /root/collect.sh' >> /etc/crontab +RUN chmod +x /root/collect.sh +RUN echo '15 15 * * * root /root/collect.sh >> /var/log/collect.log 2>&1' >> /etc/crontab -CMD ["/bin/bash", "-c", "cron && tail -f /var/log/cron.log"] +# run cron in foreground so it blocks and keeps the container running +CMD ["cron", "-f"] diff --git a/image/collect.sh b/image/collect.sh index 28d21ed..3114527 100644 --- a/image/collect.sh +++ b/image/collect.sh @@ -1,6 +1,14 @@ -!/bin/bash +#!/bin/bash +echo ----- automatic update $(date +%F-%H-%M) -------- +cd /root/git/ +git pull # download Covid-Cases for Austria based on age groupes -wget --output-document=/root/data/CovidFaelle_Altersgruppe-$(date +%F_%T).csv https://covid19-dashboard.ages.at/data/CovidFaelle_Altersgruppe.csv +wget --output-document=./data/CovidFaelle_Altersgruppe-$(date +%F-%H-%M).csv https://covid19-dashboard.ages.at/data/CovidFaelle_Altersgruppe.csv 2>&1 +git add data +git commit -m 'automatic update' +git push origin +echo ------------------------------------------------ +echo diff --git a/image/git b/image/git new file mode 160000 index 0000000..a952f65 --- /dev/null +++ b/image/git @@ -0,0 +1 @@ +Subproject commit a952f6573c88890ae3fc6eb65ef6f604b55c19b1 diff --git a/sshkeys/.gitignore b/sshkeys/.gitignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/sshkeys/.gitignore @@ -0,0 +1 @@ +*