+custom services
This commit is contained in:
parent
aa1e617e3a
commit
c4bff08f72
@ -10,7 +10,7 @@ import? "/etc/self-host-playbook/tiers/premium.just"
|
|||||||
gum style \
|
gum style \
|
||||||
--foreground 212 --border double --border-foreground 212 \
|
--foreground 212 --border double --border-foreground 212 \
|
||||||
--align center --width 50 --margin "1 2" --padding "1 2" \
|
--align center --width 50 --margin "1 2" --padding "1 2" \
|
||||||
"🚀 DevOps Control Center 🚀"
|
"🚀 Self-Hosting Playbook Command Center 🚀"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to create menu items with icons and descriptions
|
# Function to create menu items with icons and descriptions
|
||||||
@ -20,6 +20,7 @@ import? "/etc/self-host-playbook/tiers/premium.just"
|
|||||||
echo "💾 Disk Usage - Show docker disk usage"
|
echo "💾 Disk Usage - Show docker disk usage"
|
||||||
echo "🔄 Restart - Restart a specific container"
|
echo "🔄 Restart - Restart a specific container"
|
||||||
echo "🐳 Update Docker - Update Docker containers"
|
echo "🐳 Update Docker - Update Docker containers"
|
||||||
|
echo "🌐 Add custom service"
|
||||||
echo "❌ Exit"
|
echo "❌ Exit"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +59,9 @@ import? "/etc/self-host-playbook/tiers/premium.just"
|
|||||||
"🐳 Update Docker"*)
|
"🐳 Update Docker"*)
|
||||||
just update-containers
|
just update-containers
|
||||||
;;
|
;;
|
||||||
"❌ Exit")
|
"🌐 Add custom"*)
|
||||||
|
just add-custom-service
|
||||||
|
;; "❌ Exit")
|
||||||
echo "Goodbye! 👋" | gum style --foreground 212
|
echo "Goodbye! 👋" | gum style --foreground 212
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
@ -1,101 +1,14 @@
|
|||||||
status:
|
status:
|
||||||
#!/usr/bin/env bash
|
@/etc/self-host-playbook/scripts/status.sh
|
||||||
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:
|
logs:
|
||||||
#!/usr/bin/env bash
|
@/etc/self-host-playbook/scripts/logs.sh
|
||||||
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:
|
docker-disk:
|
||||||
#!/usr/bin/env bash
|
@/etc/self-host-playbook/scripts/docker-disk.sh
|
||||||
gum style --foreground 212 --bold --border normal --align center --width 50 --margin "1 2" "💾 Docker Disk Usage"
|
|
||||||
docker system df | gum table
|
|
||||||
|
|
||||||
docker-restart:
|
docker-restart:
|
||||||
#!/usr/bin/env bash
|
@/etc/self-host-playbook/scripts/docker-restart.sh
|
||||||
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:
|
update-containers:
|
||||||
#!/usr/bin/env bash
|
@/etc/self-host-playbook/scripts/update-containers.sh
|
||||||
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,0 +1,2 @@
|
|||||||
|
add-custom-service:
|
||||||
|
@/etc/self-host-playbook/scripts/add-custom-service.sh
|
@ -82,13 +82,33 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
programs.bash = {
|
||||||
|
loginShellInit = ''
|
||||||
|
# Only show the message for interactive login shells
|
||||||
|
if [[ -t 0 && -t 1 && "$BASH_EXECUTION_STRING" == "" ]]; then
|
||||||
|
gum style \
|
||||||
|
--foreground 212 \
|
||||||
|
--border double \
|
||||||
|
--margin "1 2" \
|
||||||
|
--padding "1 2" \
|
||||||
|
--align center \
|
||||||
|
--width 70 \
|
||||||
|
"🌟 Welcome to Your Self-Host Playbook Server! 🌟" \
|
||||||
|
"" \
|
||||||
|
"🔧 To manage your server: Run 'shp' (requires sudo)" \
|
||||||
|
"" \
|
||||||
|
"💬 Join our community: https://www.m3tam3re.com"
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
environment.etc = {
|
environment.etc = {
|
||||||
# Main justfile
|
# Main justfile
|
||||||
"self-host-playbook/justfile".source = ../justfiles/main.just;
|
"self-host-playbook/justfile".source = ../justfiles/main.just;
|
||||||
|
|
||||||
# Tier justfiles
|
# Tier justfiles
|
||||||
"self-host-playbook/tiers/core.just".source = ../justfiles/tiers/core.just;
|
"self-host-playbook/tiers".source = ../justfiles/tiers;
|
||||||
"self-host-playbook/tiers/starter.just".source = ../justfiles/tiers/starter.just;
|
"self-host-playbook/scripts".source = ../justfiles/scripts;
|
||||||
};
|
};
|
||||||
# System state version (do not change)
|
# System state version (do not change)
|
||||||
system.stateVersion = "24.11";
|
system.stateVersion = "24.11";
|
||||||
|
@ -1,41 +1,14 @@
|
|||||||
{jsonConfig, ...}: {
|
{jsonConfig, ...}: let
|
||||||
|
# Get all .nix files from the hosts directory
|
||||||
|
hostFiles = builtins.attrNames (builtins.readDir ./hosts);
|
||||||
|
# Filter out non-.nix files
|
||||||
|
hostModules = builtins.filter (n: builtins.match ".*\\.nix" n != null) hostFiles;
|
||||||
|
# Import each host file and merge them
|
||||||
|
importHost = file: import ./hosts/${file} {inherit jsonConfig;};
|
||||||
|
virtualHosts = builtins.foldl' (acc: file: acc // (importHost file)) {} hostModules;
|
||||||
|
in {
|
||||||
services.caddy = {
|
services.caddy = {
|
||||||
enable = true;
|
enable = true;
|
||||||
virtualHosts = {
|
inherit virtualHosts;
|
||||||
${jsonConfig.domains.portainer} = {
|
|
||||||
extraConfig = ''
|
|
||||||
reverse_proxy localhost:9000
|
|
||||||
header {
|
|
||||||
# Security headers
|
|
||||||
Strict-Transport-Security "max-age=31536000; includeSubDomains"
|
|
||||||
X-Content-Type-Options "nosniff"
|
|
||||||
X-Frame-Options "DENY"
|
|
||||||
Referrer-Policy "strict-origin-when-cross-origin"
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
${jsonConfig.domains.n8n} = {
|
|
||||||
extraConfig = ''
|
|
||||||
reverse_proxy localhost:5678
|
|
||||||
header {
|
|
||||||
Strict-Transport-Security "max-age=31536000; includeSubDomains"
|
|
||||||
X-Content-Type-Options "nosniff"
|
|
||||||
X-Frame-Options "DENY"
|
|
||||||
Referrer-Policy "strict-origin-when-cross-origin"
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
${jsonConfig.domains.baserow} = {
|
|
||||||
extraConfig = ''
|
|
||||||
reverse_proxy localhost:3000
|
|
||||||
header {
|
|
||||||
Strict-Transport-Security "max-age=31536000; includeSubDomains"
|
|
||||||
X-Content-Type-Options "nosniff"
|
|
||||||
X-Frame-Options "DENY"
|
|
||||||
Referrer-Policy "strict-origin-when-cross-origin"
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user