diff --git a/scripts/image-builder.sh b/scripts/image-builder.sh index 4506075..d243aa4 100755 --- a/scripts/image-builder.sh +++ b/scripts/image-builder.sh @@ -609,15 +609,38 @@ load_project_config() { auto_subversion=$(grep "^auto_subversion=" "$config_file" | cut -d= -f2 || echo "no") } -# Registry-URL auslesen +# Gibt die URL einer Registry anhand des Config-Files zurück get_registry_url() { - local reg_name=$1 - local reg_file="$REGISTRY_CONFIG_DIR/$reg_name/config-file" - if [[ -f "$reg_file" ]]; then - grep '^url=' "$reg_file" | cut -d= -f2 - else - echo "$reg_name" + local reg=$1 + local reg_file="$REGISTRY_CONFIG_DIR/$reg.conf" + if [[ ! -f "$reg_file" ]]; then + echo "" + return fi + grep -E '^url=' "$reg_file" | cut -d'=' -f2- +} + +# Führt docker login für eine Registry anhand des Config-Files aus +registry_login() { + local reg=$1 + local reg_file="$REGISTRY_CONFIG_DIR/$reg.conf" + + if [[ ! -f "$reg_file" ]]; then + echo "Registry-Konfiguration '$reg' fehlt!" + return 1 + fi + + local url username password + url=$(grep -E '^url=' "$reg_file" | cut -d'=' -f2-) + username=$(grep -E '^username=' "$reg_file" | cut -d'=' -f2-) + password=$(grep -E '^password=' "$reg_file" | cut -d'=' -f2-) + + if [[ -z "$url" || -z "$username" || -z "$password" ]]; then + echo "Ungültige Registry-Konfig für $reg (url/username/password fehlt)!" + return 1 + fi + + echo "$password" | docker login "$url" -u "$username" --password-stdin } # Image bauen @@ -687,6 +710,15 @@ build_image() { build_cmd+=(--load) fi + # Docker Login für jede Registry durchführen + for reg in $registry; do + if ! registry_login "$reg" >> "$logfile" 2>&1; then + echo "Login bei Registry '$reg' fehlgeschlagen!" >> "$logfile" + whiptail --msgbox "Login bei Registry '$reg' fehlgeschlagen! Build abgebrochen." 10 70 + return + fi + done + # Log-Ausgabe echo "${build_cmd[*]}" >> "$logfile"