infra: add staging runner and network helper scripts

This commit is contained in:
Seth Call 2026-03-13 19:46:12 -05:00
parent 78eb7e6bf0
commit a859c76944
3 changed files with 153 additions and 0 deletions

View File

@ -0,0 +1,44 @@
#!/usr/bin/env ruby
require 'net/http'
require 'json'
require 'uri'
# Configuration
GITEA_URL = "https://git.staging.jamkazam.com/api/v1"
GITEA_TOKEN = "6798c2d2b1beed9a8c33c738f7a521548e40bcc5"
GITEA_OWNER = "seth"
# Default repos if none specified
DEFAULT_REPOS = ["jam-cloud", "video-iac"]
repos_to_delete = ARGV.empty? ? DEFAULT_REPOS : ARGV
def delete_repo(repo_name)
puts "🗑️ Deleting repository: #{repo_name}..."
uri = URI.parse("#{GITEA_URL}/repos/#{GITEA_OWNER}/#{repo_name}")
header = {
'Authorization' => "token #{GITEA_TOKEN}"
}
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(uri.request_uri, header)
response = http.request(request)
if response.code == "204"
puts "✅ Successfully deleted #{repo_name}."
elsif response.code == "404"
puts " Repository #{repo_name} not found. Skipping."
else
puts "❌ Failed to delete #{repo_name}: #{response.code}"
puts response.body
end
end
repos_to_delete.each do |repo|
delete_repo(repo)
end
puts "\n✨ Cleanup complete."

View File

@ -0,0 +1,63 @@
#!/bin/bash
# Configuration
ENV="stg"
PORT=5432
# Parse arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
-s|--stg) ENV="stg" ;;
-p|--prd) ENV="prd" ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
# Function to get IPs based on environment
get_ips() {
if [ "$ENV" == "stg" ]; then
# Sourcing activate-stg to ensure KUBECONFIG is correct
if [ -f "$HOME/bin/activate-stg" ]; then
source "$HOME/bin/activate-stg" > /dev/null
fi
else
# Placeholder for production kubeconfig activation
echo "❌ Error: Production kubeconfig activation not yet defined in this script."
exit 1
fi
kubectl get nodes -o jsonpath='{range .items[*]}{.status.addresses[?(@.type=="ExternalIP")].address}{"\n"}{end}'
}
echo "🔍 Fetching Kubernetes Worker IPs for $ENV..."
IPS=$(get_ips)
if [ -z "$IPS" ]; then
echo "❌ Error: No IPs found. Are you authenticated to the cluster?"
exit 1
fi
echo ""
echo "==============================================================="
echo "📋 IPTABLES RULES FOR $(echo $ENV | tr '[:lower:]' '[:upper:]') POSTGRESQL ACCESS"
echo "==============================================================="
echo "# Port: $PORT"
echo "# Generated on: $(date)"
echo ""
for IP in $IPS; do
# Skip IPv6 for old iptables
if [[ $IP =~ .*:.* ]]; then
continue
fi
echo "iptables -A INPUT -p tcp -s $IP --dport $PORT -j ACCEPT"
done
echo ""
echo "==============================================================="
echo "💡 INSTRUCTIONS:"
echo "1. SSH into the 'int' server: ssh root@72.14.176.182"
echo "2. Copy/Paste the rules above into the terminal."
echo "3. Verify with: iptables -L -n | grep $PORT"
echo "==============================================================="

46
scripts/list-build-runners.sh Executable file
View File

@ -0,0 +1,46 @@
#!/bin/bash
# Simple script to list Gitea Build Runners in Staging or Production
ENVIRONMENT=""
NAMESPACE="jam-cloud-infra"
APP_LABEL="app=act-runner"
case "$1" in
--stg)
ENVIRONMENT="stg"
source ~/bin/activate-stg
;;
--prd)
ENVIRONMENT="prd"
source ~/bin/activate-prd
;;
*)
echo "Usage: $0 --stg|--prd"
exit 1
;;
esac
echo "--------------------------------------------------------"
echo "🔍 Checking Build Runners in [$ENVIRONMENT]"
echo "--------------------------------------------------------"
# 1. Check Deployment Replicas
REPLICAS=$(kubectl get deployment act-runner -n $NAMESPACE -o jsonpath='{.spec.replicas}' 2>/dev/null)
READY=$(kubectl get deployment act-runner -n $NAMESPACE -o jsonpath='{.status.readyReplicas}' 2>/dev/null)
if [ -z "$REPLICAS" ]; then
echo "❌ Deployment 'act-runner' not found in $NAMESPACE"
else
echo "📈 Deployment Status: $REPLICAS total replicas (Ready: ${READY:-0})"
fi
echo ""
echo "📦 Pod Details:"
# 2. List Individual Pods
kubectl get pods -n $NAMESPACE -l $APP_LABEL -o custom-columns="NAME:.metadata.name,STATUS:.status.phase,AGE:.metadata.creationTimestamp,NODE:.spec.nodeName" --no-headers 2>/dev/null || echo "No active runner pods found."
if [ "$REPLICAS" -eq "0" ] && [ -z "$(kubectl get pods -n $NAMESPACE -l $APP_LABEL --no-headers 2>/dev/null)" ]; then
echo "✅ Scale-to-Zero: Success (0 active runners)"
fi
echo "--------------------------------------------------------"