playbook base initial skeleton
This commit is contained in:
69
justfiles/main.just
Normal file
69
justfiles/main.just
Normal file
@ -0,0 +1,69 @@
|
||||
import? "/etc/self-host-playbook/tiers/core.just"
|
||||
import? "/etc/self-host-playbook/tiers/starter.just"
|
||||
import? "/etc/self-host-playbook/tiers/premium.just"
|
||||
|
||||
@default:
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Function to show the header
|
||||
show_header() {
|
||||
gum style \
|
||||
--foreground 212 --border double --border-foreground 212 \
|
||||
--align center --width 50 --margin "1 2" --padding "1 2" \
|
||||
"🚀 DevOps Control Center 🚀"
|
||||
}
|
||||
|
||||
# Function to create menu items with icons and descriptions
|
||||
create_menu() {
|
||||
echo "📊 Status - Show running docker containers"
|
||||
echo "📝 Logs - View container logs"
|
||||
echo "💾 Disk Usage - Show docker disk usage"
|
||||
echo "🔄 Restart - Restart a specific container"
|
||||
echo "🐳 Update Docker - Update Docker containers"
|
||||
echo "❌ Exit"
|
||||
}
|
||||
|
||||
while true; do
|
||||
clear
|
||||
show_header
|
||||
|
||||
# Show menu and get selection
|
||||
choice=$(create_menu | gum choose --cursor.foreground 212 --selected.foreground 212 --header "Select an action:" --cursor "➜ ")
|
||||
|
||||
# Exit if no selection
|
||||
if [ -z "$choice" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Process selection
|
||||
case $choice in
|
||||
"📊 Status"*)
|
||||
just status
|
||||
;;
|
||||
"📝 Logs"*)
|
||||
just logs
|
||||
;;
|
||||
"🛑 Stop All"*)
|
||||
just docker-stop-all
|
||||
;;
|
||||
"🗑️ Prune"*)
|
||||
just docker-prune
|
||||
;;
|
||||
"💾 Disk Usage"*)
|
||||
just docker-disk
|
||||
;;
|
||||
"🔄 Restart"*)
|
||||
just docker-restart
|
||||
;;
|
||||
"🐳 Update Docker"*)
|
||||
just update-containers
|
||||
;;
|
||||
"❌ Exit")
|
||||
echo "Goodbye! 👋" | gum style --foreground 212
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
# Pause after command execution
|
||||
gum confirm "Press Enter to continue..." --default=true --affirmative "Continue" --negative "Exit" || exit 0
|
||||
done
|
101
justfiles/tiers/core.just
Normal file
101
justfiles/tiers/core.just
Normal file
@ -0,0 +1,101 @@
|
||||
status:
|
||||
#!/usr/bin/env bash
|
||||
gum style --foreground 212 --bold --border normal --align center --width 50 --margin "1 2" "📊 Running Containers"
|
||||
docker ps --format "table {{"{{.Names}}\t{{.Status}}"}}" | gum table
|
||||
|
||||
# Interactive logs viewer with gum
|
||||
logs:
|
||||
#!/usr/bin/env bash
|
||||
gum style --foreground 212 --bold --border normal --align center --width 50 --margin "1 2" "📝 Docker Logs Viewer"
|
||||
|
||||
# Get running container names
|
||||
containers=($(docker ps --format "{{"{{.Names}}"}}"))
|
||||
|
||||
if [ ${#containers[@]} -eq 0 ]; then
|
||||
gum style --foreground 1 "⚠️ No running containers found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Select container using gum choose
|
||||
container=$(printf "%s\n" "${containers[@]}" | gum choose --header "Select a container:" --cursor.foreground 212)
|
||||
|
||||
if [ -z "$container" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Select number of lines using gum choose
|
||||
lines=$(gum choose --header "Select number of log lines:" --cursor.foreground 212 \
|
||||
"5 lines" "10 lines" "25 lines" "50 lines" "100 lines" "200 lines")
|
||||
|
||||
if [ -z "$lines" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Extract number from selection
|
||||
lines=${lines%% *}
|
||||
|
||||
# Show spinner while fetching logs
|
||||
gum spin --spinner dot --title "Fetching logs..." -- sleep 1
|
||||
|
||||
# Show logs
|
||||
docker logs "$container" 2>&1 | tail -n "$lines" | gum pager
|
||||
|
||||
docker-disk:
|
||||
#!/usr/bin/env bash
|
||||
gum style --foreground 212 --bold --border normal --align center --width 50 --margin "1 2" "💾 Docker Disk Usage"
|
||||
docker system df | gum table
|
||||
|
||||
docker-restart:
|
||||
#!/usr/bin/env bash
|
||||
containers=($(docker ps --format "{{"{{.Names}}"}}"))
|
||||
if [ ${#containers[@]} -eq 0 ]; then
|
||||
gum style --foreground 1 "⚠️ No running containers found"
|
||||
exit 1
|
||||
fi
|
||||
container=$(printf "%s\n" "${containers[@]}" | gum choose --header "Select a container to restart:" --cursor.foreground 212)
|
||||
if [ -n "$container" ]; then
|
||||
gum spin --spinner dot --title "Restarting $container..." -- docker restart "$container"
|
||||
gum style --foreground 212 "✅ Container $container restarted successfully!"
|
||||
fi
|
||||
|
||||
update-containers:
|
||||
#!/usr/bin/env bash
|
||||
set -e # Exit on error
|
||||
CONTAINERS=($(docker ps --format "{{"{{.Names}}"}}"))
|
||||
|
||||
echo "Will update these containers:"
|
||||
printf '%s\n' "${CONTAINERS[@]}" | gum table && \
|
||||
gum confirm "Continue?" || exit 0
|
||||
|
||||
# First collect all image information
|
||||
declare -A CONTAINER_IMAGES
|
||||
echo "Collecting image information..."
|
||||
for container in "${CONTAINERS[@]}"; do
|
||||
FULL_IMAGE=$(docker inspect "$container" --format '{{"{{.Config.Image}}"}}')
|
||||
CONTAINER_IMAGES[$container]=$(echo "$FULL_IMAGE" | sed 's/@sha256.*$//')
|
||||
echo "$container -> ${CONTAINER_IMAGES[$container]}"
|
||||
done
|
||||
|
||||
echo "Stopping containers..." && \
|
||||
for container in "${CONTAINERS[@]}"; do
|
||||
echo "Stopping $container..."
|
||||
sudo systemctl stop "docker-$container.service"
|
||||
done
|
||||
|
||||
echo "Pulling new images..." && \
|
||||
for container in "${CONTAINERS[@]}"; do
|
||||
IMAGE="${CONTAINER_IMAGES[$container]}"
|
||||
echo -e "\n📥 Pulling $IMAGE for $container..." | gum style --foreground 99
|
||||
if ! docker pull "$IMAGE" --quiet=false; then
|
||||
echo "❌ Failed to pull $IMAGE" | gum style --foreground 196
|
||||
exit 1
|
||||
fi
|
||||
echo "------------------------"
|
||||
done
|
||||
|
||||
echo "Starting containers..." && \
|
||||
for container in "${CONTAINERS[@]}"; do
|
||||
echo "Starting $container..."
|
||||
sudo systemctl start "docker-$container.service"
|
||||
done && \
|
||||
gum style --foreground 212 "✅ Containers updated successfully!"
|
0
justfiles/tiers/premium.just
Normal file
0
justfiles/tiers/premium.just
Normal file
0
justfiles/tiers/starter.just
Normal file
0
justfiles/tiers/starter.just
Normal file
Reference in New Issue
Block a user