Update scripts/dccd2.sh
This commit is contained in:
parent
86cf6c018e
commit
e9315da2f7
1 changed files with 24 additions and 20 deletions
|
@ -64,29 +64,33 @@ update_compose_files() {
|
||||||
if [ "$local_hash" != "$remote_hash" ]; then
|
if [ "$local_hash" != "$remote_hash" ]; then
|
||||||
log_message "STATE: Hashes don't match, checking for relevant changes..."
|
log_message "STATE: Hashes don't match, checking for relevant changes..."
|
||||||
|
|
||||||
# Get the list of changed files
|
# Get the list of changed files
|
||||||
changed_files=$(git diff --name-only "origin/$REMOTE_BRANCH")
|
changed_files=$(git diff --name-only "origin/$REMOTE_BRANCH")
|
||||||
|
|
||||||
# Loop through directories matching the specified pattern
|
# Loop through directories matching the specified pattern
|
||||||
find "$dir" -type d -name "$folder_pattern" | while IFS= read -r folder; do
|
find "$dir" -type d -name "$folder_pattern" | while IFS= read -r folder; do
|
||||||
log_message "INFO: Found folder matching pattern: $folder"
|
log_message "INFO: Found folder matching pattern: $folder"
|
||||||
|
|
||||||
# If EXCLUDE is set and the directory matches the exclude pattern, skip
|
# If EXCLUDE is set and the directory matches the exclude pattern, skip
|
||||||
if [ -n "$EXCLUDE" ] && [[ "$folder" == *"$EXCLUDE"* ]]; then
|
if [ -n "$EXCLUDE" ] && [[ "$folder" == *"$EXCLUDE"* ]]; then
|
||||||
log_message "INFO: Excluding directory $folder"
|
log_message "INFO: Excluding directory $folder"
|
||||||
continue
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if the docker-compose.yml file in this folder has changed
|
||||||
|
compose_file_changed=false
|
||||||
|
for file in $changed_files; do
|
||||||
|
log_message "DEBUG: Comparing changed file: $file" # Added debug line
|
||||||
|
log_message "DEBUG: With target file: $folder/docker-compose.yml" # Added debug line
|
||||||
|
log_message "DEBUG: Length of changed file: ${#file}"
|
||||||
|
log_message "DEBUG: Length of target file: ${#folder/docker-compose.yml}"
|
||||||
|
if [[ "$file" == "$folder/docker-compose.yml" ]]; then
|
||||||
|
compose_file_changed=true
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# Check if any changed file is within this directory
|
if $compose_file_changed; then
|
||||||
changed_file_in_dir=false
|
|
||||||
for file in $changed_files; do
|
|
||||||
if [[ "$file" == "$folder"* ]]; then
|
|
||||||
changed_file_in_dir=true
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if $changed_file_in_dir; then
|
|
||||||
# Go into the directory
|
# Go into the directory
|
||||||
cd "$folder" || { log_message "ERROR: Failed to enter directory $folder"; send_notification "Script Error" "Failed to update compose files: Failed to enter directory $folder"; continue; }
|
cd "$folder" || { log_message "ERROR: Failed to enter directory $folder"; send_notification "Script Error" "Failed to update compose files: Failed to enter directory $folder"; continue; }
|
||||||
|
|
||||||
|
@ -97,7 +101,7 @@ update_compose_files() {
|
||||||
# Go back to the original directory
|
# Go back to the original directory
|
||||||
cd "$dir" || { log_message "ERROR: Failed to return to directory $dir"; send_notification "Script Error" "Failed to update compose files: Failed to return to directory $dir"; exit 1; }
|
cd "$dir" || { log_message "ERROR: Failed to return to directory $dir"; send_notification "Script Error" "Failed to update compose files: Failed to return to directory $dir"; exit 1; }
|
||||||
else
|
else
|
||||||
log_message "INFO: No changes detected in $folder, skipping..."
|
log_message "INFO: No changes detected in docker-compose.yml for $folder, skipping..."
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
|
|
Reference in a new issue