diff --git a/scripts/image-builder.sh b/scripts/image-builder.sh index 9f19de3..a4b8b89 100755 --- a/scripts/image-builder.sh +++ b/scripts/image-builder.sh @@ -661,15 +661,31 @@ registry_login() { build_image() { local project=$1 local config_file="$PROJECT_CONFIG_DIR/$project/config-file" + + # ---- Konfiguration laden ---- load_project_config "$config_file" - local timestamp + # Prüfen, ob Registry gesetzt ist + if [[ -z "$registry" ]]; then + echo "Keine Registry definiert! Build abgebrochen." + whiptail --msgbox "Keine Registry definiert für Projekt $project. Build abgebrochen." 10 60 + return 1 + fi + + # Architekturen prüfen + if [[ -z "$architectures" ]]; then + echo "Keine Architekturen definiert! Build abgebrochen." + whiptail --msgbox "Keine Architekturen definiert für Projekt $project. Build abgebrochen." 10 60 + return 1 + fi + + local timestamp logfile timestamp=$(date +"%Y%m%d_%H%M%S") - local logfile="$LOGS_DIR/${project}_${timestamp}.log" + logfile="$LOGS_DIR/${project}_${timestamp}.log" echo "==== Build gestartet: $(date) ====" | tee -a "$logfile" echo "Projekt: $project" | tee -a "$logfile" - echo "Registries: $registry" | tee -a "$logfile" + echo "Registry: $registry" | tee -a "$logfile" echo "Image: $image_name" | tee -a "$logfile" echo "Architekturen: $architectures" | tee -a "$logfile" echo "Push: $push" | tee -a "$logfile" @@ -677,43 +693,40 @@ build_image() { echo "Latest: $latest" | tee -a "$logfile" echo "====================================" | tee -a "$logfile" - # Architekturen-Array vorbereiten - load_project_config "$project" - - local platforms="" - local arch_array=() - # Split nach Leerzeichen - read -r -a arch_array <<< "$architectures" + # ---- Plattformen vorbereiten ---- + local platforms arch_array + read -r -a arch_array <<< "${architectures//,/ }" + platforms="" for arch in "${arch_array[@]}"; do case "$arch" in amd64) platforms+="linux/amd64," ;; arm64) platforms+="linux/arm64," ;; armhf) platforms+="linux/arm/v7," ;; x86) platforms+="linux/386," ;; - *) echo "WARNUNG: Unbekannte Architektur '$arch' wird ignoriert." ;; + *) echo "WARNUNG: Unbekannte Architektur '$arch' wird ignoriert." | tee -a "$logfile" ;; esac done - - platforms="${platforms%,}" - - echo "DEBUG platforms='$platforms'" | tee -a "$logfile" + platforms="${platforms%,}" # letztes Komma entfernen if [[ -z "$platforms" ]]; then - echo "Keine Architektur ausgewählt. Build abgebrochen." | tee -a "$logfile" + echo "Keine gültigen Architekturen gefunden. Build abgebrochen." | tee -a "$logfile" return 1 fi - # Tags für alle Registries vorbereiten + echo "DEBUG: platforms=$platforms" | tee -a "$logfile" + + # ---- Tags für Registry vorbereiten ---- IFS=',' read -ra reg_array <<< "$registry" tags=() for reg in "${reg_array[@]}"; do reg=$(echo "$reg" | xargs) # trim [[ -z "$reg" ]] && continue - # Docker-Login für Registry (falls Config vorhanden) - reg_config="$CONFIG_DIR/registries/$reg/config-file" + # Login falls Registry-Config existiert + local reg_config="$REGISTRY_CONFIG_DIR/$reg/config-file" if [[ -f "$reg_config" ]]; then + local reg_user reg_pass reg_user=$(grep "^username=" "$reg_config" | cut -d= -f2) reg_pass=$(grep "^password=" "$reg_config" | cut -d= -f2) if [[ -n "$reg_user" && -n "$reg_pass" ]]; then @@ -724,9 +737,7 @@ build_image() { fi tags+=("-t" "$reg/$image_name:$version") - if [[ "$latest" == "yes" ]]; then - tags+=("-t" "$reg/$image_name:latest") - fi + [[ "$latest" == "yes" ]] && tags+=("-t" "$reg/$image_name:latest") done if [[ ${#tags[@]} -eq 0 ]]; then @@ -734,21 +745,23 @@ build_image() { return 1 fi - # Build-Befehl zusammenbauen + # ---- Docker Build-Befehl ---- + local cmd if [[ "$push" == "yes" ]]; then cmd=(docker buildx build --platform "$platforms" "${tags[@]}" "$PROJECTS_DIR/$project" --push) else cmd=(docker buildx build --platform "$platforms" "${tags[@]}" "$PROJECTS_DIR/$project" --load) fi - echo "${cmd[*]}" | tee -a "$logfile" + echo "Build-Befehl: ${cmd[*]}" | tee -a "$logfile" + # ---- Build ausführen ---- if "${cmd[@]}" >>"$logfile" 2>&1; then echo "==== Build beendet: $(date) ====" | tee -a "$logfile" - # Auto-Subversion + # Auto-Subversion erhöhen if [[ "$auto_subversion" == "yes" ]]; then - local major minor + local major minor new_version major=$(echo "$version" | cut -d. -f1) minor=$(echo "$version" | cut -d. -f2) minor=$((minor + 1)) @@ -758,6 +771,7 @@ build_image() { fi else echo "==== Build fehlgeschlagen: $(date) ====" | tee -a "$logfile" + whiptail --msgbox "Build für Projekt $project fehlgeschlagen. Details im Log: $logfile" 10 70 return 1 fi }