+custom services
This commit is contained in:
parent
c4bff08f72
commit
db8c385587
68
justfiles/scripts/add-custom-service.sh
Executable file
68
justfiles/scripts/add-custom-service.sh
Executable file
@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
gum style \
|
||||
--foreground 212 \
|
||||
--bold \
|
||||
--border normal \
|
||||
--align center \
|
||||
--width 50 \
|
||||
--margin "1 2" \
|
||||
"🔧 Add Custom Service"
|
||||
|
||||
SERVICE_NAME="$(gum input --placeholder "Enter service name" --prompt "Service Name: ")"
|
||||
[[ -z "${SERVICE_NAME}" ]] && { gum style --foreground 1 "⚠️ Service name cannot be empty"; exit 1; }
|
||||
|
||||
SUBDOMAIN="$(gum input --placeholder "Enter subdomain" --prompt "Subdomain: ")"
|
||||
[[ -z "${SUBDOMAIN}" ]] && { gum style --foreground 1 "⚠️ Subdomain cannot be empty"; exit 1; }
|
||||
|
||||
PORT="$(gum input --placeholder "Enter port number" --prompt "Port: ")"
|
||||
[[ ! "${PORT}" =~ ^[0-9]+$ ]] && { gum style --foreground 1 "⚠️ Port must be a number"; exit 1; }
|
||||
|
||||
gum confirm "Is ${SUBDOMAIN} the correct domain?" || { gum style --foreground 1 "❌ Operation cancelled"; exit 0; }
|
||||
|
||||
CONFIG_DIR="/etc/nixos/current-systemconfig"
|
||||
SERVICES_DIR="${CONFIG_DIR}/custom-services"
|
||||
|
||||
# Create directories if they don't exist
|
||||
mkdir -p "${SERVICES_DIR}"
|
||||
|
||||
FILE_PATH="${SERVICES_DIR}/${SERVICE_NAME}.nix"
|
||||
|
||||
cat > "${FILE_PATH}" << EOF
|
||||
{
|
||||
${SUBDOMAIN} = {
|
||||
extraConfig = ''
|
||||
reverse_proxy localhost:${PORT}
|
||||
header {
|
||||
Strict-Transport-Security "max-age=31536000; includeSubDomains"
|
||||
X-Content-Type-Options "nosniff"
|
||||
X-Frame-Options "DENY"
|
||||
Referrer-Policy "strict-origin-when-cross-origin"
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
||||
EOF
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
gum style --foreground 212 "✅ Service file created successfully at ${FILE_PATH}"
|
||||
|
||||
# Initialize Git repo if it doesn't exist
|
||||
if [[ ! -d "${CONFIG_DIR}/.git" ]]; then
|
||||
cd "${CONFIG_DIR}"
|
||||
gum spin --spinner dot --title "Initializing Git repository..." -- git init
|
||||
fi
|
||||
|
||||
gum spin --spinner dot --title "Adding all files..." -- git add .
|
||||
gum spin --spinner dot --title "Creating initial commit..." -- git commit -m "Initial commit"
|
||||
# NixOS rebuild
|
||||
cd "${CONFIG_DIR}"
|
||||
gum spin --spinner dot --title "Rebuilding NixOS..." -- \
|
||||
nixos-rebuild switch --flake .#nixos
|
||||
|
||||
gum style --foreground 212 "✅ Service deployed successfully!"
|
||||
else
|
||||
gum style --foreground 1 "❌ Failed to create service file"
|
||||
exit 1
|
||||
fi
|
3
justfiles/scripts/docker-disk.sh
Executable file
3
justfiles/scripts/docker-disk.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/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
|
11
justfiles/scripts/docker-restart.sh
Executable file
11
justfiles/scripts/docker-restart.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/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..." -- systemctl restart docker-$container
|
||||
gum style --foreground 212 "✅ Container $container restarted successfully!"
|
||||
fi
|
34
justfiles/scripts/logs.sh
Executable file
34
justfiles/scripts/logs.sh
Executable file
@ -0,0 +1,34 @@
|
||||
#!/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
|
3
justfiles/scripts/status.sh
Executable file
3
justfiles/scripts/status.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/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
|
40
justfiles/scripts/update-containers.sh
Executable file
40
justfiles/scripts/update-containers.sh
Executable file
@ -0,0 +1,40 @@
|
||||
#!/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!"
|
13
services/caddy/hosts/baserow.nix
Normal file
13
services/caddy/hosts/baserow.nix
Normal file
@ -0,0 +1,13 @@
|
||||
{jsonConfig, ...}: {
|
||||
${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"
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
13
services/caddy/hosts/n8n.nix
Normal file
13
services/caddy/hosts/n8n.nix
Normal file
@ -0,0 +1,13 @@
|
||||
{jsonConfig, ...}: {
|
||||
${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"
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
14
services/caddy/hosts/portainer.nix
Normal file
14
services/caddy/hosts/portainer.nix
Normal file
@ -0,0 +1,14 @@
|
||||
{jsonConfig, ...}: {
|
||||
${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"
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user