edit functions
This commit is contained in:
@@ -613,20 +613,27 @@ 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 prüfen
|
# Build-Parameter aus Config
|
||||||
mkdir -p "$LOGS_DIR"
|
local regs=()
|
||||||
local timestamp
|
IFS=',' read -r -a regs <<< "$registry" # Registries als Array
|
||||||
timestamp=$(date +"%Y%m%d_%H%M%S")
|
local tags=()
|
||||||
local logfile="$LOGS_DIR/${project}_${timestamp}.log"
|
for r in "${regs[@]}"; do
|
||||||
|
[[ -n "$r" ]] && tags+=("-t $r/$image_name:$version")
|
||||||
|
done
|
||||||
|
|
||||||
echo "==== Build gestartet: $(date) ====" >> "$logfile"
|
local archs
|
||||||
|
archs=$(echo "$architectures" | sed 's/ /,/g')
|
||||||
|
|
||||||
|
local push_flag=""
|
||||||
|
[[ "$push" == "yes" ]] && push_flag="--push"
|
||||||
|
|
||||||
|
local logfile="$LOGS_DIR/${project}_$(date +"%Y%m%d_%H%M%S").log"
|
||||||
|
|
||||||
|
echo "==== Build gestartet: $(date) ====" > "$logfile"
|
||||||
echo "Projekt: $project" >> "$logfile"
|
echo "Projekt: $project" >> "$logfile"
|
||||||
echo "Registries: ${regs[*]}" >> "$logfile"
|
echo "Registries: ${registry}" >> "$logfile"
|
||||||
echo "Image: $image_name" >> "$logfile"
|
echo "Image: $image_name" >> "$logfile"
|
||||||
echo "Architekturen: $architectures" >> "$logfile"
|
echo "Architekturen: $architectures" >> "$logfile"
|
||||||
echo "Push: $push" >> "$logfile"
|
echo "Push: $push" >> "$logfile"
|
||||||
@@ -634,59 +641,39 @@ build_image() {
|
|||||||
echo "Latest: $latest" >> "$logfile"
|
echo "Latest: $latest" >> "$logfile"
|
||||||
echo "====================================" >> "$logfile"
|
echo "====================================" >> "$logfile"
|
||||||
|
|
||||||
# Plattformen korrekt für buildx
|
|
||||||
local platforms
|
|
||||||
platforms=$(echo "$architectures" | sed 's/ /,linux\//g')
|
|
||||||
platforms="linux/$platforms"
|
|
||||||
|
|
||||||
# Tags vorbereiten
|
|
||||||
local tags=()
|
|
||||||
for reg in "${regs[@]}"; do
|
|
||||||
# Key=Value Datei einlesen
|
|
||||||
source "$CONFIG_DIR/registries/$reg/config-file"
|
|
||||||
tags+=("-t" "${url}/${image_name}:${version}")
|
|
||||||
[[ "$latest" == "yes" ]] && tags+=("-t" "${url}/${image_name}:latest")
|
|
||||||
done
|
|
||||||
|
|
||||||
# Push-Option
|
|
||||||
local push_flag=""
|
|
||||||
if [[ "$push" == "yes" ]]; then
|
|
||||||
push_flag="--push"
|
|
||||||
# Login zu allen Registries
|
|
||||||
for reg in "${regs[@]}"; do
|
|
||||||
source "$CONFIG_DIR/registries/$reg/config-file"
|
|
||||||
if [[ -n "$username" && -n "$password" ]]; then
|
|
||||||
docker login "$url" -u "$username" -p "$password" &>> "$logfile"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Build starten
|
# Build starten
|
||||||
{
|
local build_cmd
|
||||||
docker buildx build --platform "$platforms" "$project_dir" "${tags[@]}" $push_flag
|
build_cmd="docker buildx build --platform linux/$archs ${tags[*]} ./projects/$project $push_flag"
|
||||||
} &>> "$logfile"
|
echo "$build_cmd" >> "$logfile"
|
||||||
|
|
||||||
if [[ $? -eq 0 ]]; then
|
if $build_cmd >> "$logfile" 2>&1; then
|
||||||
echo "==== Build beendet: $(date) ====" >> "$logfile"
|
echo "==== Build beendet: $(date) ====" >> "$logfile"
|
||||||
|
|
||||||
# Auto Subversion erhöhen
|
# Latest-Tag setzen
|
||||||
local auto_subversion
|
if [[ "$latest" == "yes" ]]; then
|
||||||
auto_subversion=$(grep "^auto_subversion=" "$config_file" | cut -d= -f2)
|
for r in "${regs[@]}"; do
|
||||||
if [[ "$auto_subversion" == "yes" ]]; then
|
[[ -n "$r" ]] && docker tag "$r/$image_name:$version" "$r/$image_name:latest" >> "$logfile" 2>&1
|
||||||
IFS='.' read -r major minor <<< "$version"
|
done
|
||||||
minor=$((minor+1))
|
fi
|
||||||
version="${major}.${minor}"
|
|
||||||
|
# Subversion erhöhen
|
||||||
|
if grep -q "^auto_subversion=yes" "$config_file"; then
|
||||||
|
local main_ver sub_ver
|
||||||
|
main_ver=$(echo "$version" | cut -d. -f1)
|
||||||
|
sub_ver=$(echo "$version" | cut -d. -f2)
|
||||||
|
sub_ver=$((sub_ver+1))
|
||||||
|
version="$main_ver.$sub_ver"
|
||||||
sed -i "s|^version=.*|version=$version|" "$config_file"
|
sed -i "s|^version=.*|version=$version|" "$config_file"
|
||||||
echo "Subversion automatisch auf $version erhöht." >> "$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) ====" >> "$logfile"
|
echo "==== Build fehlgeschlagen: $(date) ====" >> "$logfile"
|
||||||
whiptail --msgbox "Build fehlgeschlagen! Log: $logfile" 10 70
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
whiptail --msgbox "Build beendet. Log-Datei: $logfile" 15 70
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Logs ansehen (optional gefiltert nach Projekt)
|
# Logs ansehen (optional gefiltert nach Projekt)
|
||||||
view_logs() {
|
view_logs() {
|
||||||
#ensure_logs_dir
|
#ensure_logs_dir
|
||||||
@@ -713,14 +700,19 @@ view_logs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Projektübersicht anzeigen
|
# Projektübersicht anzeigen
|
||||||
|
# Projektübersicht mit Aktionen
|
||||||
project_overview() {
|
project_overview() {
|
||||||
local project=$1
|
local project=$1
|
||||||
local config_file="$PROJECT_CONFIG_DIR/$project/config-file"
|
local config_file="$PROJECT_CONFIG_DIR/$project/config-file"
|
||||||
load_project_config "$config_file"
|
load_project_config "$config_file"
|
||||||
|
|
||||||
|
# Registries als Array
|
||||||
|
IFS=' ' read -r -a regs <<< "$registry"
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
choice=$(whiptail --title "Projektübersicht: $project" --menu "Parameter:" 20 70 10 \
|
local choice
|
||||||
"1" "Registry: $registry" \
|
choice=$(whiptail --title "Projektübersicht: $project" --menu "Parameter:" 20 70 12 \
|
||||||
|
"1" "Registries: ${registry}" \
|
||||||
"2" "Image-Name: $image_name" \
|
"2" "Image-Name: $image_name" \
|
||||||
"3" "Architekturen: $architectures" \
|
"3" "Architekturen: $architectures" \
|
||||||
"4" "Push: $push" \
|
"4" "Push: $push" \
|
||||||
@@ -729,16 +721,16 @@ project_overview() {
|
|||||||
"7" "Git-Repo: $git_repo" \
|
"7" "Git-Repo: $git_repo" \
|
||||||
"B" "Bauen" \
|
"B" "Bauen" \
|
||||||
"E" "Bearbeiten" \
|
"E" "Bearbeiten" \
|
||||||
"P" "Projektauswahl" \
|
"P" "Projektauswahl wechseln" \
|
||||||
"L" "Logs ansehen" \
|
"L" "Logs ansehen" \
|
||||||
"Z" "Zurück" \
|
"Z" "Zurück" \
|
||||||
3>&1 1>&2 2>&3) || return
|
3>&1 1>&2 2>&3) || return
|
||||||
|
|
||||||
case $choice in
|
case $choice in
|
||||||
B) build_image "$project" ;;
|
B) build_image "$project" ;;
|
||||||
E) edit_project "$project" ;; # Reuse aus Projektverwaltung
|
E) edit_project "$project" ;; # Bearbeitungsmenü für das Projekt
|
||||||
P) select_project_for_build ;;
|
P) return ;; # zurück zur Projektauswahl
|
||||||
L) view_logs "$project" ;;
|
L) view_logs ;;
|
||||||
Z) return ;;
|
Z) return ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@@ -746,16 +738,23 @@ project_overview() {
|
|||||||
|
|
||||||
# Projektauswahl für Image-Bauen
|
# Projektauswahl für Image-Bauen
|
||||||
select_project_for_build() {
|
select_project_for_build() {
|
||||||
local projects=($(ls "$PROJECT_CONFIG_DIR"))
|
local projects
|
||||||
[ ${#projects[@]} -eq 0 ] && { whiptail --msgbox "Keine Projekte vorhanden." 10 60; return; }
|
projects=$(ls "$PROJECT_CONFIG_DIR" 2>/dev/null)
|
||||||
|
[ -z "$projects" ] && { whiptail --msgbox "Keine Projekte vorhanden." 10 60; return; }
|
||||||
|
|
||||||
menu_list=()
|
# Projekte für Menü vorbereiten (1-Spalte)
|
||||||
for p in "${projects[@]}"; do
|
local menu_list=()
|
||||||
menu_list+=("$p" "Projekt")
|
for p in $projects; do
|
||||||
|
menu_list+=("$p" "")
|
||||||
done
|
done
|
||||||
|
|
||||||
project=$(whiptail --title "Projekt auswählen" --menu "Bitte Projekt auswählen:" 20 60 10 "${menu_list[@]}" 3>&1 1>&2 2>&3) || return
|
while true; do
|
||||||
|
local project
|
||||||
|
project=$(whiptail --title "Projekt auswählen" --menu "Projekt für Build auswählen:" 20 60 10 "${menu_list[@]}" 3>&1 1>&2 2>&3) || return
|
||||||
|
|
||||||
|
# Projektübersicht anzeigen
|
||||||
project_overview "$project"
|
project_overview "$project"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Menüpunkt im Hauptmenü
|
# Menüpunkt im Hauptmenü
|
||||||
|
|||||||
Reference in New Issue
Block a user