diff --git a/scripts/image-builder.sh b/scripts/image-builder.sh index 2ca60a2..6651588 100755 --- a/scripts/image-builder.sh +++ b/scripts/image-builder.sh @@ -613,82 +613,80 @@ load_project_config() { build_image() { local project=$1 local config_file="$PROJECT_CONFIG_DIR/$project/config-file" + local project_dir="$PROJECTS_DIR/$project" + + # Projekt-Konfiguration laden load_project_config "$config_file" - # Logs-Verzeichnis + # Logs-Verzeichnis prüfen mkdir -p "$LOGS_DIR" local timestamp timestamp=$(date +"%Y%m%d_%H%M%S") local 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 "Image: $image_name" | tee -a "$logfile" - echo "Architekturen: $architectures" | tee -a "$logfile" - echo "Push: $push" | tee -a "$logfile" - echo "Version: $version" | tee -a "$logfile" - echo "Latest: $latest" | tee -a "$logfile" - echo "====================================" | tee -a "$logfile" + echo "==== Build gestartet: $(date) ====" >> "$logfile" + echo "Projekt: $project" >> "$logfile" + echo "Registries: ${regs[*]}" >> "$logfile" + echo "Image: $image_name" >> "$logfile" + echo "Architekturen: $architectures" >> "$logfile" + echo "Push: $push" >> "$logfile" + echo "Version: $version" >> "$logfile" + echo "Latest: $latest" >> "$logfile" + echo "====================================" >> "$logfile" - # Plattformen für Buildx + # Plattformen korrekt für buildx local platforms - IFS=' ' read -ra archs <<< "$architectures" - platforms=$(printf "linux/%s," "${archs[@]}") - platforms="${platforms%,}" # letztes Komma entfernen + platforms=$(echo "$architectures" | sed 's/ /,linux\//g') + platforms="linux/$platforms" # Tags vorbereiten local tags=() for reg in "${regs[@]}"; do + # Key=Value Datei einlesen source "$CONFIG_DIR/registries/$reg/config-file" tags+=("-t" "${url}/${image_name}:${version}") [[ "$latest" == "yes" ]] && tags+=("-t" "${url}/${image_name}:latest") done - # Login zu allen Registries falls push=yes + # Push-Option + local push_flag="" if [[ "$push" == "yes" ]]; then + push_flag="--push" + # Login zu allen Registries for reg in "${regs[@]}"; do - local url username password - # key=value Datei einlesen source "$CONFIG_DIR/registries/$reg/config-file" - # url, username, password stehen jetzt als Variablen zur Verfügung if [[ -n "$username" && -n "$password" ]]; then docker login "$url" -u "$username" -p "$password" &>> "$logfile" fi done fi - # Build-Befehl - local build_cmd - build_cmd="docker buildx build --platform $platforms ${tags[*]} ./projects/$project" - if [[ "$push" == "yes" ]]; then - build_cmd+=" --push" - else - # nur erste Plattform lokal laden - build_cmd+=" --load --platform linux/${archs[0]}" - fi + # Build starten + { + docker buildx build --platform "$platforms" "$project_dir" "${tags[@]}" $push_flag + } &>> "$logfile" - # Build ausführen - if $build_cmd 2>&1 | tee -a "$logfile"; then - echo "==== Build beendet: $(date) ====" | tee -a "$logfile" - # Subversion erhöhen, falls auto_subversion=yes + if [[ $? -eq 0 ]]; then + echo "==== Build beendet: $(date) ====" >> "$logfile" + + # Auto Subversion erhöhen + local auto_subversion + auto_subversion=$(grep "^auto_subversion=" "$config_file" | cut -d= -f2) if [[ "$auto_subversion" == "yes" ]]; then - local major minor - major=${version%%.*} - minor=${version##*.} - minor=$((minor + 1)) - new_version="$major.$minor" - sed -i "s|^version=.*|version=$new_version|" "$config_file" - echo "Subversion automatisch auf $new_version erhöht." | tee -a "$logfile" + IFS='.' read -r major minor <<< "$version" + minor=$((minor+1)) + version="${major}.${minor}" + sed -i "s|^version=.*|version=$version|" "$config_file" + echo "Subversion automatisch auf $version erhöht." >> "$logfile" fi + + whiptail --msgbox "Build erfolgreich! Log: $logfile" 10 70 else - echo "==== Build fehlgeschlagen: $(date) ====" | tee -a "$logfile" + echo "==== Build fehlgeschlagen: $(date) ====" >> "$logfile" + whiptail --msgbox "Build fehlgeschlagen! Log: $logfile" 10 70 fi - - whiptail --msgbox "Build abgeschlossen. Log-Datei: $logfile" 10 60 } - # Logs ansehen (optional gefiltert nach Projekt) view_logs() { #ensure_logs_dir