edit function build_image
This commit is contained in:
@@ -661,15 +661,31 @@ registry_login() {
|
|||||||
build_image() {
|
build_image() {
|
||||||
local project=$1
|
local project=$1
|
||||||
local config_file="$PROJECT_CONFIG_DIR/$project/config-file"
|
local config_file="$PROJECT_CONFIG_DIR/$project/config-file"
|
||||||
|
|
||||||
|
# ---- Konfiguration laden ----
|
||||||
load_project_config "$config_file"
|
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")
|
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 "==== Build gestartet: $(date) ====" | tee -a "$logfile"
|
||||||
echo "Projekt: $project" | 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 "Image: $image_name" | tee -a "$logfile"
|
||||||
echo "Architekturen: $architectures" | tee -a "$logfile"
|
echo "Architekturen: $architectures" | tee -a "$logfile"
|
||||||
echo "Push: $push" | tee -a "$logfile"
|
echo "Push: $push" | tee -a "$logfile"
|
||||||
@@ -677,43 +693,40 @@ build_image() {
|
|||||||
echo "Latest: $latest" | tee -a "$logfile"
|
echo "Latest: $latest" | tee -a "$logfile"
|
||||||
echo "====================================" | tee -a "$logfile"
|
echo "====================================" | tee -a "$logfile"
|
||||||
|
|
||||||
# Architekturen-Array vorbereiten
|
# ---- Plattformen vorbereiten ----
|
||||||
load_project_config "$project"
|
local platforms arch_array
|
||||||
|
read -r -a arch_array <<< "${architectures//,/ }"
|
||||||
local platforms=""
|
|
||||||
local arch_array=()
|
|
||||||
# Split nach Leerzeichen
|
|
||||||
read -r -a arch_array <<< "$architectures"
|
|
||||||
|
|
||||||
|
platforms=""
|
||||||
for arch in "${arch_array[@]}"; do
|
for arch in "${arch_array[@]}"; do
|
||||||
case "$arch" in
|
case "$arch" in
|
||||||
amd64) platforms+="linux/amd64," ;;
|
amd64) platforms+="linux/amd64," ;;
|
||||||
arm64) platforms+="linux/arm64," ;;
|
arm64) platforms+="linux/arm64," ;;
|
||||||
armhf) platforms+="linux/arm/v7," ;;
|
armhf) platforms+="linux/arm/v7," ;;
|
||||||
x86) platforms+="linux/386," ;;
|
x86) platforms+="linux/386," ;;
|
||||||
*) echo "WARNUNG: Unbekannte Architektur '$arch' wird ignoriert." ;;
|
*) echo "WARNUNG: Unbekannte Architektur '$arch' wird ignoriert." | tee -a "$logfile" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
platforms="${platforms%,}" # letztes Komma entfernen
|
||||||
platforms="${platforms%,}"
|
|
||||||
|
|
||||||
echo "DEBUG platforms='$platforms'" | tee -a "$logfile"
|
|
||||||
|
|
||||||
if [[ -z "$platforms" ]]; then
|
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
|
return 1
|
||||||
fi
|
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"
|
IFS=',' read -ra reg_array <<< "$registry"
|
||||||
tags=()
|
tags=()
|
||||||
for reg in "${reg_array[@]}"; do
|
for reg in "${reg_array[@]}"; do
|
||||||
reg=$(echo "$reg" | xargs) # trim
|
reg=$(echo "$reg" | xargs) # trim
|
||||||
[[ -z "$reg" ]] && continue
|
[[ -z "$reg" ]] && continue
|
||||||
|
|
||||||
# Docker-Login für Registry (falls Config vorhanden)
|
# Login falls Registry-Config existiert
|
||||||
reg_config="$CONFIG_DIR/registries/$reg/config-file"
|
local reg_config="$REGISTRY_CONFIG_DIR/$reg/config-file"
|
||||||
if [[ -f "$reg_config" ]]; then
|
if [[ -f "$reg_config" ]]; then
|
||||||
|
local reg_user reg_pass
|
||||||
reg_user=$(grep "^username=" "$reg_config" | cut -d= -f2)
|
reg_user=$(grep "^username=" "$reg_config" | cut -d= -f2)
|
||||||
reg_pass=$(grep "^password=" "$reg_config" | cut -d= -f2)
|
reg_pass=$(grep "^password=" "$reg_config" | cut -d= -f2)
|
||||||
if [[ -n "$reg_user" && -n "$reg_pass" ]]; then
|
if [[ -n "$reg_user" && -n "$reg_pass" ]]; then
|
||||||
@@ -724,9 +737,7 @@ build_image() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
tags+=("-t" "$reg/$image_name:$version")
|
tags+=("-t" "$reg/$image_name:$version")
|
||||||
if [[ "$latest" == "yes" ]]; then
|
[[ "$latest" == "yes" ]] && tags+=("-t" "$reg/$image_name:latest")
|
||||||
tags+=("-t" "$reg/$image_name:latest")
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ ${#tags[@]} -eq 0 ]]; then
|
if [[ ${#tags[@]} -eq 0 ]]; then
|
||||||
@@ -734,21 +745,23 @@ build_image() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Build-Befehl zusammenbauen
|
# ---- Docker Build-Befehl ----
|
||||||
|
local cmd
|
||||||
if [[ "$push" == "yes" ]]; then
|
if [[ "$push" == "yes" ]]; then
|
||||||
cmd=(docker buildx build --platform "$platforms" "${tags[@]}" "$PROJECTS_DIR/$project" --push)
|
cmd=(docker buildx build --platform "$platforms" "${tags[@]}" "$PROJECTS_DIR/$project" --push)
|
||||||
else
|
else
|
||||||
cmd=(docker buildx build --platform "$platforms" "${tags[@]}" "$PROJECTS_DIR/$project" --load)
|
cmd=(docker buildx build --platform "$platforms" "${tags[@]}" "$PROJECTS_DIR/$project" --load)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${cmd[*]}" | tee -a "$logfile"
|
echo "Build-Befehl: ${cmd[*]}" | tee -a "$logfile"
|
||||||
|
|
||||||
|
# ---- Build ausführen ----
|
||||||
if "${cmd[@]}" >>"$logfile" 2>&1; then
|
if "${cmd[@]}" >>"$logfile" 2>&1; then
|
||||||
echo "==== Build beendet: $(date) ====" | tee -a "$logfile"
|
echo "==== Build beendet: $(date) ====" | tee -a "$logfile"
|
||||||
|
|
||||||
# Auto-Subversion
|
# Auto-Subversion erhöhen
|
||||||
if [[ "$auto_subversion" == "yes" ]]; then
|
if [[ "$auto_subversion" == "yes" ]]; then
|
||||||
local major minor
|
local major minor new_version
|
||||||
major=$(echo "$version" | cut -d. -f1)
|
major=$(echo "$version" | cut -d. -f1)
|
||||||
minor=$(echo "$version" | cut -d. -f2)
|
minor=$(echo "$version" | cut -d. -f2)
|
||||||
minor=$((minor + 1))
|
minor=$((minor + 1))
|
||||||
@@ -758,6 +771,7 @@ build_image() {
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "==== Build fehlgeschlagen: $(date) ====" | tee -a "$logfile"
|
echo "==== Build fehlgeschlagen: $(date) ====" | tee -a "$logfile"
|
||||||
|
whiptail --msgbox "Build für Projekt $project fehlgeschlagen. Details im Log: $logfile" 10 70
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user