Skip to content

Commit a00d7a5

Browse files
committed
Refactor logging functions and fix installation
1 parent d4698af commit a00d7a5

6 files changed

Lines changed: 77 additions & 180 deletions

File tree

cluster/bootstrap.sh

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,12 @@
11
#!/usr/bin/env bash
2-
# Bootstrap script for Grounds Development Infrastructure (grounds-dev) k3d cluster
3-
# Creates cluster, sets up namespaces, and configures Helm repositories
42

53
set -euo pipefail
64

7-
# Colors and emojis for fancy console output
8-
readonly RED='\033[0;31m'
9-
readonly GREEN='\033[0;32m'
10-
readonly YELLOW='\033[1;33m'
11-
readonly BLUE='\033[0;34m'
12-
readonly PURPLE='\033[0;35m'
13-
readonly CYAN='\033[0;36m'
14-
readonly WHITE='\033[1;37m'
15-
readonly NC='\033[0m' # No Color
16-
17-
# Logging functions
18-
log_info() {
19-
echo -e "${BLUE}ℹ️ $1${NC}"
20-
}
21-
22-
log_success() {
23-
echo -e "${GREEN}$1${NC}"
24-
}
25-
26-
log_warning() {
27-
echo -e "${YELLOW}⚠️ $1${NC}"
28-
}
29-
30-
log_error() {
31-
echo -e "${RED}$1${NC}"
32-
}
33-
34-
log_step() {
35-
echo -e "${PURPLE}🚀 $1${NC}"
36-
}
37-
385
# Get script directory
396
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
407

8+
source "${here}/../scripts/common.sh"
9+
4110
log_step "Starting Grounds Development Infrastructure cluster bootstrap..."
4211

4312
# Check prerequisites
@@ -194,17 +163,6 @@ else
194163
log_info "To enable GHCR authentication, set GHCR_USERNAME and GHCR_TOKEN in your .env file"
195164
fi
196165

197-
# Add Helm repositories
198-
log_step "Adding Helm repositories..."
199-
helm repo add bitnami https://charts.bitnami.com/bitnami
200-
helm repo add agones https://agones.dev/chart/stable
201-
log_success "Helm repositories added"
202-
203-
# Update Helm repositories
204-
log_info "Updating Helm repository cache..."
205-
helm repo update
206-
log_success "Helm repositories updated"
207-
208166
# Verify cluster is ready with retry
209167
log_info "Verifying cluster readiness..."
210168
max_retries=5
@@ -231,7 +189,7 @@ fi
231189

232190
log_step "Bootstrap completed successfully! 🎉"
233191
log_info "Next steps:"
234-
echo -e " ${CYAN}${NC} Run ${WHITE}make up${NC} to deploy the full stack"
235-
echo -e " ${CYAN}${NC} Run ${WHITE}make status${NC} to check deployment status"
236-
echo -e " ${CYAN}${NC} Access services at ${WHITE}http://localhost${NC}"
237-
echo -e " ${CYAN}${NC} Use kubeconfig: ${WHITE}export KUBECONFIG=\$(pwd)/kubeconfig${NC}"
192+
log_info " Run 'make up' to deploy the full stack"
193+
log_info " Run 'make status' to check deployment status"
194+
log_info " Access services at 'http://localhost'"
195+
log_info " Use kubeconfig: 'export KUBECONFIG=\$(pwd)/kubeconfig'"

scripts/common.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Colors and emojis for log output
2+
readonly RED='\033[0;31m'
3+
readonly GREEN='\033[0;32m'
4+
readonly YELLOW='\033[1;33m'
5+
readonly BLUE='\033[0;34m'
6+
readonly PURPLE='\033[0;35m'
7+
readonly NC='\033[0m' # No Color
8+
9+
# Logging functions
10+
log_info() {
11+
echo -e "${BLUE}ℹ️ $1${NC}"
12+
}
13+
14+
log_success() {
15+
echo -e "${GREEN}$1${NC}"
16+
}
17+
18+
log_warning() {
19+
echo -e "${YELLOW}⚠️ $1${NC}"
20+
}
21+
22+
log_error() {
23+
echo -e "${RED}$1${NC}"
24+
}
25+
26+
log_step() {
27+
echo -e "${PURPLE}🚀 $1${NC}"
28+
}

scripts/install-prereqs.sh

Lines changed: 28 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,26 @@
11
#!/usr/bin/env bash
2-
# Prerequisites installation script for Grounds Development Infrastructure
3-
# Automatically installs missing dependencies for local Kubernetes development
42

53
set -euo pipefail
64

7-
# Colors and emojis for fancy console output
8-
readonly RED='\033[0;31m'
9-
readonly GREEN='\033[0;32m'
10-
readonly YELLOW='\033[1;33m'
11-
readonly BLUE='\033[0;34m'
12-
readonly PURPLE='\033[0;35m'
13-
readonly CYAN='\033[0;36m'
14-
readonly WHITE='\033[1;37m'
15-
readonly NC='\033[0m' # No Color
16-
17-
# Logging functions
18-
log_info() {
19-
echo -e "${BLUE}ℹ️ $1${NC}"
20-
}
21-
22-
log_success() {
23-
echo -e "${GREEN}$1${NC}"
24-
}
25-
26-
log_warning() {
27-
echo -e "${YELLOW}⚠️ $1${NC}"
28-
}
29-
30-
log_error() {
31-
echo -e "${RED}$1${NC}"
32-
}
33-
34-
log_step() {
35-
echo -e "${PURPLE}🚀 $1${NC}"
36-
}
5+
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
source "${here}/common.sh"
377

388
# Check if command exists
399
command_exists() {
40-
command -v "$1" >/dev/null 2>&1
10+
if command -v "$1" >/dev/null 2>&1; then
11+
echo 0
12+
else
13+
echo 1
14+
fi
4115
}
4216

4317
# Detect OS
4418
detect_os() {
4519
if [[ "${OSTYPE}" == "linux-gnu"* ]]; then
4620
local has_apt has_yum has_pacman
47-
command_exists apt-get
48-
has_apt=$?
49-
command_exists yum
50-
has_yum=$?
51-
command_exists pacman
52-
has_pacman=$?
21+
has_apt=$(command_exists apt-get)
22+
has_yum=$(command_exists yum)
23+
has_pacman=$(command_exists pacman)
5324

5425
if [[ "${has_apt}" -eq 0 ]]; then
5526
echo "ubuntu"
@@ -77,8 +48,7 @@ install_docker() {
7748
case "${os}" in
7849
"ubuntu")
7950
local docker_exists
80-
command_exists docker
81-
docker_exists=$?
51+
docker_exists=$(command_exists docker)
8252
if [[ "${docker_exists}" -ne 0 ]]; then
8353
curl -fsSL https://get.docker.com | sh
8454
sudo usermod -aG docker "${USER}"
@@ -89,8 +59,7 @@ install_docker() {
8959
;;
9060
"macos")
9161
local docker_exists
92-
command_exists docker
93-
docker_exists=$?
62+
docker_exists=$(command_exists docker)
9463
if [[ "${docker_exists}" -ne 0 ]]; then
9564
log_warning "Please install Docker Desktop for macOS from https://www.docker.com/products/docker-desktop"
9665
log_info "Or install via Homebrew: brew install --cask docker"
@@ -107,8 +76,7 @@ install_docker() {
10776
# Install k3d
10877
install_k3d() {
10978
local k3d_exists
110-
command_exists k3d
111-
k3d_exists=$?
79+
k3d_exists=$(command_exists k3d)
11280
if [[ "${k3d_exists}" -ne 0 ]]; then
11381
log_info "Installing k3d..."
11482
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
@@ -121,8 +89,7 @@ install_k3d() {
12189
# Install kubectl
12290
install_kubectl() {
12391
local kubectl_exists
124-
command_exists kubectl
125-
kubectl_exists=$?
92+
kubectl_exists=$(command_exists kubectl)
12693
if [[ "${kubectl_exists}" -ne 0 ]]; then
12794
log_info "Installing kubectl..."
12895
local kubectl_version=$(curl -L -s https://dl.k8s.io/release/stable.txt)
@@ -138,8 +105,7 @@ install_kubectl() {
138105
# Install Helm
139106
install_helm() {
140107
local helm_exists
141-
command_exists helm
142-
helm_exists=$?
108+
helm_exists=$(command_exists helm)
143109
if [[ "${helm_exists}" -ne 0 ]]; then
144110
log_info "Installing Helm..."
145111
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
@@ -152,13 +118,15 @@ install_helm() {
152118
# Install Helmfile
153119
install_helmfile() {
154120
local helmfile_exists
155-
command_exists helmfile
156-
helmfile_exists=$?
121+
helmfile_exists=$(command_exists helmfile)
157122
if [[ "${helmfile_exists}" -ne 0 ]]; then
158123
log_info "Installing Helmfile..."
159-
local helmfile_version="v0.156.0"
160-
curl -L "https://github.com/helmfile/helmfile/releases/download/${helmfile_version}/helmfile_${helmfile_version#v}_linux_amd64.tar.gz" | tar xz
161-
sudo mv helmfile /usr/local/bin/
124+
local helmfile_version="v1.2.3"
125+
local tmp_dir
126+
tmp_dir="$(mktemp -d)"
127+
curl -L "https://github.com/helmfile/helmfile/releases/download/${helmfile_version}/helmfile_${helmfile_version#v}_linux_amd64.tar.gz" | tar -xz -C "${tmp_dir}"
128+
sudo mv "${tmp_dir}/helmfile" /usr/local/bin/
129+
rm -rf "${tmp_dir}"
162130
log_success "Helmfile installed"
163131
else
164132
log_success "Helmfile already installed"
@@ -197,18 +165,12 @@ check_prereqs() {
197165
local missing=()
198166
local docker_exists k3d_exists kubectl_exists helm_exists helmfile_exists devspace_exists
199167

200-
command_exists docker
201-
docker_exists=$?
202-
command_exists k3d
203-
k3d_exists=$?
204-
command_exists kubectl
205-
kubectl_exists=$?
206-
command_exists helm
207-
helm_exists=$?
208-
command_exists helmfile
209-
helmfile_exists=$?
210-
command_exists devspace
211-
devspace_exists=$?
168+
docker_exists=$(command_exists docker)
169+
k3d_exists=$(command_exists k3d)
170+
kubectl_exists=$(command_exists kubectl)
171+
helm_exists=$(command_exists helm)
172+
helmfile_exists=$(command_exists helmfile)
173+
devspace_exists=$(command_exists devspace)
212174

213175
if [[ "${docker_exists}" -ne 0 ]]; then
214176
missing+=("docker")

scripts/kubehelpers.sh

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,9 @@
11
#!/usr/bin/env bash
2-
# Kubernetes helper utilities with fancy console output
3-
# Provides common kubectl operations with colored logging
42

53
set -euo pipefail
64

7-
# Colors and emojis for fancy console output
8-
readonly RED='\033[0;31m'
9-
readonly GREEN='\033[0;32m'
10-
readonly YELLOW='\033[1;33m'
11-
readonly BLUE='\033[0;34m'
12-
readonly PURPLE='\033[0;35m'
13-
readonly CYAN='\033[0;36m'
14-
readonly WHITE='\033[1;37m'
15-
readonly NC='\033[0m' # No Color
16-
17-
# Logging functions
18-
log_info() {
19-
echo -e "${BLUE}ℹ️ $1${NC}"
20-
}
21-
22-
log_success() {
23-
echo -e "${GREEN}$1${NC}"
24-
}
25-
26-
log_warning() {
27-
echo -e "${YELLOW}⚠️ $1${NC}"
28-
}
29-
30-
log_error() {
31-
echo -e "${RED}$1${NC}"
32-
}
33-
34-
log_step() {
35-
echo -e "${PURPLE}🚀 $1${NC}"
36-
}
5+
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
source "${here}/common.sh"
377

388
# Check if kubectl is available
399
check_kubectl() {
@@ -57,13 +27,16 @@ check_cluster() {
5727
get_cluster_status() {
5828
log_step "Getting cluster status..."
5929

60-
echo -e "\n${CYAN}📊 Cluster Nodes:${NC}"
30+
echo ""
31+
log_info "📊 Cluster Nodes:"
6132
kubectl get nodes -o wide
6233

63-
echo -e "\n${CYAN}📦 All Pods:${NC}"
34+
echo ""
35+
log_info "📦 All Pods:"
6436
kubectl get pods -A
6537

66-
echo -e "\n${CYAN}🔧 Services:${NC}"
38+
echo ""
39+
log_info "🔧 Services:"
6740
kubectl get services -A
6841
}
6942

@@ -155,8 +128,8 @@ main() {
155128
port_forward "$2" "$3" "$4" "$5"
156129
;;
157130
"help"|*)
158-
echo -e "${WHITE}Kubernetes Helper Script${NC}"
159-
echo -e "${CYAN}Usage:${NC}"
131+
log_info "Kubernetes Helper Script"
132+
log_info "Usage:"
160133
echo " $0 status - Get cluster status"
161134
echo " $0 wait-pods <ns> <selector> - Wait for pods to be ready"
162135
echo " $0 check-ns <namespace> - Check if namespace exists"

scripts/wait-for-crds.sh

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,17 @@
11
#!/usr/bin/env bash
2-
# Wait for Agones CRDs to be ready
3-
# Provides fancy console output with spinner and progress indicators
42

53
set -euo pipefail
64

7-
# Colors and emojis for fancy console output
8-
readonly RED='\033[0;31m'
9-
readonly GREEN='\033[0;32m'
10-
readonly YELLOW='\033[1;33m'
11-
readonly BLUE='\033[0;34m'
12-
readonly PURPLE='\033[0;35m'
13-
readonly CYAN='\033[0;36m'
14-
readonly WHITE='\033[1;37m'
15-
readonly NC='\033[0m' # No Color
5+
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
source "${here}/common.sh"
167

178
# Spinner characters
189
spinner_chars=("" "" "" "" "" "" "" "" "" "")
1910
spinner_index=0
2011

21-
# Logging functions
22-
log_info() {
23-
echo -e "${BLUE}ℹ️ $1${NC}"
24-
}
25-
26-
log_success() {
27-
echo -e "${GREEN}$1${NC}"
28-
}
29-
30-
log_warning() {
31-
echo -e "${YELLOW}⚠️ $1${NC}"
32-
}
33-
34-
log_error() {
35-
echo -e "${RED}$1${NC}"
36-
}
37-
3812
# Spinner function
3913
show_spinner() {
40-
printf "\r%s%s%s %s" "${PURPLE}" "${spinner_chars[${spinner_index}]}" "${NC}" "$1"
14+
printf "\r%s %s" "${spinner_chars[${spinner_index}]}" "$1"
4115
spinner_index=$(( (spinner_index + 1) % ${#spinner_chars[@]} ))
4216
}
4317

values/agones.values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ agones:
1515
service:
1616
http:
1717
port: 10443
18+
targetPort: 8443
1819
grpc:
1920
port: 10444
21+
targetPort: 8444
2022

2123
# Controller configuration
2224
controller:

0 commit comments

Comments
 (0)