edit function create_project to use default registry
This commit is contained in:
@@ -52,6 +52,7 @@ config_menu() {
|
|||||||
1 "Abhängigkeiten installieren (docker, git, jq, whiptail)" \
|
1 "Abhängigkeiten installieren (docker, git, jq, whiptail)" \
|
||||||
2 "Buildx-Builder einrichten | Status: $builder_icon" \
|
2 "Buildx-Builder einrichten | Status: $builder_icon" \
|
||||||
3 "Globalen Editor setzen" \
|
3 "Globalen Editor setzen" \
|
||||||
|
4 "Standard-Registry setzen" \
|
||||||
0 "Zurück" \
|
0 "Zurück" \
|
||||||
3>&1 1>&2 2>&3) || return
|
3>&1 1>&2 2>&3) || return
|
||||||
|
|
||||||
@@ -59,11 +60,13 @@ config_menu() {
|
|||||||
1) install_dependencies;;
|
1) install_dependencies;;
|
||||||
2) install_docker_and_buildx;;
|
2) install_docker_and_buildx;;
|
||||||
3) set_editor;;
|
3) set_editor;;
|
||||||
|
4) set_default_registry ;;
|
||||||
0) return;;
|
0) return;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# BuildX-Builder Status Icon
|
||||||
get_builder_status_icon() {
|
get_builder_status_icon() {
|
||||||
if docker buildx ls 2>/dev/null | grep -q "multiarch-builder"; then
|
if docker buildx ls 2>/dev/null | grep -q "multiarch-builder"; then
|
||||||
if docker buildx ls | grep "multiarch-builder" | grep -q "running"; then
|
if docker buildx ls | grep "multiarch-builder" | grep -q "running"; then
|
||||||
@@ -76,6 +79,7 @@ get_builder_status_icon() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# BuildX-Builder-Status abrufen
|
||||||
get_builder_status() {
|
get_builder_status() {
|
||||||
if docker buildx ls 2>/dev/null | grep -q "multiarch-builder"; then
|
if docker buildx ls 2>/dev/null | grep -q "multiarch-builder"; then
|
||||||
if docker buildx ls | grep "multiarch-builder" | grep -q "running"; then
|
if docker buildx ls | grep "multiarch-builder" | grep -q "running"; then
|
||||||
@@ -88,12 +92,14 @@ get_builder_status() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Abhängigkeiten installieren
|
||||||
install_dependencies() {
|
install_dependencies() {
|
||||||
whiptail --msgbox "Installation von Abhängigkeiten (Beispiel für Debian/Ubuntu). Bitte root-Rechte eingeben." 10 70
|
whiptail --msgbox "Installation von Abhängigkeiten (Beispiel für Debian/Ubuntu). Bitte root-Rechte eingeben." 10 70
|
||||||
sudo apt update
|
sudo apt update
|
||||||
sudo apt install -y docker.io git jq whiptail micro
|
sudo apt install -y docker.io git jq whiptail micro
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# BuildX-Builder einrichten
|
||||||
install_docker_and_buildx() {
|
install_docker_and_buildx() {
|
||||||
# Prüfen ob Docker installiert ist
|
# Prüfen ob Docker installiert ist
|
||||||
if ! command -v docker >/dev/null 2>&1; then
|
if ! command -v docker >/dev/null 2>&1; then
|
||||||
@@ -126,6 +132,7 @@ install_docker_and_buildx() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Standard Editor setzen
|
||||||
set_editor() {
|
set_editor() {
|
||||||
# editor -> paketname
|
# editor -> paketname
|
||||||
declare -A editor_pkg
|
declare -A editor_pkg
|
||||||
@@ -188,7 +195,43 @@ set_editor() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Standard-Registry setzen
|
||||||
|
set_default_registry() {
|
||||||
|
# Alle verfügbaren Registries auslesen
|
||||||
|
local registries
|
||||||
|
registries=$(ls "$REGISTRY_CONFIG_DIR" 2>/dev/null)
|
||||||
|
[ -z "$registries" ] && { whiptail --msgbox "Keine Registries verfügbar. Bitte zuerst eine Registry erstellen." 10 60; return; }
|
||||||
|
|
||||||
|
# Menü-Liste vorbereiten
|
||||||
|
local menu_list=()
|
||||||
|
for r in $registries; do
|
||||||
|
menu_list+=("$r" "$r")
|
||||||
|
done
|
||||||
|
|
||||||
|
# Aktuelle Default-Registry auslesen
|
||||||
|
local current
|
||||||
|
current=$(jq -r '.default_registry // ""' "$GLOBAL_CONFIG")
|
||||||
|
|
||||||
|
# Auswahl per Whiptail
|
||||||
|
local choice
|
||||||
|
choice=$(whiptail --title "Standard-Registry wählen" \
|
||||||
|
--menu "Bitte Standard-Registry auswählen:" 20 70 10 \
|
||||||
|
"${menu_list[@]}" 3>&1 1>&2 2>&3) || return
|
||||||
|
|
||||||
|
# Speichern in global/config.json
|
||||||
|
jq --arg reg "$choice" '.default_registry = $reg' "$GLOBAL_CONFIG" >"$GLOBAL_CONFIG.tmp" && mv "$GLOBAL_CONFIG.tmp" "$GLOBAL_CONFIG"
|
||||||
|
|
||||||
|
whiptail --msgbox "Standard-Registry auf '$choice' gesetzt." 10 60
|
||||||
|
}
|
||||||
|
|
||||||
|
# Standard-Registry auslesen
|
||||||
|
get_default_registry() {
|
||||||
|
if [[ -f "$GLOBAL_CONFIG" ]]; then
|
||||||
|
jq -r '.default_registry // ""' "$GLOBAL_CONFIG"
|
||||||
|
else
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
}
|
||||||
# ===============================
|
# ===============================
|
||||||
# Projektverwaltung
|
# Projektverwaltung
|
||||||
# ===============================
|
# ===============================
|
||||||
@@ -219,15 +262,19 @@ create_project() {
|
|||||||
|
|
||||||
mkdir -p "$PROJECT_CONFIG_DIR/$project_name" "$PROJECTS_DIR/$project_name"
|
mkdir -p "$PROJECT_CONFIG_DIR/$project_name" "$PROJECTS_DIR/$project_name"
|
||||||
|
|
||||||
|
# Standardwerte setzen
|
||||||
|
default_registry=$(get_default_registry)
|
||||||
|
|
||||||
# Default Config-File
|
# Default Config-File
|
||||||
cat > "$PROJECT_CONFIG_DIR/$project_name/config-file" <<EOF
|
cat > "$PROJECT_CONFIG_DIR/$project_name/config-file" <<EOF
|
||||||
# Projektkonfiguration für $project_name
|
# Projektkonfiguration für $project_name
|
||||||
registry=docker.io
|
registry=$default_registry
|
||||||
image_name=$project_name
|
image_name=$project_name
|
||||||
architectures=amd64
|
architectures=amd64
|
||||||
push=yes
|
push=yes
|
||||||
version=1.0
|
version=1.0
|
||||||
latest=yes
|
latest=yes
|
||||||
|
auto_increment=no
|
||||||
git_repo=
|
git_repo=
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@@ -235,14 +282,14 @@ EOF
|
|||||||
if whiptail --yesno "Soll ein Git-Repo geklont werden?" 10 60; then
|
if whiptail --yesno "Soll ein Git-Repo geklont werden?" 10 60; then
|
||||||
repo_url=$(whiptail --inputbox "Git-Repository-URL eingeben:" 10 60 3>&1 1>&2 2>&3) || return
|
repo_url=$(whiptail --inputbox "Git-Repository-URL eingeben:" 10 60 3>&1 1>&2 2>&3) || return
|
||||||
if git clone "$repo_url" "$PROJECTS_DIR/$project_name"; then
|
if git clone "$repo_url" "$PROJECTS_DIR/$project_name"; then
|
||||||
echo "git_repo=$repo_url" >> "$PROJECT_CONFIG_DIR/$project_name/config-file"
|
sed -i "s|^git_repo=.*|git_repo=$repo_url|" "$PROJECT_CONFIG_DIR/$project_name/config-file"
|
||||||
else
|
else
|
||||||
whiptail --msgbox "Fehler beim Klonen des Git-Repos!" 10 60
|
whiptail --msgbox "Fehler beim Klonen des Git-Repos!" 10 60
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo -e "FROM debian:bookworm-slim\nCMD echo 'Hello from $project_name'" > "$PROJECTS_DIR/$project_name/Dockerfile"
|
echo -e "FROM debian:bookworm-slim\nCMD echo 'Hello from $project_name'" > "$PROJECTS_DIR/$project_name/Dockerfile"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
whiptail --msgbox "Projekt $project_name wurde erstellt." 10 60
|
whiptail --msgbox "Projekt $project_name wurde erstellt." 10 60
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,17 +368,24 @@ edit_project_registries() {
|
|||||||
|
|
||||||
# aktuelle registries im Projekt auslesen
|
# aktuelle registries im Projekt auslesen
|
||||||
local current=$(grep "^registry=" "$config_file" 2>/dev/null | cut -d= -f2 | tr ',' ' ')
|
local current=$(grep "^registry=" "$config_file" 2>/dev/null | cut -d= -f2 | tr ',' ' ')
|
||||||
|
|
||||||
# alle registries aus Registry-Verwaltung
|
# alle registries aus Registry-Verwaltung
|
||||||
local all_registries
|
local all_registries
|
||||||
all_registries=$(ls "$REGISTRY_CONFIG_DIR" 2>/dev/null)
|
all_registries=$(ls "$REGISTRY_CONFIG_DIR" 2>/dev/null)
|
||||||
[ -z "$all_registries" ] && { whiptail --msgbox "Keine Registries verfügbar. Bitte zuerst eine Registry erstellen." 10 60; return; }
|
[ -z "$all_registries" ] && { whiptail --msgbox "Keine Registries verfügbar. Bitte zuerst eine Registry erstellen." 10 60; return; }
|
||||||
|
|
||||||
|
# Default-Registry aus globaler Config
|
||||||
|
local default_registry
|
||||||
|
default_registry=$(get_default_registry)
|
||||||
|
|
||||||
# menu_list für whiptail vorbereiten
|
# menu_list für whiptail vorbereiten
|
||||||
local menu_list=()
|
local menu_list=()
|
||||||
for r in $all_registries; do
|
for r in $all_registries; do
|
||||||
if [[ " $current " =~ " $r " ]]; then
|
if [[ " $current " =~ " $r " ]]; then
|
||||||
menu_list+=("$r" "$r" ON)
|
menu_list+=("$r" "$r" ON)
|
||||||
|
elif [[ -z "$current" && "$r" == "$default_registry" ]]; then
|
||||||
|
# Projekt hat noch keine registries, Default wird ON
|
||||||
|
menu_list+=("$r" "$r" ON)
|
||||||
else
|
else
|
||||||
menu_list+=("$r" "$r" OFF)
|
menu_list+=("$r" "$r" OFF)
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user