Naposledy aktivní 1746485425

bjorn's Avatar bjorn revidoval tento gist 1746485425. Přejít na revizi

1 file changed, 82 insertions, 8 deletions

update_docker_stacks.sh

@@ -1,15 +1,89 @@
1 1 #!/bin/bash
2 2
3 - ROOT_DIR="$1" # Root directory passed as an argument
3 + set -euo pipefail
4 +
5 + # Regex for valid docker compose file names
6 + COMPOSE_REGEX='^(docker-compose|compose)\.ya?ml$'
7 +
8 + # Colors for output
9 + RED='\033[0;31m'
10 + GREEN='\033[0;32m'
11 + YELLOW='\033[1;33m'
12 + NC='\033[0m' # No Color
13 +
14 + # Dry-run mode
15 + DRY_RUN=0
16 +
17 + # Parse arguments
18 + while [[ $# -gt 0 ]]; do
19 + case "$1" in
20 + --dry-run)
21 + DRY_RUN=1
22 + shift
23 + ;;
24 + *)
25 + ROOT_DIR="$1"
26 + shift
27 + ;;
28 + esac
29 + done
30 +
31 + # Prompt for directory if not provided
32 + if [[ -z "${ROOT_DIR:-}" ]]; then
33 + echo -e "${YELLOW}No root directory provided.${NC}"
34 + read -e -p "Enter the root directory to search: " ROOT_DIR
35 + fi
36 +
37 + # Validate directory
38 + if [[ ! -d "$ROOT_DIR" ]]; then
39 + echo -e "${RED}Error: '$ROOT_DIR' is not a valid directory.${NC}"
40 + exit 1
41 + fi
42 +
43 + echo -e "${GREEN}Searching for docker-compose files in: $ROOT_DIR${NC}"
44 +
45 + processed=()
46 + skipped=()
4 47
5 48 find "$ROOT_DIR" -maxdepth 1 -type d -print0 | while IFS= read -r -d $'\0' dir; do
6 - if [ -f "$dir/docker-compose.yaml" ]; then
7 - echo "Processing: $dir"
8 - (
9 - cd "$dir" || exit 1 # Changed || to exit 1 for clearer error handling
10 - docker compose pull && docker compose up -d
11 - )
49 + # Skip the root directory itself if you want only subdirs
50 + # [[ "$dir" == "$ROOT_DIR" ]] && continue
51 +
52 + compose_file=""
53 + for file in "$dir"/*; do
54 + filename=$(basename "$file")
55 + if [[ $filename =~ $COMPOSE_REGEX ]]; then
56 + compose_file="$file"
57 + break
58 + fi
59 + done
60 +
61 + if [[ -n "$compose_file" ]]; then
62 + echo -e "${GREEN}Processing: $dir ($compose_file)${NC}"
63 + processed+=("$dir")
64 + if [[ $DRY_RUN -eq 0 ]]; then
65 + (
66 + cd "$dir" || exit 1
67 + docker compose -f "$compose_file" pull && docker compose -f "$compose_file" up -d
68 + )
69 + else
70 + echo -e "${YELLOW}[Dry-run] Would run: docker compose -f \"$compose_file\" pull && docker compose -f \"$compose_file\" up -d${NC}"
71 + fi
72 + else
73 + echo -e "${YELLOW}No compose file found in: $dir${NC}"
74 + skipped+=("$dir")
12 75 fi
13 76 done
14 77
15 - echo "Completed processing all subdirectories."
78 + echo -e "\n${GREEN}Completed processing all subdirectories.${NC}"
79 + echo -e "${GREEN}Processed directories:${NC}"
80 + for d in "${processed[@]}"; do
81 + echo " $d"
82 + done
83 +
84 + if [[ ${#skipped[@]} -gt 0 ]]; then
85 + echo -e "${YELLOW}Skipped directories (no compose file found):${NC}"
86 + for d in "${skipped[@]}"; do
87 + echo " $d"
88 + done
89 + fi

bjorn's Avatar bjorn revidoval tento gist 1746485177. Přejít na revizi

1 file changed, 1 insertion, 3 deletions

update_docker_stacks.sh

@@ -1,4 +1,3 @@
1 - ```bash
2 1 #!/bin/bash
3 2
4 3 ROOT_DIR="$1" # Root directory passed as an argument
@@ -13,5 +12,4 @@ find "$ROOT_DIR" -maxdepth 1 -type d -print0 | while IFS= read -r -d $'\0' dir;
13 12 fi
14 13 done
15 14
16 - echo "Completed processing all subdirectories."
17 - ```
15 + echo "Completed processing all subdirectories."

bjorn's Avatar bjorn revidoval tento gist 1746485160. Přejít na revizi

Žádné změny

bjorn's Avatar bjorn revidoval tento gist 1746485150. Přejít na revizi

1 file changed, 17 insertions

update_docker_stacks.sh(vytvořil soubor)

@@ -0,0 +1,17 @@
1 + ```bash
2 + #!/bin/bash
3 +
4 + ROOT_DIR="$1" # Root directory passed as an argument
5 +
6 + find "$ROOT_DIR" -maxdepth 1 -type d -print0 | while IFS= read -r -d $'\0' dir; do
7 + if [ -f "$dir/docker-compose.yaml" ]; then
8 + echo "Processing: $dir"
9 + (
10 + cd "$dir" || exit 1 # Changed || to exit 1 for clearer error handling
11 + docker compose pull && docker compose up -d
12 + )
13 + fi
14 + done
15 +
16 + echo "Completed processing all subdirectories."
17 + ```
Novější Starší