diff --git a/scripts/image-builder.sh b/scripts/image-builder.sh index 3de6ede..4f5590c 100755 --- a/scripts/image-builder.sh +++ b/scripts/image-builder.sh @@ -598,35 +598,30 @@ EOF # Projektparameter laden load_project_config() { - local config_file=$1 + local config_file="$1" registry=$(grep "^registry=" "$config_file" | cut -d= -f2) image_name=$(grep "^image_name=" "$config_file" | cut -d= -f2) architectures=$(grep "^architectures=" "$config_file" | cut -d= -f2) push=$(grep "^push=" "$config_file" | cut -d= -f2) version=$(grep "^version=" "$config_file" | cut -d= -f2) latest=$(grep "^latest=" "$config_file" | cut -d= -f2) - auto_increment=$(grep "^auto_increment=" "$config_file" | cut -d= -f2 2>/dev/null || echo "no") git_repo=$(grep "^git_repo=" "$config_file" | cut -d= -f2) + auto_subversion=$(grep "^auto_subversion=" "$config_file" | cut -d= -f2 || echo "no") } + +# Image bauen # Image bauen build_image() { local project=$1 local config_file="$PROJECT_CONFIG_DIR/$project/config-file" - local project_dir="$PROJECTS_DIR/$project" - load_project_config "$config_file" - local tags="-t $registry/$image_name:$version" - [ "$latest" = "yes" ] && tags="$tags -t $registry/$image_name:latest" - + ensure_logs_dir local timestamp timestamp=$(date +"%Y%m%d_%H%M%S") local logfile="$LOGS_DIR/${project}_${timestamp}.log" - whiptail --msgbox "Starte Build:\n\nProjekt: $project\nRegistry: $registry\nImage: $image_name\nArchitekturen: $architectures\nPush: $push\nVersion: $version\nTags: $tags\n\nBuild-Log: $logfile" 20 70 - - # Build ausführen und alles ins Log schreiben { echo "==== Build gestartet: $(date) ====" echo "Projekt: $project" @@ -635,30 +630,50 @@ build_image() { echo "Architekturen: $architectures" echo "Push: $push" echo "Version: $version" - echo "Tags: $tags" + echo "Latest-Tag: $latest" echo "====================================" - docker buildx build --platform "$architectures" $tags "$project_dir" $( [ "$push" = "yes" ] && echo "--push" ) - echo "==== Build abgeschlossen: $(date) ====" - } &> "$logfile" + } | tee "$logfile" - # Version hochzählen falls auto_increment aktiv - if [ "$auto_increment" = "yes" ]; then - base=$(echo "$version" | cut -d. -f1) - sub=$(echo "$version" | cut -d. -f2) - new_sub=$((sub+1)) - new_version="$base.$new_sub" - sed -i "s|^version=.*|version=$new_version|" "$config_file" - fi + # Architekturen in Buildx-Format umwandeln (linux/arch, getrennt durch Komma) + local platforms + platforms=$(echo "$architectures" | xargs -n1 | sed 's|^|linux/|' | paste -sd, -) - # Nachfrage, ob Log angezeigt werden soll - if whiptail --yesno "Build abgeschlossen!\n\nMöchten Sie die Logdatei jetzt ansehen?\n\n$logfile" 15 70; then - EDITOR_CMD=$(get_editor_cmd) - $EDITOR_CMD "$logfile" - else - whiptail --msgbox "Build abgeschlossen!\n\nLogdatei: $logfile" 12 70 + # Tags aufbauen + local tags=() + IFS=',' read -ra regs <<< "$registry" + for reg in "${regs[@]}"; do + tags+=("-t" "${reg}/${image_name}:${version}") + if [[ "$latest" == "yes" ]]; then + tags+=("-t" "${reg}/${image_name}:latest") + fi + done + + # Push-Flag + local push_flag="" + [[ "$push" == "yes" ]] && push_flag="--push" + + { + docker buildx build \ + --platform "$platforms" \ + "${tags[@]}" \ + "$PROJECTS_DIR/$project" \ + $push_flag + } 2>&1 | tee -a "$logfile" + + echo "==== Build beendet: $(date) ====" | tee -a "$logfile" + + # Auto-Subversion + if [[ "$auto_subversion" == "yes" ]]; then + local major minor + major=$(echo "$version" | cut -d. -f1) + minor=$(echo "$version" | cut -d. -f2) + minor=$((minor + 1)) + sed -i "s/^version=.*/version=${major}.${minor}/" "$config_file" + echo "Subversion automatisch auf ${major}.${minor} erhöht." | tee -a "$logfile" fi } + # Logs ansehen (optional gefiltert nach Projekt) view_logs() { ensure_logs_dir