Fixed scripting issues and multi-repo issues.

This commit is contained in:
Nicole Rappe 2024-01-07 17:46:37 -07:00
parent 5415f58c33
commit ec6bd5f9d2
4 changed files with 15 additions and 7 deletions

5
.env
View File

@ -6,6 +6,5 @@ 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"

View File

@ -9,7 +9,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"]

View File

@ -8,4 +8,5 @@ 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

View File

@ -12,7 +12,7 @@ process_repo() {
echo "password=$GIT_PASSWORD" >> /tmp/git-credentials
# Directory to hold the repository locally
REPO_DIR="/root/Repo_Watcher/$(basename $REPO_URL)"
REPO_DIR="/root/Repo_Cache/$(basename $REPO_URL)"
# Clone the repo if it doesn't exist, or navigate to it if it does
if [ ! -d "$REPO_DIR" ]; then
@ -43,10 +43,18 @@ process_repo() {
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]}"
# Split the value by comma and read into separate variables
OLD_IFS="$IFS" # Save the original IFS
IFS=',' # Set IFS to comma for splitting
set -- $value # Set positional parameters ($1, $2, ...)
REPO_URL="$1" # Assign first parameter to REPO_URL
DESTINATION="$2" # Assign second parameter to DESTINATION
IFS="$OLD_IFS" # Restore original IFS
process_repo "$REPO_URL" "$DESTINATION"
done
# Wait for 5 seconds before the next iteration
sleep 5
done