Added Infinite Repo Functionality (Beta)
This commit is contained in:
parent
ec619ffecd
commit
462bfa5e01
11
.env
11
.env
@ -1,10 +1,11 @@
|
|||||||
# Repository to Pull
|
# Gitea Credentials
|
||||||
REPO_URL=https://git.cyberstrawberry.net/cyberstrawberry/website.git
|
|
||||||
GIT_USERNAME=nicole.rappe
|
GIT_USERNAME=nicole.rappe
|
||||||
GIT_PASSWORD=USE-AN-APP-PASSWORD
|
GIT_PASSWORD=USE-AN-APP-PASSWORD
|
||||||
|
|
||||||
# NTFY Server to Notify on Pull Events
|
# NTFY Push Notification Server URL
|
||||||
NTFY_URL=https://ntfy.cyberstrawberry.net/git-repo-updater
|
NTFY_URL=https://ntfy.cyberstrawberry.net/git-repo-updater
|
||||||
|
|
||||||
# Folder of the destination server / container folder where you want the repository data to transfer
|
# Repository/Destination Pairs (Add as Many as Needed)
|
||||||
DESTINATION=/srv/containers/nginx-portfolio-website/www
|
REPO_01="https://git.bunny-lab.io/repo1.git,/srv/containers/destination"
|
||||||
|
REPO_02="https://git.bunny-lab.io/repo1.git,/srv/containers/destination"
|
||||||
|
REPO_03="https://git.bunny-lab.io/repo1.git,/srv/containers/destination"
|
@ -3,13 +3,9 @@ services:
|
|||||||
git-repo-updater:
|
git-repo-updater:
|
||||||
privileged: true
|
privileged: true
|
||||||
container_name: git-repo-updater
|
container_name: git-repo-updater
|
||||||
environment:
|
env_file:
|
||||||
- REPO_URL=${REPO_URL}
|
- stack.env
|
||||||
- COPY_DIR=${COPY_DIR}
|
image: git.bunny-lab.io/container-registry/git-repo-updater:latest
|
||||||
- NTFY_URL=${NTFY_URL}
|
|
||||||
- GIT_USERNAME=${GIT_USERNAME}
|
|
||||||
- GIT_PASSWORD=${GIT_PASSWORD}
|
|
||||||
image: git.cyberstrawberry.net/container-registry/git-repo-updater:latest
|
|
||||||
volumes:
|
volumes:
|
||||||
- ${DESTINATION}:/DATA
|
- /srv/containers:/srv/containers
|
||||||
restart: always
|
restart: always
|
@ -1,25 +1,26 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
while true; do
|
# Function to process each repo-destination pair
|
||||||
|
process_repo() {
|
||||||
|
REPO_URL=$1
|
||||||
|
DESTINATION=$2
|
||||||
|
|
||||||
# Set Git credentials
|
# Set Git credentials
|
||||||
git config --global credential.helper 'store --file /tmp/git-credentials'
|
git config --global credential.helper 'store --file /tmp/git-credentials'
|
||||||
echo "url=$REPO_URL" > /tmp/git-credentials
|
echo "url=$REPO_URL" > /tmp/git-credentials
|
||||||
echo "username=$GIT_USERNAME" >> /tmp/git-credentials
|
echo "username=$GIT_USERNAME" >> /tmp/git-credentials
|
||||||
echo "password=$GIT_PASSWORD" >> /tmp/git-credentials
|
echo "password=$GIT_PASSWORD" >> /tmp/git-credentials
|
||||||
|
|
||||||
# Navigate to the watcher directory
|
# Directory to hold the repository locally
|
||||||
cd /root/Repo_Watcher
|
REPO_DIR="/root/Repo_Watcher/$(basename $REPO_URL)"
|
||||||
|
|
||||||
# Clone the repo if it doesn't exist
|
# Clone the repo if it doesn't exist, or navigate to it if it does
|
||||||
if [ -z "$(find /root/Repo_Watcher/repo -maxdepth 1 -mindepth 1 -type f -o -type d 2>/dev/null)" ]; then
|
if [ ! -d "$REPO_DIR" ]; then
|
||||||
curl -d "Pulling: $REPO_URL" $NTFY_URL
|
curl -d "Cloning: $REPO_URL" $NTFY_URL
|
||||||
echo "Pulling: $REPO_URL"
|
echo "Cloning: $REPO_URL"
|
||||||
git clone $REPO_URL repo
|
git clone "$REPO_URL" "$REPO_DIR"
|
||||||
cd repo
|
|
||||||
rsync -av --delete --exclude '.git/' ./ /DATA
|
|
||||||
fi
|
fi
|
||||||
|
cd "$REPO_DIR"
|
||||||
cd repo
|
|
||||||
|
|
||||||
# Fetch the latest changes
|
# Fetch the latest changes
|
||||||
git fetch origin main
|
git fetch origin main
|
||||||
@ -27,18 +28,25 @@ while true; do
|
|||||||
# 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})
|
|
||||||
|
|
||||||
if [ $LOCAL = $REMOTE ]; then
|
if [ $LOCAL != $REMOTE ]; then
|
||||||
echo "Repository Up-to-Date"
|
curl -d "Updating: $REPO_URL" $NTFY_URL
|
||||||
else
|
echo "Updating: $REPO_URL"
|
||||||
curl -d "Pulling: $REPO_URL" $NTFY_URL
|
|
||||||
echo "Pulling: $REPO_URL"
|
|
||||||
git pull origin main
|
git pull origin main
|
||||||
rsync -av --delete --exclude '.git/' ./ /DATA
|
rsync -av --delete --exclude '.git/' ./ "$DESTINATION"
|
||||||
|
else
|
||||||
|
echo "Repository $REPO_URL Up-to-Date"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main loop
|
||||||
|
while true; do
|
||||||
|
# Iterate over each environment variable matching 'REPO_[0-9]+'
|
||||||
|
env | grep '^REPO_[0-9]\+=' | while IFS='=' read -r name value; do
|
||||||
|
IFS=',' read -ra REPO_DEST <<< "$value"
|
||||||
|
process_repo "${REPO_DEST[0]}" "${REPO_DEST[1]}"
|
||||||
|
done
|
||||||
|
|
||||||
# Wait for 5 seconds before the next iteration
|
# Wait for 5 seconds before the next iteration
|
||||||
sleep 5
|
sleep 5
|
||||||
|
|
||||||
done
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user