From 1b896956c924ea4f440bc0125543826195ed5b78 Mon Sep 17 00:00:00 2001 From: ItsKev Date: Sat, 20 Dec 2025 10:30:29 +0100 Subject: [PATCH 1/6] Refactor logging functions and fix installation --- .github/workflows/lint.yml | 2 +- cluster/bootstrap.sh | 54 +++------------------- scripts/common.sh | 28 ++++++++++++ scripts/install-prereqs.sh | 94 ++++++++++++-------------------------- scripts/kubehelpers.sh | 47 ++++--------------- scripts/wait-for-crds.sh | 32 ++----------- values/agones.values.yaml | 2 + 7 files changed, 78 insertions(+), 181 deletions(-) create mode 100644 scripts/common.sh diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5adbb4d..88f86bc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -35,7 +35,7 @@ jobs: sudo mv kubectl /usr/local/bin/ # Install helmfile - curl -L https://github.com/helmfile/helmfile/releases/download/v0.156.0/helmfile_0.156.0_linux_amd64.tar.gz | tar xz + curl -L https://github.com/helmfile/helmfile/releases/download/v1.2.3/helmfile_1.2.3_linux_amd64.tar.gz | tar xz sudo mv helmfile /usr/local/bin/ echo "✅ All prerequisites installed successfully" diff --git a/cluster/bootstrap.sh b/cluster/bootstrap.sh index 54a2fa1..4377489 100755 --- a/cluster/bootstrap.sh +++ b/cluster/bootstrap.sh @@ -1,43 +1,12 @@ #!/usr/bin/env bash -# Bootstrap script for Grounds Development Infrastructure (grounds-dev) k3d cluster -# Creates cluster, sets up namespaces, and configures Helm repositories set -euo pipefail -# Colors and emojis for fancy console output -readonly RED='\033[0;31m' -readonly GREEN='\033[0;32m' -readonly YELLOW='\033[1;33m' -readonly BLUE='\033[0;34m' -readonly PURPLE='\033[0;35m' -readonly CYAN='\033[0;36m' -readonly WHITE='\033[1;37m' -readonly NC='\033[0m' # No Color - -# Logging functions -log_info() { - echo -e "${BLUE}ℹ️ $1${NC}" -} - -log_success() { - echo -e "${GREEN}✅ $1${NC}" -} - -log_warning() { - echo -e "${YELLOW}⚠️ $1${NC}" -} - -log_error() { - echo -e "${RED}❌ $1${NC}" -} - -log_step() { - echo -e "${PURPLE}🚀 $1${NC}" -} - # Get script directory here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${here}/../scripts/common.sh" + log_step "Starting Grounds Development Infrastructure cluster bootstrap..." # Check prerequisites @@ -194,17 +163,6 @@ else log_info "To enable GHCR authentication, set GHCR_USERNAME and GHCR_TOKEN in your .env file" fi -# Add Helm repositories -log_step "Adding Helm repositories..." -helm repo add bitnami https://charts.bitnami.com/bitnami -helm repo add agones https://agones.dev/chart/stable -log_success "Helm repositories added" - -# Update Helm repositories -log_info "Updating Helm repository cache..." -helm repo update -log_success "Helm repositories updated" - # Verify cluster is ready with retry log_info "Verifying cluster readiness..." max_retries=5 @@ -231,7 +189,7 @@ fi log_step "Bootstrap completed successfully! 🎉" log_info "Next steps:" -echo -e " ${CYAN}•${NC} Run ${WHITE}make up${NC} to deploy the full stack" -echo -e " ${CYAN}•${NC} Run ${WHITE}make status${NC} to check deployment status" -echo -e " ${CYAN}•${NC} Access services at ${WHITE}http://localhost${NC}" -echo -e " ${CYAN}•${NC} Use kubeconfig: ${WHITE}export KUBECONFIG=\$(pwd)/kubeconfig${NC}" +log_info "• Run 'make up' to deploy the full stack" +log_info "• Run 'make status' to check deployment status" +log_info "• Access services at 'http://localhost'" +log_info "• Use kubeconfig: 'export KUBECONFIG=\$(pwd)/kubeconfig'" diff --git a/scripts/common.sh b/scripts/common.sh new file mode 100644 index 0000000..467f95f --- /dev/null +++ b/scripts/common.sh @@ -0,0 +1,28 @@ +# Colors and emojis for log output +readonly RED='\033[0;31m' +readonly GREEN='\033[0;32m' +readonly YELLOW='\033[1;33m' +readonly BLUE='\033[0;34m' +readonly PURPLE='\033[0;35m' +readonly NC='\033[0m' # No Color + +# Logging functions +log_info() { + echo -e "${BLUE}ℹ️ $1${NC}" +} + +log_success() { + echo -e "${GREEN}✅ $1${NC}" +} + +log_warning() { + echo -e "${YELLOW}⚠️ $1${NC}" +} + +log_error() { + echo -e "${RED}❌ $1${NC}" +} + +log_step() { + echo -e "${PURPLE}🚀 $1${NC}" +} diff --git a/scripts/install-prereqs.sh b/scripts/install-prereqs.sh index 03264f8..12fb0db 100755 --- a/scripts/install-prereqs.sh +++ b/scripts/install-prereqs.sh @@ -1,55 +1,26 @@ #!/usr/bin/env bash -# Prerequisites installation script for Grounds Development Infrastructure -# Automatically installs missing dependencies for local Kubernetes development set -euo pipefail -# Colors and emojis for fancy console output -readonly RED='\033[0;31m' -readonly GREEN='\033[0;32m' -readonly YELLOW='\033[1;33m' -readonly BLUE='\033[0;34m' -readonly PURPLE='\033[0;35m' -readonly CYAN='\033[0;36m' -readonly WHITE='\033[1;37m' -readonly NC='\033[0m' # No Color - -# Logging functions -log_info() { - echo -e "${BLUE}ℹ️ $1${NC}" -} - -log_success() { - echo -e "${GREEN}✅ $1${NC}" -} - -log_warning() { - echo -e "${YELLOW}⚠️ $1${NC}" -} - -log_error() { - echo -e "${RED}❌ $1${NC}" -} - -log_step() { - echo -e "${PURPLE}🚀 $1${NC}" -} +here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${here}/common.sh" # Check if command exists command_exists() { - command -v "$1" >/dev/null 2>&1 + if command -v "$1" >/dev/null 2>&1; then + echo 0 + else + echo 1 + fi } # Detect OS detect_os() { if [[ "${OSTYPE}" == "linux-gnu"* ]]; then local has_apt has_yum has_pacman - command_exists apt-get - has_apt=$? - command_exists yum - has_yum=$? - command_exists pacman - has_pacman=$? + has_apt=$(command_exists apt-get) + has_yum=$(command_exists yum) + has_pacman=$(command_exists pacman) if [[ "${has_apt}" -eq 0 ]]; then echo "ubuntu" @@ -77,8 +48,7 @@ install_docker() { case "${os}" in "ubuntu") local docker_exists - command_exists docker - docker_exists=$? + docker_exists=$(command_exists docker) if [[ "${docker_exists}" -ne 0 ]]; then curl -fsSL https://get.docker.com | sh sudo usermod -aG docker "${USER}" @@ -89,8 +59,7 @@ install_docker() { ;; "macos") local docker_exists - command_exists docker - docker_exists=$? + docker_exists=$(command_exists docker) if [[ "${docker_exists}" -ne 0 ]]; then log_warning "Please install Docker Desktop for macOS from https://www.docker.com/products/docker-desktop" log_info "Or install via Homebrew: brew install --cask docker" @@ -107,8 +76,7 @@ install_docker() { # Install k3d install_k3d() { local k3d_exists - command_exists k3d - k3d_exists=$? + k3d_exists=$(command_exists k3d) if [[ "${k3d_exists}" -ne 0 ]]; then log_info "Installing k3d..." curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash @@ -121,8 +89,7 @@ install_k3d() { # Install kubectl install_kubectl() { local kubectl_exists - command_exists kubectl - kubectl_exists=$? + kubectl_exists=$(command_exists kubectl) if [[ "${kubectl_exists}" -ne 0 ]]; then log_info "Installing kubectl..." local kubectl_version=$(curl -L -s https://dl.k8s.io/release/stable.txt) @@ -138,8 +105,7 @@ install_kubectl() { # Install Helm install_helm() { local helm_exists - command_exists helm - helm_exists=$? + helm_exists=$(command_exists helm) if [[ "${helm_exists}" -ne 0 ]]; then log_info "Installing Helm..." curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash @@ -152,13 +118,15 @@ install_helm() { # Install Helmfile install_helmfile() { local helmfile_exists - command_exists helmfile - helmfile_exists=$? + helmfile_exists=$(command_exists helmfile) if [[ "${helmfile_exists}" -ne 0 ]]; then log_info "Installing Helmfile..." - local helmfile_version="v0.156.0" - curl -L "https://github.com/helmfile/helmfile/releases/download/${helmfile_version}/helmfile_${helmfile_version#v}_linux_amd64.tar.gz" | tar xz - sudo mv helmfile /usr/local/bin/ + local helmfile_version="v1.2.3" + local tmp_dir + tmp_dir="$(mktemp -d)" + curl -L "https://github.com/helmfile/helmfile/releases/download/${helmfile_version}/helmfile_${helmfile_version#v}_linux_amd64.tar.gz" | tar -xz -C "${tmp_dir}" + sudo mv "${tmp_dir}/helmfile" /usr/local/bin/ + rm -rf "${tmp_dir}" log_success "Helmfile installed" else log_success "Helmfile already installed" @@ -197,18 +165,12 @@ check_prereqs() { local missing=() local docker_exists k3d_exists kubectl_exists helm_exists helmfile_exists devspace_exists - command_exists docker - docker_exists=$? - command_exists k3d - k3d_exists=$? - command_exists kubectl - kubectl_exists=$? - command_exists helm - helm_exists=$? - command_exists helmfile - helmfile_exists=$? - command_exists devspace - devspace_exists=$? + docker_exists=$(command_exists docker) + k3d_exists=$(command_exists k3d) + kubectl_exists=$(command_exists kubectl) + helm_exists=$(command_exists helm) + helmfile_exists=$(command_exists helmfile) + devspace_exists=$(command_exists devspace) if [[ "${docker_exists}" -ne 0 ]]; then missing+=("docker") diff --git a/scripts/kubehelpers.sh b/scripts/kubehelpers.sh index 27f76ab..f08e8ae 100755 --- a/scripts/kubehelpers.sh +++ b/scripts/kubehelpers.sh @@ -1,39 +1,9 @@ #!/usr/bin/env bash -# Kubernetes helper utilities with fancy console output -# Provides common kubectl operations with colored logging set -euo pipefail -# Colors and emojis for fancy console output -readonly RED='\033[0;31m' -readonly GREEN='\033[0;32m' -readonly YELLOW='\033[1;33m' -readonly BLUE='\033[0;34m' -readonly PURPLE='\033[0;35m' -readonly CYAN='\033[0;36m' -readonly WHITE='\033[1;37m' -readonly NC='\033[0m' # No Color - -# Logging functions -log_info() { - echo -e "${BLUE}ℹ️ $1${NC}" -} - -log_success() { - echo -e "${GREEN}✅ $1${NC}" -} - -log_warning() { - echo -e "${YELLOW}⚠️ $1${NC}" -} - -log_error() { - echo -e "${RED}❌ $1${NC}" -} - -log_step() { - echo -e "${PURPLE}🚀 $1${NC}" -} +here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${here}/common.sh" # Check if kubectl is available check_kubectl() { @@ -57,13 +27,16 @@ check_cluster() { get_cluster_status() { log_step "Getting cluster status..." - echo -e "\n${CYAN}📊 Cluster Nodes:${NC}" + echo "" + log_info "📊 Cluster Nodes:" kubectl get nodes -o wide - echo -e "\n${CYAN}📦 All Pods:${NC}" + echo "" + log_info "📦 All Pods:" kubectl get pods -A - echo -e "\n${CYAN}🔧 Services:${NC}" + echo "" + log_info "🔧 Services:" kubectl get services -A } @@ -155,8 +128,8 @@ main() { port_forward "$2" "$3" "$4" "$5" ;; "help"|*) - echo -e "${WHITE}Kubernetes Helper Script${NC}" - echo -e "${CYAN}Usage:${NC}" + log_info "Kubernetes Helper Script" + log_info "Usage:" echo " $0 status - Get cluster status" echo " $0 wait-pods - Wait for pods to be ready" echo " $0 check-ns - Check if namespace exists" diff --git a/scripts/wait-for-crds.sh b/scripts/wait-for-crds.sh index 85d1a05..db2593e 100755 --- a/scripts/wait-for-crds.sh +++ b/scripts/wait-for-crds.sh @@ -1,43 +1,17 @@ #!/usr/bin/env bash -# Wait for Agones CRDs to be ready -# Provides fancy console output with spinner and progress indicators set -euo pipefail -# Colors and emojis for fancy console output -readonly RED='\033[0;31m' -readonly GREEN='\033[0;32m' -readonly YELLOW='\033[1;33m' -readonly BLUE='\033[0;34m' -readonly PURPLE='\033[0;35m' -readonly CYAN='\033[0;36m' -readonly WHITE='\033[1;37m' -readonly NC='\033[0m' # No Color +here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${here}/common.sh" # Spinner characters spinner_chars=("⠋" "⠙" "⠹" "⠸" "⠼" "⠴" "⠦" "⠧" "⠇" "⠏") spinner_index=0 -# Logging functions -log_info() { - echo -e "${BLUE}ℹ️ $1${NC}" -} - -log_success() { - echo -e "${GREEN}✅ $1${NC}" -} - -log_warning() { - echo -e "${YELLOW}⚠️ $1${NC}" -} - -log_error() { - echo -e "${RED}❌ $1${NC}" -} - # Spinner function show_spinner() { - printf "\r%s%s%s %s" "${PURPLE}" "${spinner_chars[${spinner_index}]}" "${NC}" "$1" + printf "\r%s %s" "${spinner_chars[${spinner_index}]}" "$1" spinner_index=$(( (spinner_index + 1) % ${#spinner_chars[@]} )) } diff --git a/values/agones.values.yaml b/values/agones.values.yaml index 30ecad9..51f0646 100644 --- a/values/agones.values.yaml +++ b/values/agones.values.yaml @@ -15,8 +15,10 @@ agones: service: http: port: 10443 + targetPort: 8443 grpc: port: 10444 + targetPort: 8444 # Controller configuration controller: From e080eb82004eb2741a961eb55b7fd359fb028f85 Mon Sep 17 00:00:00 2001 From: ItsKev Date: Sat, 20 Dec 2025 10:42:45 +0100 Subject: [PATCH 2/6] Fix all shellcheck findings --- cluster/bootstrap.sh | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/cluster/bootstrap.sh b/cluster/bootstrap.sh index 4377489..1099be8 100755 --- a/cluster/bootstrap.sh +++ b/cluster/bootstrap.sh @@ -25,20 +25,20 @@ if k3d cluster list | grep -q "^dev "; then retry_count=0 cluster_healthy=false - while [ $retry_count -lt $max_retries ]; do + while [[ "${retry_count}" -lt "${max_retries}" ]]; do if kubectl cluster-info >/dev/null 2>&1 && kubectl get nodes >/dev/null 2>&1; then cluster_healthy=true break fi retry_count=$((retry_count + 1)) - log_warning "Cluster health check failed (attempt $retry_count/$max_retries), retrying in 5 seconds..." + log_warning "Cluster health check failed (attempt ${retry_count}/${max_retries}), retrying in 5 seconds..." sleep 5 done - if [ "$cluster_healthy" = true ]; then + if [[ "${cluster_healthy}" = true ]]; then log_success "Cluster 'dev' is healthy, skipping creation" else - log_warning "Cluster 'dev' exists but is unhealthy after $max_retries attempts, recreating..." + log_warning "Cluster 'dev' exists but is unhealthy after ${max_retries} attempts, recreating..." k3d cluster delete dev log_step "Creating k3d cluster 'dev'..." k3d cluster create --config "${here}/k3d.yaml" @@ -65,15 +65,15 @@ if command -v kubectx >/dev/null 2>&1; then log_info "kubectx detected, installing kubeconfig to ~/.kube/config..." # Ensure ~/.kube directory exists - mkdir -p "$HOME/.kube" + mkdir -p "${HOME}/.kube" # Merge kubeconfigs using kubectl's native merge capability - if [ -f "$HOME/.kube/config" ]; then - KUBECONFIG="$HOME/.kube/config:${here}/../kubeconfig" kubectl config view --flatten > /tmp/merged-config - mv /tmp/merged-config "$HOME/.kube/config" + if [[ -f "${HOME}/.kube/config" ]]; then + KUBECONFIG="${HOME}/.kube/config:${here}/../kubeconfig" kubectl config view --flatten > /tmp/merged-config + mv /tmp/merged-config "${HOME}/.kube/config" log_success "k3d-dev context merged into ~/.kube/config" else - cp "${here}/../kubeconfig" "$HOME/.kube/config" + cp "${here}/../kubeconfig" "${HOME}/.kube/config" log_success "kubeconfig installed to ~/.kube/config" fi @@ -92,7 +92,7 @@ log_success "Namespaces created: infra, databases, games, api" # Load .env file if it exists env_file="${here}/../.env" -if [ -f "${env_file}" ]; then +if [[ -f "${env_file}" ]]; then log_info "Loading environment variables from .env file..." set -a # shellcheck source=/dev/null @@ -104,7 +104,7 @@ else fi # Create GHCR pull secret if credentials are provided -if [ -n "${GHCR_USERNAME:-}" ] && [ -n "${GHCR_TOKEN:-}" ]; then +if [[ -n "${GHCR_USERNAME:-}" && -n "${GHCR_TOKEN:-}" ]]; then log_step "Creating GHCR pull secret..." # Create secret in default namespace @@ -169,21 +169,21 @@ max_retries=5 retry_count=0 cluster_ready=false -while [ $retry_count -lt $max_retries ]; do +while [[ "${retry_count}" -lt "${max_retries}" ]]; do if kubectl get nodes >/dev/null 2>&1; then cluster_ready=true break fi retry_count=$((retry_count + 1)) - log_warning "Cluster readiness check failed (attempt $retry_count/$max_retries), retrying in 10 seconds..." + log_warning "Cluster readiness check failed (attempt ${retry_count}/${max_retries}), retrying in 10 seconds..." sleep 10 done -if [ "$cluster_ready" = true ]; then +if [[ "${cluster_ready}" = true ]]; then kubectl get nodes log_success "Cluster is ready!" else - log_error "Cluster failed to become ready after $max_retries attempts" + log_error "Cluster failed to become ready after ${max_retries} attempts" exit 1 fi From d654ff0c2aaa63c95dc23f5566a69f48f8524cc1 Mon Sep 17 00:00:00 2001 From: ItsKev Date: Sat, 20 Dec 2025 10:56:11 +0100 Subject: [PATCH 3/6] Remove custom os handling and do not try to install docker --- Makefile | 6 -- scripts/install-prereqs.sh | 119 +------------------------------------ 2 files changed, 1 insertion(+), 124 deletions(-) diff --git a/Makefile b/Makefile index caaf993..8c63789 100644 --- a/Makefile +++ b/Makefile @@ -110,12 +110,6 @@ test: ## Test the deployment @curl -s http://localhost/demo || echo -e "$(YELLOW)⚠️ Dummy server not accessible (may still be starting)$(NC)" @echo -e "$(GREEN)✅ Tests completed$(NC)" -# Utility targets -.PHONY: check-prereqs -check-prereqs: ## Check prerequisites - @echo -e "$(BLUE)ℹ️ Checking prerequisites...$(NC)" - @./scripts/install-prereqs.sh --check-only || true - .PHONY: export-kubeconfig export-kubeconfig: ## Export k3d cluster kubeconfig to ./kubeconfig @echo -e "$(BLUE)ℹ️ Exporting kubeconfig...$(NC)" diff --git a/scripts/install-prereqs.sh b/scripts/install-prereqs.sh index 12fb0db..9aa5513 100755 --- a/scripts/install-prereqs.sh +++ b/scripts/install-prereqs.sh @@ -14,65 +14,6 @@ command_exists() { fi } -# Detect OS -detect_os() { - if [[ "${OSTYPE}" == "linux-gnu"* ]]; then - local has_apt has_yum has_pacman - has_apt=$(command_exists apt-get) - has_yum=$(command_exists yum) - has_pacman=$(command_exists pacman) - - if [[ "${has_apt}" -eq 0 ]]; then - echo "ubuntu" - elif [[ "${has_yum}" -eq 0 ]]; then - echo "rhel" - elif [[ "${has_pacman}" -eq 0 ]]; then - echo "arch" - else - echo "linux" - fi - elif [[ "${OSTYPE}" == "darwin"* ]]; then - echo "macos" - elif [[ "${OSTYPE}" == "msys" ]] || [[ "${OSTYPE}" == "cygwin" ]]; then - echo "windows" - else - echo "unknown" - fi -} - -# Install Docker -install_docker() { - local os="$1" - log_info "Installing Docker..." - - case "${os}" in - "ubuntu") - local docker_exists - docker_exists=$(command_exists docker) - if [[ "${docker_exists}" -ne 0 ]]; then - curl -fsSL https://get.docker.com | sh - sudo usermod -aG docker "${USER}" - log_success "Docker installed. Please log out and back in for group changes to take effect." - else - log_success "Docker already installed" - fi - ;; - "macos") - local docker_exists - docker_exists=$(command_exists docker) - if [[ "${docker_exists}" -ne 0 ]]; then - log_warning "Please install Docker Desktop for macOS from https://www.docker.com/products/docker-desktop" - log_info "Or install via Homebrew: brew install --cask docker" - else - log_success "Docker already installed" - fi - ;; - *) - log_warning "Please install Docker manually for your OS" - ;; - esac -} - # Install k3d install_k3d() { local k3d_exists @@ -151,75 +92,17 @@ install_devspace() { # Check Docker daemon check_docker_daemon() { if ! docker info >/dev/null 2>&1; then - log_warning "Docker daemon is not running. Please start Docker and try again." - log_info "On Linux: sudo systemctl start docker" - log_info "On macOS: Start Docker Desktop" + log_warning "Docker daemon is not running. Please install or start Docker and try again." return 1 fi return 0 } -# Check prerequisites only -check_prereqs() { - log_info "Checking prerequisites..." - local missing=() - local docker_exists k3d_exists kubectl_exists helm_exists helmfile_exists devspace_exists - - docker_exists=$(command_exists docker) - k3d_exists=$(command_exists k3d) - kubectl_exists=$(command_exists kubectl) - helm_exists=$(command_exists helm) - helmfile_exists=$(command_exists helmfile) - devspace_exists=$(command_exists devspace) - - if [[ "${docker_exists}" -ne 0 ]]; then - missing+=("docker") - fi - - if [[ "${k3d_exists}" -ne 0 ]]; then - missing+=("k3d") - fi - - if [[ "${kubectl_exists}" -ne 0 ]]; then - missing+=("kubectl") - fi - - if [[ "${helm_exists}" -ne 0 ]]; then - missing+=("helm") - fi - - if [[ "${helmfile_exists}" -ne 0 ]]; then - missing+=("helmfile") - fi - - if [[ "${devspace_exists}" -ne 0 ]]; then - missing+=("devspace") - fi - - if [[ ${#missing[@]} -eq 0 ]]; then - log_success "All prerequisites found" - return 0 - else - log_warning "Missing prerequisites: ${missing[*]}" - return 1 - fi -} - # Main installation function main() { - # Check if --check-only flag is provided - if [[ "${1:-}" == "--check-only" ]]; then - check_prereqs - return $? - fi - log_step "Checking and installing prerequisites for Grounds Development Infrastructure..." - local os=$(detect_os) - log_info "Detected OS: ${os}" - # Install prerequisites - install_docker "${os}" install_k3d install_kubectl install_helm From 042651ef4508fc8f17435a7a916cb61727eb387e Mon Sep 17 00:00:00 2001 From: ItsKev Date: Sat, 20 Dec 2025 11:11:11 +0100 Subject: [PATCH 4/6] Remove lots of unnecessary comments --- .gitignore | 3 --- .shellcheckrc | 3 --- .yamllint | 3 --- Makefile | 11 ----------- cluster/bootstrap.sh | 12 +++++------- cluster/k3d.yaml | 14 -------------- helmfile.yaml | 4 ---- scripts/install-prereqs.sh | 8 -------- scripts/kubehelpers.sh | 12 ++---------- scripts/wait-for-crds.sh | 3 --- 10 files changed, 7 insertions(+), 66 deletions(-) diff --git a/.gitignore b/.gitignore index 2224aef..5b89781 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -# Grounds Development Infrastructure (grounds-dev) .gitignore -# Ignores temporary files, build artifacts, and sensitive data - # Kubernetes and Helm artifacts *.kubeconfig *.kubeconfig.backup diff --git a/.shellcheckrc b/.shellcheckrc index 9f3a842..6d345a4 100644 --- a/.shellcheckrc +++ b/.shellcheckrc @@ -1,6 +1,3 @@ -# ShellCheck configuration for Grounds Development Infrastructure -# Ensures consistent shell script quality and security - # Disable specific warnings that are acceptable for this project disable=SC1091,SC2034,SC2155,SC2164 diff --git a/.yamllint b/.yamllint index b18234c..3a252c8 100644 --- a/.yamllint +++ b/.yamllint @@ -1,6 +1,3 @@ -# yamllint configuration for Grounds Development Infrastructure -# Ensures consistent YAML formatting across the repository - extends: default rules: diff --git a/Makefile b/Makefile index 8c63789..8b80b7f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,3 @@ -# Grounds Development Infrastructure (grounds-dev) Makefile -# Automation for local Kubernetes development environment -# Provides one-command setup and management of k3d cluster with PostgreSQL, Agones, and Open Match - SHELL := /usr/bin/env bash # Colors for fancy output @@ -109,10 +105,3 @@ test: ## Test the deployment @echo -e "$(BLUE)ℹ️ Testing dummy HTTP server...$(NC)" @curl -s http://localhost/demo || echo -e "$(YELLOW)⚠️ Dummy server not accessible (may still be starting)$(NC)" @echo -e "$(GREEN)✅ Tests completed$(NC)" - -.PHONY: export-kubeconfig -export-kubeconfig: ## Export k3d cluster kubeconfig to ./kubeconfig - @echo -e "$(BLUE)ℹ️ Exporting kubeconfig...$(NC)" - @k3d kubeconfig get dev > kubeconfig - @echo -e "$(GREEN)✅ Kubeconfig exported to ./kubeconfig$(NC)" - @echo -e "$(CYAN)Use it with: export KUBECONFIG=\$$(pwd)/kubeconfig$(NC)" diff --git a/cluster/bootstrap.sh b/cluster/bootstrap.sh index 1099be8..915e214 100755 --- a/cluster/bootstrap.sh +++ b/cluster/bootstrap.sh @@ -4,7 +4,6 @@ set -euo pipefail # Get script directory here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - source "${here}/../scripts/common.sh" log_step "Starting Grounds Development Infrastructure cluster bootstrap..." @@ -55,14 +54,14 @@ log_info "Setting kubectl context to k3d-dev..." kubectl config use-context k3d-dev log_success "kubectl context set to k3d-dev" -# Export kubeconfig to project root -log_info "Exporting kubeconfig to ./kubeconfig..." -k3d kubeconfig get dev > "${here}/../kubeconfig" -log_success "Kubeconfig exported to ./kubeconfig" - # Install kubeconfig for kubectx if available if command -v kubectx >/dev/null 2>&1; then log_info "kubectx detected, installing kubeconfig to ~/.kube/config..." + + # Export kubeconfig to project root + log_info "Exporting kubeconfig to ./kubeconfig..." + k3d kubeconfig get dev > "${here}/../kubeconfig" + log_success "Kubeconfig exported to ./kubeconfig" # Ensure ~/.kube directory exists mkdir -p "${HOME}/.kube" @@ -192,4 +191,3 @@ log_info "Next steps:" log_info "• Run 'make up' to deploy the full stack" log_info "• Run 'make status' to check deployment status" log_info "• Access services at 'http://localhost'" -log_info "• Use kubeconfig: 'export KUBECONFIG=\$(pwd)/kubeconfig'" diff --git a/cluster/k3d.yaml b/cluster/k3d.yaml index 7e1e28d..75f2e77 100644 --- a/cluster/k3d.yaml +++ b/cluster/k3d.yaml @@ -1,7 +1,3 @@ -# k3d cluster configuration for local development -# This creates a lightweight Kubernetes cluster with 1 server + 2 agents -# Includes integrated registry and ingress port mapping for local development - apiVersion: k3d.io/v1alpha5 kind: Simple metadata: @@ -11,7 +7,6 @@ metadata: servers: 1 agents: 2 -# Use k3s version 1.34.1 for stability and compatibility image: rancher/k3s:v1.34.1-k3s1 # Port mappings for ingress traffic @@ -41,15 +36,6 @@ registries: username: ${DOCKER_USERNAME} password: ${DOCKER_PASSWORD} -# k3d and k3s options options: k3d: wait: true # Wait for cluster to be ready before returning - # k3s: - # extraArgs: - # # Keep ServiceLB enabled for LoadBalancer services - # - arg: --disable=servicelb=false - # nodeFilters: [server:0] - # # Keep Traefik enabled for ingress controller - # - arg: --disable=traefik=false - # nodeFilters: [server:0] diff --git a/helmfile.yaml b/helmfile.yaml index 971269a..6bfd6fe 100644 --- a/helmfile.yaml +++ b/helmfile.yaml @@ -1,7 +1,3 @@ -# Helmfile configuration for grounds-dev -# Orchestrates deployment of PostgreSQL and Agones -# Uses declarative approach with proper dependency management - # Helm repositories repositories: - name: bitnami diff --git a/scripts/install-prereqs.sh b/scripts/install-prereqs.sh index 9aa5513..8784930 100755 --- a/scripts/install-prereqs.sh +++ b/scripts/install-prereqs.sh @@ -5,7 +5,6 @@ set -euo pipefail here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${here}/common.sh" -# Check if command exists command_exists() { if command -v "$1" >/dev/null 2>&1; then echo 0 @@ -14,7 +13,6 @@ command_exists() { fi } -# Install k3d install_k3d() { local k3d_exists k3d_exists=$(command_exists k3d) @@ -27,7 +25,6 @@ install_k3d() { fi } -# Install kubectl install_kubectl() { local kubectl_exists kubectl_exists=$(command_exists kubectl) @@ -43,7 +40,6 @@ install_kubectl() { fi } -# Install Helm install_helm() { local helm_exists helm_exists=$(command_exists helm) @@ -56,7 +52,6 @@ install_helm() { fi } -# Install Helmfile install_helmfile() { local helmfile_exists helmfile_exists=$(command_exists helmfile) @@ -74,7 +69,6 @@ install_helmfile() { fi } -# Install DevSpace install_devspace() { if ! command -v devspace >/dev/null 2>&1; then log_info "Installing DevSpace..." @@ -89,7 +83,6 @@ install_devspace() { fi } -# Check Docker daemon check_docker_daemon() { if ! docker info >/dev/null 2>&1; then log_warning "Docker daemon is not running. Please install or start Docker and try again." @@ -98,7 +91,6 @@ check_docker_daemon() { return 0 } -# Main installation function main() { log_step "Checking and installing prerequisites for Grounds Development Infrastructure..." diff --git a/scripts/kubehelpers.sh b/scripts/kubehelpers.sh index f08e8ae..17998b3 100755 --- a/scripts/kubehelpers.sh +++ b/scripts/kubehelpers.sh @@ -5,7 +5,6 @@ set -euo pipefail here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${here}/common.sh" -# Check if kubectl is available check_kubectl() { if ! command -v kubectl >/dev/null 2>&1; then log_error "kubectl is not installed or not in PATH" @@ -13,8 +12,7 @@ check_kubectl() { fi } -# Check cluster connectivity -check_cluster() { +check_cluster_connectivity() { log_info "Checking cluster connectivity..." if ! kubectl cluster-info >/dev/null 2>&1; then log_error "Cannot connect to Kubernetes cluster" @@ -23,7 +21,6 @@ check_cluster() { log_success "Cluster is accessible" } -# Get cluster status get_cluster_status() { log_step "Getting cluster status..." @@ -40,7 +37,6 @@ get_cluster_status() { kubectl get services -A } -# Wait for pods to be ready wait_for_pods() { local namespace="$1" local selector="$2" @@ -57,7 +53,6 @@ wait_for_pods() { fi } -# Check namespace exists check_namespace() { local namespace="$1" @@ -70,7 +65,6 @@ check_namespace() { fi } -# Get pod logs get_pod_logs() { local namespace="$1" local pod="$2" @@ -80,7 +74,6 @@ get_pod_logs() { kubectl logs -n "${namespace}" "${pod}" --tail="${lines}" } -# Port forward helper port_forward() { local namespace="$1" local service="$2" @@ -91,12 +84,11 @@ port_forward() { kubectl port-forward -n "${namespace}" "service/${service}" "${local_port}:${service_port}" } -# Main function for script usage main() { case "${1:-help}" in "status") check_kubectl - check_cluster + check_cluster_connectivity get_cluster_status ;; "wait-pods") diff --git a/scripts/wait-for-crds.sh b/scripts/wait-for-crds.sh index db2593e..dab55e3 100755 --- a/scripts/wait-for-crds.sh +++ b/scripts/wait-for-crds.sh @@ -9,13 +9,11 @@ source "${here}/common.sh" spinner_chars=("⠋" "⠙" "⠹" "⠸" "⠼" "⠴" "⠦" "⠧" "⠇" "⠏") spinner_index=0 -# Spinner function show_spinner() { printf "\r%s %s" "${spinner_chars[${spinner_index}]}" "$1" spinner_index=$(( (spinner_index + 1) % ${#spinner_chars[@]} )) } -# Wait for CRD function wait_for_crd() { local crd="$1" local timeout="${2:-60}" @@ -38,7 +36,6 @@ wait_for_crd() { return 1 } -# Main execution main() { log_info "Starting CRD readiness check..." From 63c126bbc597066b1ac8c77bb5091992c0fe3c1c Mon Sep 17 00:00:00 2001 From: ItsKev Date: Sat, 20 Dec 2025 11:29:45 +0100 Subject: [PATCH 5/6] Remove kubectx logic --- cluster/bootstrap.sh | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/cluster/bootstrap.sh b/cluster/bootstrap.sh index 915e214..809e0de 100755 --- a/cluster/bootstrap.sh +++ b/cluster/bootstrap.sh @@ -54,33 +54,6 @@ log_info "Setting kubectl context to k3d-dev..." kubectl config use-context k3d-dev log_success "kubectl context set to k3d-dev" -# Install kubeconfig for kubectx if available -if command -v kubectx >/dev/null 2>&1; then - log_info "kubectx detected, installing kubeconfig to ~/.kube/config..." - - # Export kubeconfig to project root - log_info "Exporting kubeconfig to ./kubeconfig..." - k3d kubeconfig get dev > "${here}/../kubeconfig" - log_success "Kubeconfig exported to ./kubeconfig" - - # Ensure ~/.kube directory exists - mkdir -p "${HOME}/.kube" - - # Merge kubeconfigs using kubectl's native merge capability - if [[ -f "${HOME}/.kube/config" ]]; then - KUBECONFIG="${HOME}/.kube/config:${here}/../kubeconfig" kubectl config view --flatten > /tmp/merged-config - mv /tmp/merged-config "${HOME}/.kube/config" - log_success "k3d-dev context merged into ~/.kube/config" - else - cp "${here}/../kubeconfig" "${HOME}/.kube/config" - log_success "kubeconfig installed to ~/.kube/config" - fi - - log_info "You can now use: kubectx k3d-dev" -else - log_info "kubectx not found, skipping kubeconfig installation to ~/.kube/" -fi - # Create namespaces log_info "Creating namespaces..." for ns in infra databases games api; do From 412c2d4c443a51a9dcab1b33d82ee048a727d1a7 Mon Sep 17 00:00:00 2001 From: ItsKev Date: Sat, 20 Dec 2025 12:13:57 +0100 Subject: [PATCH 6/6] Fix imagePullSecrets for GHCR --- cluster/bootstrap.sh | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/cluster/bootstrap.sh b/cluster/bootstrap.sh index 809e0de..744c939 100755 --- a/cluster/bootstrap.sh +++ b/cluster/bootstrap.sh @@ -79,16 +79,6 @@ fi if [[ -n "${GHCR_USERNAME:-}" && -n "${GHCR_TOKEN:-}" ]]; then log_step "Creating GHCR pull secret..." - # Create secret in default namespace - log_info "Creating ghcr-pull-secret in default namespace..." - kubectl create secret docker-registry ghcr-pull-secret \ - --docker-server=ghcr.io \ - --docker-username="${GHCR_USERNAME}" \ - --docker-password="${GHCR_TOKEN}" \ - --namespace=default \ - --dry-run=client -o yaml | kubectl apply -f - - log_success "GHCR pull secret created in default namespace" - # Function to patch service account with GHCR pull secret patch_service_account() { local namespace=$1 @@ -97,25 +87,25 @@ if [[ -n "${GHCR_USERNAME:-}" && -n "${GHCR_TOKEN:-}" ]]; then log_info "GHCR pull secret already configured in default service account for namespace: ${namespace}" else log_info "Patching default service account in namespace: ${namespace}" - # Create imagePullSecrets array if it doesn't exist - if ! kubectl get serviceaccount default -n "${namespace}" -o jsonpath='{.imagePullSecrets}' 2>/dev/null | grep -q "."; then + local pull_secrets_raw + pull_secrets_raw="$(kubectl get serviceaccount default -n "${namespace}" -o jsonpath='{.imagePullSecrets}' 2>/dev/null || true)" + if [[ -z "${pull_secrets_raw}" ]]; then + # Initialize imagePullSecrets so we can append entries later. kubectl patch serviceaccount default \ --namespace="${namespace}" \ --type=json \ - -p='[{"op": "add", "path": "/imagePullSecrets", "value": []}]' || true + -p='[{"op": "add", "path": "/imagePullSecrets", "value": [{"name": "ghcr-pull-secret"}]}]' + else + # Add the secret to the existing list. + kubectl patch serviceaccount default \ + --namespace="${namespace}" \ + --type=json \ + -p='[{"op": "add", "path": "/imagePullSecrets/-", "value": {"name": "ghcr-pull-secret"}}]' fi - # Add the secret to imagePullSecrets - kubectl patch serviceaccount default \ - --namespace="${namespace}" \ - --type=json \ - -p='[{"op": "add", "path": "/imagePullSecrets/-", "value": {"name": "ghcr-pull-secret"}}]' || true log_success "Default service account patched in namespace: ${namespace}" fi } - # Patch default service account in default namespace - patch_service_account default - # Create secret and patch service accounts in all namespaces for ns in infra databases games api; do log_info "Creating ghcr-pull-secret in namespace: ${ns}"