edit function build_image

This commit is contained in:
2025-09-27 20:34:25 +02:00
parent cc71689b27
commit c8f7dc9827

View File

@@ -598,35 +598,30 @@ EOF
# Projektparameter laden # Projektparameter laden
load_project_config() { load_project_config() {
local config_file=$1 local config_file="$1"
registry=$(grep "^registry=" "$config_file" | cut -d= -f2) registry=$(grep "^registry=" "$config_file" | cut -d= -f2)
image_name=$(grep "^image_name=" "$config_file" | cut -d= -f2) image_name=$(grep "^image_name=" "$config_file" | cut -d= -f2)
architectures=$(grep "^architectures=" "$config_file" | cut -d= -f2) architectures=$(grep "^architectures=" "$config_file" | cut -d= -f2)
push=$(grep "^push=" "$config_file" | cut -d= -f2) push=$(grep "^push=" "$config_file" | cut -d= -f2)
version=$(grep "^version=" "$config_file" | cut -d= -f2) version=$(grep "^version=" "$config_file" | cut -d= -f2)
latest=$(grep "^latest=" "$config_file" | cut -d= -f2) latest=$(grep "^latest=" "$config_file" | cut -d= -f2)
auto_increment=$(grep "^auto_increment=" "$config_file" | cut -d= -f2 2>/dev/null || echo "no")
git_repo=$(grep "^git_repo=" "$config_file" | cut -d= -f2) git_repo=$(grep "^git_repo=" "$config_file" | cut -d= -f2)
auto_subversion=$(grep "^auto_subversion=" "$config_file" | cut -d= -f2 || echo "no")
} }
# Image bauen
# Image bauen # Image bauen
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"
load_project_config "$config_file" load_project_config "$config_file"
local tags="-t $registry/$image_name:$version" ensure_logs_dir
[ "$latest" = "yes" ] && tags="$tags -t $registry/$image_name:latest"
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"
whiptail --msgbox "Starte Build:\n\nProjekt: $project\nRegistry: $registry\nImage: $image_name\nArchitekturen: $architectures\nPush: $push\nVersion: $version\nTags: $tags\n\nBuild-Log: $logfile" 20 70
# Build ausführen und alles ins Log schreiben
{ {
echo "==== Build gestartet: $(date) ====" echo "==== Build gestartet: $(date) ===="
echo "Projekt: $project" echo "Projekt: $project"
@@ -635,30 +630,50 @@ build_image() {
echo "Architekturen: $architectures" echo "Architekturen: $architectures"
echo "Push: $push" echo "Push: $push"
echo "Version: $version" echo "Version: $version"
echo "Tags: $tags" echo "Latest-Tag: $latest"
echo "====================================" echo "===================================="
docker buildx build --platform "$architectures" $tags "$project_dir" $( [ "$push" = "yes" ] && echo "--push" ) } | tee "$logfile"
echo "==== Build abgeschlossen: $(date) ===="
} &> "$logfile"
# Version hochzählen falls auto_increment aktiv # Architekturen in Buildx-Format umwandeln (linux/arch, getrennt durch Komma)
if [ "$auto_increment" = "yes" ]; then local platforms
base=$(echo "$version" | cut -d. -f1) platforms=$(echo "$architectures" | xargs -n1 | sed 's|^|linux/|' | paste -sd, -)
sub=$(echo "$version" | cut -d. -f2)
new_sub=$((sub+1))
new_version="$base.$new_sub"
sed -i "s|^version=.*|version=$new_version|" "$config_file"
fi
# Nachfrage, ob Log angezeigt werden soll # Tags aufbauen
if whiptail --yesno "Build abgeschlossen!\n\nMöchten Sie die Logdatei jetzt ansehen?\n\n$logfile" 15 70; then local tags=()
EDITOR_CMD=$(get_editor_cmd) IFS=',' read -ra regs <<< "$registry"
$EDITOR_CMD "$logfile" for reg in "${regs[@]}"; do
else tags+=("-t" "${reg}/${image_name}:${version}")
whiptail --msgbox "Build abgeschlossen!\n\nLogdatei: $logfile" 12 70 if [[ "$latest" == "yes" ]]; then
tags+=("-t" "${reg}/${image_name}:latest")
fi
done
# Push-Flag
local push_flag=""
[[ "$push" == "yes" ]] && push_flag="--push"
{
docker buildx build \
--platform "$platforms" \
"${tags[@]}" \
"$PROJECTS_DIR/$project" \
$push_flag
} 2>&1 | tee -a "$logfile"
echo "==== Build beendet: $(date) ====" | tee -a "$logfile"
# Auto-Subversion
if [[ "$auto_subversion" == "yes" ]]; then
local major minor
major=$(echo "$version" | cut -d. -f1)
minor=$(echo "$version" | cut -d. -f2)
minor=$((minor + 1))
sed -i "s/^version=.*/version=${major}.${minor}/" "$config_file"
echo "Subversion automatisch auf ${major}.${minor} erhöht." | tee -a "$logfile"
fi fi
} }
# Logs ansehen (optional gefiltert nach Projekt) # Logs ansehen (optional gefiltert nach Projekt)
view_logs() { view_logs() {
ensure_logs_dir ensure_logs_dir