edit function build_image

This commit is contained in:
2025-09-27 22:47:58 +02:00
parent fe797377bd
commit 9bfc3b26e3

View File

@@ -615,9 +615,7 @@ build_image() {
local config_file="$PROJECT_CONFIG_DIR/$project/config-file" local config_file="$PROJECT_CONFIG_DIR/$project/config-file"
load_project_config "$config_file" load_project_config "$config_file"
# Logs-Verzeichnis anlegen
mkdir -p "$LOGS_DIR" mkdir -p "$LOGS_DIR"
local timestamp local timestamp
timestamp=$(date +"%Y%m%d_%H%M%S") timestamp=$(date +"%Y%m%d_%H%M%S")
local logfile="$LOGS_DIR/${project}_${timestamp}.log" local logfile="$LOGS_DIR/${project}_${timestamp}.log"
@@ -632,56 +630,59 @@ build_image() {
echo "Latest: $latest" >> "$logfile" echo "Latest: $latest" >> "$logfile"
echo "====================================" >> "$logfile" echo "====================================" >> "$logfile"
# Registry-URL Funktion # Plattformen für Buildx
get_registry_url() { local platforms=""
local reg_name=$1 for arch in $architectures; do
local reg_file="$REGISTRY_CONFIG_DIR/$reg_name/config-file" case "$arch" in
if [[ -f "$reg_file" ]]; then amd64) platforms+="linux/amd64," ;;
jq -r '.url' "$reg_file" arm64) platforms+="linux/arm64," ;;
else armhf) platforms+="linux/arm/v7," ;;
echo "$reg_name" x86) platforms+="linux/386," ;;
fi esac
} done
platforms=${platforms%,} # letztes Komma entfernen
# Tags erstellen # Tags für alle Registries
tags=() local tags=()
IFS=',' read -r -a regs <<< "$registry" for reg in $registry; do
for r in "${regs[@]}"; do reg_url=$(get_registry_url "$reg")
[[ -n "$r" ]] && tags+=("-t $(get_registry_url "$r")/$image_name:$version") tags+=("-t" "$reg_url/$image_name:$version")
if [[ "$latest" == "yes" ]]; then if [[ "$latest" == "yes" ]]; then
tags+=("-t $(get_registry_url "$r")/$image_name:latest") tags+=("-t" "$reg_url/$image_name:latest")
fi fi
done done
# Architekturen korrekt formatieren # Build-Befehl
IFS=' ' read -r -a archs_arr <<< "$architectures" local build_cmd="docker buildx build --platform $platforms ${tags[*]} ./projects/$project"
platforms=$(printf ",linux/%s" "${archs_arr[@]}") if [[ "$push" == "yes" ]]; then
platforms=${platforms:1} # führendes Komma entfernen build_cmd+=" --push"
else
build_cmd+=" --load"
fi
# Build-Befehl als Array echo "$build_cmd" >> "$logfile"
build_cmd=(docker buildx build --platform "$platforms" "${tags[@]}" "./projects/$project")
[[ "$push" == "yes" ]] && build_cmd+=(--push) || build_cmd+=(--load) # Build starten
if ! eval "$build_cmd" >> "$logfile" 2>&1; then
echo "==== Build fehlgeschlagen: $(date) ====" >> "$logfile"
whiptail --msgbox "Build fehlgeschlagen! Log-Datei: $logfile" 10 70
return
fi
# Build ausführen
if "${build_cmd[@]}" >> "$logfile" 2>&1; then
echo "==== Build beendet: $(date) ====" >> "$logfile" echo "==== Build beendet: $(date) ====" >> "$logfile"
whiptail --msgbox "Build erfolgreich abgeschlossen.\nLog: $logfile" 12 70
# Subversion automatisch erhöhen, falls aktiviert # Subversion automatisch erhöhen
if [[ "${auto_subversion:-no}" == "yes" ]]; then if grep -q "^auto_subversion=yes" "$config_file"; then
IFS='.' read -r main sub <<< "$version" IFS='.' read -r main sub <<< "$version"
sub=$((sub + 1)) sub=$((sub + 1))
new_version="$main.$sub" new_version="$main.$sub"
sed -i "s|^version=.*|version=$new_version|" "$config_file" sed -i "s|^version=.*|version=$new_version|" "$config_file"
whiptail --msgbox "Subversion automatisch auf $new_version erhöht." 10 60 echo "Subversion automatisch auf $new_version erhöht." >> "$logfile"
fi
else
echo "==== Build fehlgeschlagen: $(date) ====" >> "$logfile"
whiptail --msgbox "Build fehlgeschlagen.\nLog: $logfile" 12 70
fi fi
whiptail --msgbox "Build erfolgreich abgeschlossen!\nLog-Datei: $logfile" 10 70
} }
# Logs ansehen (optional gefiltert nach Projekt) # Logs ansehen (optional gefiltert nach Projekt)
view_logs() { view_logs() {
#ensure_logs_dir #ensure_logs_dir