From a97da6711178a9bd49e711c3119ed256cb241e42 Mon Sep 17 00:00:00 2001 From: YuruC3 <98943911+YuruC3@@users.noreply.github.com> Date: Sun, 11 May 2025 16:42:14 +0200 Subject: [PATCH] Working docker-compose --- code/requirements.txt | 3 ++- docker/.gitignore | 2 +- docker/Dockerfile | 19 +++++++++++++------ docker/cron-jobs | 6 ++++-- docker/docker-compose.yml | 2 +- docker/gitPush.sh | 17 ++++++++++------- docker/mainDocker.py | 6 ++++-- docker/requirements.txt | 3 ++- 8 files changed, 37 insertions(+), 21 deletions(-) diff --git a/code/requirements.txt b/code/requirements.txt index e779096..a2aa631 100644 --- a/code/requirements.txt +++ b/code/requirements.txt @@ -1,3 +1,4 @@ beautifulsoup4==4.13.4 requests==2.32.3 -schedule==1.2.2 \ No newline at end of file +schedule==1.2.2 +nslookup==1.8.1 \ No newline at end of file diff --git a/docker/.gitignore b/docker/.gitignore index d1c9345..233416d 100644 --- a/docker/.gitignore +++ b/docker/.gitignore @@ -1,3 +1,3 @@ repo __pycache__ -.env \ No newline at end of file +/.env \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index 002ab1c..68838f6 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -7,11 +7,15 @@ RUN apk update && \ apk add python3 py3-pip git # inotify-tools -RUN mkdir /etc/debmirror && \ - touch /etc/debmirror/MirrorListV6 && \ - touch /etc/debmirror/MirrorListV4 +RUN mkdir /etc/debmirror WORKDIR /etc/debmirror/ +RUN git clone https://tea.shupogaki.org/YuruC3/Debain-repos && \ + ln -s /etc/debmirror/Debain-repos/MirrorListV4 /etc/debmirror/MirrorListV4 && \ + ln -s /etc/debmirror/Debain-repos/MirrorListV6 /etc/debmirror/MirrorListV6 +# RUN touch /etc/debmirror/MirrorListV6 && \ +# touch /etc/debmirror/MirrorListV4 + COPY mainDocker.py /etc/debmirror/ COPY whatDomain.py /etc/debmirror/ COPY requirements.txt /etc/debmirror/ @@ -21,8 +25,11 @@ RUN python3 -m venv venv && \ venv/bin/pip3 install -r requirements.txt COPY cron-jobs /etc/crontabs/ -COPY gitPush.sh /etc/crontabs/ +RUN chmod 0644 /etc/crontabs/cron-jobs && \ + crontab /etc/crontabs/cron-jobs -RUN chmod +x /etc/crontabs/gitPush.sh +COPY gitPush.sh /etc/debmirror/ -CMD ["/usr/sbin/crond"] +RUN chmod +x /etc/debmirror/gitPush.sh + +CMD ["/usr/sbin/crond", "-f"] diff --git a/docker/cron-jobs b/docker/cron-jobs index 317a727..08ce8dc 100644 --- a/docker/cron-jobs +++ b/docker/cron-jobs @@ -1,5 +1,7 @@ # python -25 19 * * * /etc/debmirror/venv/bin/python3 /etc/debmirror/mainDocker.py +# 25 19 * * * /etc/debmirror/venv/bin/python3 /etc/debmirror/mainDocker.py +*/3 * * * * /etc/debmirror/venv/bin/python3 /etc/debmirror/mainDocker.py # git push -30 19 * * * /bin/sh /etc/debmirror/gitPush.sh \ No newline at end of file +# 30 19 * * * /bin/sh /etc/debmirror/gitPush.sh +*/1 * * * * /bin/sh /etc/debmirror/gitPush.sh \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index c4c3487..2b06201 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -4,7 +4,7 @@ services: debmirup: container_name: Debian_Mirrors_Updater build: ./ - image: DebMirrorLists:V1 + image: debmirrorupd:V1 environment: - DEBMIRRORURL=https://www.debian.org/mirror/list - GITEA_TOKEN= diff --git a/docker/gitPush.sh b/docker/gitPush.sh index a18cd75..25757f3 100644 --- a/docker/gitPush.sh +++ b/docker/gitPush.sh @@ -3,7 +3,8 @@ set -e WORKPTH="/etc/debmirror/" REPO_DIR="$WORKPTH/Debain-repos" -REPO_URL="https://$GITEA_TOKEN@tea.shupogaki.org/YuruC3/Debain-repos.git" +REPO_URL="https://tea.shupogaki.org/YuruC3/Debain-repos.git" + # Clone repo only if it doesn't already exist if [ ! -d "$REPO_DIR/.git" ]; then @@ -14,6 +15,7 @@ fi cd "$REPO_DIR" +git remote set-url origin "https://${GITEA_TOKEN}@tea.shupogaki.org/YuruC3/Debain-repos.git" git config user.name "UpdateBot" git config user.email "UpdateBot@localhost.local" @@ -21,14 +23,15 @@ git config user.email "UpdateBot@localhost.local" # pull changes git pull -# check if modified -if git diff --quiet && git diff --cached --quiet; then - echo "No changes to commit." -# if yes, push +# stage files +git add MirrorListV4 MirrorListV6 + +# Commit and push only if there's anything new staged +if git diff --cached --quiet; then + echo "[$(date)] No changes to commit." else - git add MirrorsV4 MirrorsV6 git commit -m "Auto-update mirror list on $(date -Iseconds)" git push - echo "Changes pushed successfully." + echo "[$(date)] Changes pushed successfully." fi diff --git a/docker/mainDocker.py b/docker/mainDocker.py index 32797f9..56245ab 100644 --- a/docker/mainDocker.py +++ b/docker/mainDocker.py @@ -8,8 +8,8 @@ if os.environ["DEBMIRRORURL"]: else: DEBMIRRORURL = "https://www.debian.org/mirror/list" -IPv4FILE = "./MirrorListV4" -IPv6FILE = "./MirrorListV6" +IPv4FILE = "/etc/debmirror/MirrorListV4" +IPv6FILE = "/etc/debmirror/MirrorListV6" # Define EU and American countries @@ -146,3 +146,5 @@ def LeJob(): LeJob() + +print("Done") \ No newline at end of file diff --git a/docker/requirements.txt b/docker/requirements.txt index e779096..a2aa631 100644 --- a/docker/requirements.txt +++ b/docker/requirements.txt @@ -1,3 +1,4 @@ beautifulsoup4==4.13.4 requests==2.32.3 -schedule==1.2.2 \ No newline at end of file +schedule==1.2.2 +nslookup==1.8.1 \ No newline at end of file