-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
Β·139 lines (118 loc) Β· 5.11 KB
/
setup.sh
File metadata and controls
executable file
Β·139 lines (118 loc) Β· 5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
# Cascade GKE Setup Script
# This script automates the setup of the GKE cluster and deployment of the Cascade application.
set -e
# Configuration
PROJECT_ID=$1
REGION=${2:-"europe-west1"}
CLUSTER_NAME=${3:-"cascade-cluster"}
REPO_NAME="cascade"
# Try to get project ID from gcloud if not provided
if [ -z "$PROJECT_ID" ]; then
if command -v gcloud >/dev/null 2>&1; then
PROJECT_ID=$(gcloud config get-value project 2>/dev/null)
fi
fi
if [ -z "$PROJECT_ID" ]; then
echo "Error: Could not determine PROJECT_ID. Please provide it as the first argument or set it in gcloud config."
echo "Usage: ./setup.sh <PROJECT_ID> [REGION] [CLUSTER_NAME]"
exit 1
fi
echo "π Starting Cascade GKE Setup..."
echo "Project: $PROJECT_ID"
echo "Region: $REGION"
echo "Cluster: $CLUSTER_NAME"
# 1. Prerequisites Check
echo "------------------------------------------------"
echo "π Checking prerequisites..."
command -v gcloud >/dev/null 2>&1 || { echo >&2 "gcloud is required but not installed. Aborting."; exit 1; }
command -v kubectl >/dev/null 2>&1 || { echo >&2 "kubectl is required but not installed. Aborting."; exit 1; }
command -v helm >/dev/null 2>&1 || { echo >&2 "helm is required but not installed. Aborting."; exit 1; }
echo "β
Prerequisites met."
# 2. GKE Cluster Creation
echo "------------------------------------------------"
echo "ποΈ Creating GKE Cluster (this may take a few minutes)..."
# Check if cluster exists
if gcloud container clusters describe $CLUSTER_NAME --region $REGION --project $PROJECT_ID >/dev/null 2>&1; then
echo "Cluster $CLUSTER_NAME already exists. Skipping creation."
else
gcloud container clusters create $CLUSTER_NAME \
--region $REGION \
--project $PROJECT_ID \
--num-nodes 1 \
--machine-type e2-standard-4 \
--enable-autoscaling --min-nodes 1 --max-nodes 3
fi
# Get Credentials
echo "π Getting cluster credentials..."
gcloud container clusters get-credentials $CLUSTER_NAME --region $REGION --project $PROJECT_ID
# 3. Helm Repositories
echo "------------------------------------------------"
echo "π¦ Adding Helm repositories..."
helm repo add strimzi https://strimzi.io/charts/
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo add jetstack https://charts.jetstack.io
helm repo add provectus https://provectus.github.io/kafka-ui-charts
helm repo update
# 4. Infrastructure Installation
echo "------------------------------------------------"
echo "π Installing Nginx Ingress Controller..."
helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx \
--namespace ingress-nginx --create-namespace
echo "π Installing Cert-Manager (Optional for Extra Points)..."
helm upgrade --install cert-manager jetstack/cert-manager \
--namespace cert-manager --create-namespace \
--version v1.13.3 \
--set installCRDs=true
# 5. Build and Push Images
echo "------------------------------------------------"
echo "π³ Building and Pushing Docker Images..."
# Ensure Artifact Registry exists
if ! gcloud artifacts repositories describe $REPO_NAME --location=$REGION --project=$PROJECT_ID >/dev/null 2>&1; then
echo "Creating Artifact Registry repository..."
gcloud artifacts repositories create $REPO_NAME \
--repository-format=docker \
--location=$REGION \
--description="Cascade Docker Repository" \
--project=$PROJECT_ID
fi
# Run build script
./build-and-push.sh $PROJECT_ID $REGION $REPO_NAME "latest"
# 6. Deploy Cascade
echo "------------------------------------------------"
echo "π Deploying Cascade Helm Chart..."
# Update dependencies
helm dependency update helm/cascade
# Install/Upgrade
helm upgrade --install cascade helm/cascade \
--set app.image.repository="$REGION-docker.pkg.dev/$PROJECT_ID/$REPO_NAME" \
--set app.image.tag="latest"
echo "------------------------------------------------"
echo "β
Setup Complete!"
echo "To get the external IP of the Ingress:"
echo "kubectl get svc -n ingress-nginx ingress-nginx-controller"
echo "Then map that IP to 'cascade.local' in your /etc/hosts file OR access it directly via the IP."
echo "------------------------------------------------"
echo "π Configuring Auth Service with Ingress IP..."
# Wait for Ingress IP
INGRESS_IP=""
echo "Waiting for Ingress External IP..."
while [ -z "$INGRESS_IP" ]; do
INGRESS_IP=$(kubectl get svc -n ingress-nginx ingress-nginx-controller -o jsonpath='{.status.loadBalancer.ingress[0].ip}' 2>/dev/null || true)
if [ -z "$INGRESS_IP" ]; then
sleep 5
fi
done
echo "Ingress IP: $INGRESS_IP"
echo "Updating cascade-auth deployment with BASE_URL and TRUSTED_ORIGINS..."
BASE_URL="http://$INGRESS_IP.nip.io"
kubectl set env deployment/cascade-auth \
BASE_URL="$BASE_URL" \
TRUSTED_ORIGINS="http://$INGRESS_IP,http://$INGRESS_IP.nip.io"
echo "β
Auth service configured."
echo "π GitHub OAuth Callback URL: $BASE_URL/api/auth/callback/github"
echo "------------------------------------------------"
echo "To access Kafka UI:"
echo "kubectl port-forward svc/cascade-kafka-ui 8080:80"
echo "Then open http://localhost:8080"
echo "------------------------------------------------"