Update Containers/Docker/Docker Compose/Custom Containers/Git Repo Updater.md
This commit is contained in:
@ -13,6 +13,7 @@ services:
|
||||
image: git.bunny-lab.io/container-registry/git-repo-updater:latest
|
||||
volumes:
|
||||
- /srv/containers:/srv/containers
|
||||
- /srv/containers/git-repo-updater/Repo_Cache:/root/Repo_Cache
|
||||
restart: always
|
||||
```
|
||||
|
||||
@ -25,9 +26,8 @@ GIT_PASSWORD=USE-AN-APP-PASSWORD
|
||||
NTFY_URL=https://ntfy.cyberstrawberry.net/git-repo-updater
|
||||
|
||||
# Repository/Destination Pairs (Add as Many as Needed)
|
||||
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"
|
||||
REPO_01="https://${GIT_USERNAME}:${GIT_PASSWORD}@git.bunny-lab.io/bunny-lab/docs.git,/srv/containers/material-mkdocs/docs/docs"
|
||||
REPO_02="https://${GIT_USERNAME}:${GIT_PASSWORD}@git.bunny-lab.io/GitOps/servers.bunny-lab.io.git,/srv/containers/homepage-docker"
|
||||
```
|
||||
### Build / Development
|
||||
If you want to learn how the container was assembled, the related build files are located [here](https://git.cyberstrawberry.net/container-registry/git-repo-updater)
|
||||
@ -43,7 +43,7 @@ COPY repo_watcher.sh /repo_watcher.sh
|
||||
RUN chmod +x /repo_watcher.sh
|
||||
|
||||
#Create Directory to store Repositories
|
||||
RUN mkdir -p /root/Repo_Watcher
|
||||
RUN mkdir -p /root/Repo_Cache
|
||||
|
||||
# Start script (Alpine uses /bin/sh instead of /bin/bash)
|
||||
CMD ["/bin/sh", "-c", "/repo_watcher.sh"]
|
||||
@ -54,40 +54,33 @@ CMD ["/bin/sh", "-c", "/repo_watcher.sh"]
|
||||
|
||||
# Function to process each repo-destination pair
|
||||
process_repo() {
|
||||
REPO_URL=$1
|
||||
FULL_REPO_URL=$1
|
||||
DESTINATION=$2
|
||||
|
||||
# Set Git credentials
|
||||
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
|
||||
# Extract the URL without credentials for logging and notifications
|
||||
CLEAN_REPO_URL=$(echo "$FULL_REPO_URL" | sed 's/https:\/\/[^@]*@/https:\/\//')
|
||||
|
||||
# Directory to hold the repository locally
|
||||
REPO_DIR="/root/Repo_Watcher/$(basename $REPO_URL)"
|
||||
REPO_DIR="/root/Repo_Cache/$(basename $CLEAN_REPO_URL .git)"
|
||||
|
||||
# Clone the repo if it doesn't exist, or navigate to it if it does
|
||||
if [ ! -d "$REPO_DIR" ]; then
|
||||
curl -d "Cloning: $REPO_URL" $NTFY_URL
|
||||
echo "Cloning: $REPO_URL"
|
||||
git clone "$REPO_URL" "$REPO_DIR"
|
||||
curl -d "Cloning: $CLEAN_REPO_URL" $NTFY_URL
|
||||
git clone "$FULL_REPO_URL" "$REPO_DIR" > /dev/null 2>&1
|
||||
fi
|
||||
cd "$REPO_DIR"
|
||||
cd "$REPO_DIR" || exit
|
||||
|
||||
# Fetch the latest changes
|
||||
git fetch origin main
|
||||
git fetch origin main > /dev/null 2>&1
|
||||
|
||||
# Check if the local repository is behind the remote
|
||||
LOCAL=$(git rev-parse @)
|
||||
REMOTE=$(git rev-parse @{u})
|
||||
|
||||
if [ $LOCAL != $REMOTE ]; then
|
||||
curl -d "Updating: $REPO_URL" $NTFY_URL
|
||||
echo "Updating: $REPO_URL"
|
||||
git pull origin main
|
||||
rsync -av --delete --exclude '.git/' ./ "$DESTINATION"
|
||||
else
|
||||
echo "Repository $REPO_URL Up-to-Date"
|
||||
if [ "$LOCAL" != "$REMOTE" ]; then
|
||||
curl -d "Updating: $CLEAN_REPO_URL" $NTFY_URL
|
||||
git pull origin main > /dev/null 2>&1
|
||||
rsync -av --delete --exclude '.git/' ./ "$DESTINATION" > /dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
@ -110,5 +103,4 @@ while true; do
|
||||
sleep 5
|
||||
done
|
||||
|
||||
|
||||
```
|
Reference in New Issue
Block a user