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