Updated Approach to Scheduling
This commit is contained in:
parent
4fdaf788b5
commit
9038a7c9b2
12
Dockerfile
12
Dockerfile
@ -2,17 +2,13 @@ FROM ubuntu:latest
|
|||||||
|
|
||||||
# Install necessary packages
|
# Install necessary packages
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y git curl cron rsync
|
apt-get install -y git curl rsync
|
||||||
|
|
||||||
# Add script and cronjob
|
# Add script
|
||||||
COPY repo_watcher.sh /root/Repo_Watcher/repo_watcher.sh
|
COPY repo_watcher.sh /root/Repo_Watcher/repo_watcher.sh
|
||||||
COPY crontab.txt /crontab.txt
|
|
||||||
|
|
||||||
# Make script executable
|
# Make script executable
|
||||||
RUN chmod +x /root/Repo_Watcher/repo_watcher.sh
|
RUN chmod +x /root/Repo_Watcher/repo_watcher.sh
|
||||||
|
|
||||||
# Apply cron job
|
# Start script
|
||||||
RUN crontab /crontab.txt
|
CMD ["/bin/bash", "-c", "/root/Repo_Watcher/repo_watcher.sh"]
|
||||||
|
|
||||||
# Start cron in foreground
|
|
||||||
CMD ["cron", "-f"]
|
|
@ -1,4 +0,0 @@
|
|||||||
**Basic Docker Run Command**:
|
|
||||||
```
|
|
||||||
docker run -e REPO_URL='https://your.git.repo.url' -e COPY_DIR='/your/copy/dir' -e NTFY_URL='https://your.ntfy.url' -e GIT_USERNAME='your_username' -e GIT_PASSWORD='your_password' git_repo_updater
|
|
||||||
```
|
|
@ -1 +0,0 @@
|
|||||||
* * * * * /bin/bash /root/Repo_Watcher/repo_watcher.sh
|
|
@ -1,45 +1,52 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Fetch environment variables
|
while true; do
|
||||||
repo_url=$REPO_URL
|
|
||||||
copy_dir=$COPY_DIR
|
|
||||||
ntfy_url=$NTFY_URL
|
|
||||||
git_username=$GIT_USERNAME
|
|
||||||
git_password=$GIT_PASSWORD
|
|
||||||
|
|
||||||
# Set Git credentials
|
# Fetch environment variables
|
||||||
git config --global credential.helper 'store --file /tmp/git-credentials'
|
repo_url=$REPO_URL
|
||||||
echo "url=$repo_url" > /tmp/git-credentials
|
copy_dir=$COPY_DIR
|
||||||
echo "username=$git_username" >> /tmp/git-credentials
|
ntfy_url=$NTFY_URL
|
||||||
echo "password=$git_password" >> /tmp/git-credentials
|
git_username=$GIT_USERNAME
|
||||||
|
git_password=$GIT_PASSWORD
|
||||||
|
|
||||||
# Navigate to the watcher directory
|
# Set Git credentials
|
||||||
cd /root/Repo_Watcher
|
git config --global credential.helper 'store --file /tmp/git-credentials'
|
||||||
|
echo "url=$repo_url" > /tmp/git-credentials
|
||||||
|
echo "username=$git_username" >> /tmp/git-credentials
|
||||||
|
echo "password=$git_password" >> /tmp/git-credentials
|
||||||
|
|
||||||
# Clone the repo if it doesn't exist
|
# Navigate to the watcher directory
|
||||||
if [ ! -d "repo" ]; then
|
cd /root/Repo_Watcher
|
||||||
|
|
||||||
|
# Clone the repo if it doesn't exist
|
||||||
|
if [ ! -d "repo" ]; then
|
||||||
git clone $repo_url repo
|
git clone $repo_url repo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd repo
|
cd repo
|
||||||
|
|
||||||
# Fetch the latest changes
|
# Fetch the latest changes
|
||||||
git fetch origin main
|
git fetch origin main
|
||||||
|
|
||||||
# Check if the local repository is behind the remote
|
# Check if the local repository is behind the remote
|
||||||
LOCAL=$(git rev-parse @)
|
LOCAL=$(git rev-parse @)
|
||||||
REMOTE=$(git rev-parse @{u})
|
REMOTE=$(git rev-parse @{u})
|
||||||
BASE=$(git merge-base @ @{u})
|
BASE=$(git merge-base @ @{u})
|
||||||
|
|
||||||
if [ $LOCAL = $REMOTE ]; then
|
if [ $LOCAL = $REMOTE ]; then
|
||||||
echo "Up-to-date"
|
echo "Up-to-date"
|
||||||
elif [ $LOCAL = $BASE ]; then
|
elif [ $LOCAL = $BASE ]; then
|
||||||
echo "Need to pull"
|
echo "Need to pull"
|
||||||
git pull origin main
|
git pull origin main
|
||||||
rsync -av --delete ./ $copy_dir
|
rsync -av --delete ./ $copy_dir
|
||||||
curl -d "Data updated from Git repo" $ntfy_url
|
curl -d "Data updated from Git repo" $ntfy_url
|
||||||
elif [ $REMOTE = $BASE ]; then
|
elif [ $REMOTE = $BASE ]; then
|
||||||
echo "Need to push"
|
echo "Need to push"
|
||||||
else
|
else
|
||||||
echo "Data diverged"
|
echo "Data diverged"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Wait for 5 seconds before the next iteration
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
done
|
Loading…
x
Reference in New Issue
Block a user