rewrite function build_image
This commit is contained in:
@@ -613,82 +613,80 @@ load_project_config() {
|
|||||||
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"
|
||||||
|
local project_dir="$PROJECTS_DIR/$project"
|
||||||
|
|
||||||
|
# Projekt-Konfiguration laden
|
||||||
load_project_config "$config_file"
|
load_project_config "$config_file"
|
||||||
|
|
||||||
# Logs-Verzeichnis
|
# Logs-Verzeichnis prüfen
|
||||||
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"
|
||||||
|
|
||||||
echo "==== Build gestartet: $(date) ====" | tee -a "$logfile"
|
echo "==== Build gestartet: $(date) ====" >> "$logfile"
|
||||||
echo "Projekt: $project" | tee -a "$logfile"
|
echo "Projekt: $project" >> "$logfile"
|
||||||
echo "Registries: $registry" | tee -a "$logfile"
|
echo "Registries: ${regs[*]}" >> "$logfile"
|
||||||
echo "Image: $image_name" | tee -a "$logfile"
|
echo "Image: $image_name" >> "$logfile"
|
||||||
echo "Architekturen: $architectures" | tee -a "$logfile"
|
echo "Architekturen: $architectures" >> "$logfile"
|
||||||
echo "Push: $push" | tee -a "$logfile"
|
echo "Push: $push" >> "$logfile"
|
||||||
echo "Version: $version" | tee -a "$logfile"
|
echo "Version: $version" >> "$logfile"
|
||||||
echo "Latest: $latest" | tee -a "$logfile"
|
echo "Latest: $latest" >> "$logfile"
|
||||||
echo "====================================" | tee -a "$logfile"
|
echo "====================================" >> "$logfile"
|
||||||
|
|
||||||
# Plattformen für Buildx
|
# Plattformen korrekt für buildx
|
||||||
local platforms
|
local platforms
|
||||||
IFS=' ' read -ra archs <<< "$architectures"
|
platforms=$(echo "$architectures" | sed 's/ /,linux\//g')
|
||||||
platforms=$(printf "linux/%s," "${archs[@]}")
|
platforms="linux/$platforms"
|
||||||
platforms="${platforms%,}" # letztes Komma entfernen
|
|
||||||
|
|
||||||
# Tags vorbereiten
|
# Tags vorbereiten
|
||||||
local tags=()
|
local tags=()
|
||||||
for reg in "${regs[@]}"; do
|
for reg in "${regs[@]}"; do
|
||||||
|
# Key=Value Datei einlesen
|
||||||
source "$CONFIG_DIR/registries/$reg/config-file"
|
source "$CONFIG_DIR/registries/$reg/config-file"
|
||||||
tags+=("-t" "${url}/${image_name}:${version}")
|
tags+=("-t" "${url}/${image_name}:${version}")
|
||||||
[[ "$latest" == "yes" ]] && tags+=("-t" "${url}/${image_name}:latest")
|
[[ "$latest" == "yes" ]] && tags+=("-t" "${url}/${image_name}:latest")
|
||||||
done
|
done
|
||||||
|
|
||||||
# Login zu allen Registries falls push=yes
|
# Push-Option
|
||||||
|
local push_flag=""
|
||||||
if [[ "$push" == "yes" ]]; then
|
if [[ "$push" == "yes" ]]; then
|
||||||
|
push_flag="--push"
|
||||||
|
# Login zu allen Registries
|
||||||
for reg in "${regs[@]}"; do
|
for reg in "${regs[@]}"; do
|
||||||
local url username password
|
|
||||||
# key=value Datei einlesen
|
|
||||||
source "$CONFIG_DIR/registries/$reg/config-file"
|
source "$CONFIG_DIR/registries/$reg/config-file"
|
||||||
# url, username, password stehen jetzt als Variablen zur Verfügung
|
|
||||||
if [[ -n "$username" && -n "$password" ]]; then
|
if [[ -n "$username" && -n "$password" ]]; then
|
||||||
docker login "$url" -u "$username" -p "$password" &>> "$logfile"
|
docker login "$url" -u "$username" -p "$password" &>> "$logfile"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Build-Befehl
|
# Build starten
|
||||||
local build_cmd
|
{
|
||||||
build_cmd="docker buildx build --platform $platforms ${tags[*]} ./projects/$project"
|
docker buildx build --platform "$platforms" "$project_dir" "${tags[@]}" $push_flag
|
||||||
if [[ "$push" == "yes" ]]; then
|
} &>> "$logfile"
|
||||||
build_cmd+=" --push"
|
|
||||||
else
|
|
||||||
# nur erste Plattform lokal laden
|
|
||||||
build_cmd+=" --load --platform linux/${archs[0]}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Build ausführen
|
if [[ $? -eq 0 ]]; then
|
||||||
if $build_cmd 2>&1 | tee -a "$logfile"; then
|
echo "==== Build beendet: $(date) ====" >> "$logfile"
|
||||||
echo "==== Build beendet: $(date) ====" | tee -a "$logfile"
|
|
||||||
# Subversion erhöhen, falls auto_subversion=yes
|
# Auto Subversion erhöhen
|
||||||
|
local auto_subversion
|
||||||
|
auto_subversion=$(grep "^auto_subversion=" "$config_file" | cut -d= -f2)
|
||||||
if [[ "$auto_subversion" == "yes" ]]; then
|
if [[ "$auto_subversion" == "yes" ]]; then
|
||||||
local major minor
|
IFS='.' read -r major minor <<< "$version"
|
||||||
major=${version%%.*}
|
|
||||||
minor=${version##*.}
|
|
||||||
minor=$((minor+1))
|
minor=$((minor+1))
|
||||||
new_version="$major.$minor"
|
version="${major}.${minor}"
|
||||||
sed -i "s|^version=.*|version=$new_version|" "$config_file"
|
sed -i "s|^version=.*|version=$version|" "$config_file"
|
||||||
echo "Subversion automatisch auf $new_version erhöht." | tee -a "$logfile"
|
echo "Subversion automatisch auf $version erhöht." >> "$logfile"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
whiptail --msgbox "Build erfolgreich! Log: $logfile" 10 70
|
||||||
else
|
else
|
||||||
echo "==== Build fehlgeschlagen: $(date) ====" | tee -a "$logfile"
|
echo "==== Build fehlgeschlagen: $(date) ====" >> "$logfile"
|
||||||
|
whiptail --msgbox "Build fehlgeschlagen! Log: $logfile" 10 70
|
||||||
fi
|
fi
|
||||||
|
|
||||||
whiptail --msgbox "Build abgeschlossen. Log-Datei: $logfile" 10 60
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Logs ansehen (optional gefiltert nach Projekt)
|
# Logs ansehen (optional gefiltert nach Projekt)
|
||||||
view_logs() {
|
view_logs() {
|
||||||
#ensure_logs_dir
|
#ensure_logs_dir
|
||||||
|
|||||||
Reference in New Issue
Block a user