-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·257 lines (221 loc) · 10.1 KB
/
deploy.sh
File metadata and controls
executable file
·257 lines (221 loc) · 10.1 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/bin/bash
# ============================================
# Teable Azure AKS - One-Click Deployment
# ============================================
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Banner
echo -e "${CYAN}"
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ 🚀 Teable Azure AKS One-Click Deployment ║"
echo "║ ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
# Check prerequisites
check_prerequisites() {
echo -e "${BLUE}▶ Checking prerequisites...${NC}"
echo ""
local missing=0
# Check Azure CLI
if command -v az &> /dev/null; then
echo -e " ${GREEN}✓${NC} Azure CLI installed"
else
echo -e " ${RED}✗${NC} Azure CLI not installed"
echo -e " Install: ${CYAN}brew install azure-cli${NC} (macOS)"
echo -e " Or visit: https://docs.microsoft.com/cli/azure/install-azure-cli"
missing=1
fi
# Check Terraform
if command -v terraform &> /dev/null; then
echo -e " ${GREEN}✓${NC} Terraform installed"
else
echo -e " ${RED}✗${NC} Terraform not installed"
echo -e " Install: ${CYAN}brew install terraform${NC} (macOS)"
echo -e " Or visit: https://www.terraform.io/downloads"
missing=1
fi
# Check kubectl
if command -v kubectl &> /dev/null; then
echo -e " ${GREEN}✓${NC} kubectl installed"
else
echo -e " ${RED}✗${NC} kubectl not installed"
echo -e " Install: ${CYAN}brew install kubectl${NC} (macOS)"
echo -e " Or visit: https://kubernetes.io/docs/tasks/tools/"
missing=1
fi
if [ $missing -eq 1 ]; then
echo ""
echo -e "${RED}Please install the missing tools and run this script again${NC}"
exit 1
fi
# Check Azure login
echo ""
echo -e "${BLUE}▶ Checking Azure login status...${NC}"
if az account show &> /dev/null; then
local account=$(az account show --query name -o tsv)
echo -e " ${GREEN}✓${NC} Logged in to Azure: ${CYAN}$account${NC}"
else
echo -e " ${YELLOW}!${NC} Not logged in to Azure, opening login..."
az login
fi
echo ""
echo -e "${GREEN}✓ Prerequisites check passed${NC}"
}
# Check configuration
check_config() {
echo ""
echo -e "${BLUE}▶ Checking configuration file...${NC}"
if [ ! -f "terraform.tfvars" ]; then
echo -e " ${YELLOW}!${NC} Configuration file not found, creating..."
cp terraform.tfvars.example terraform.tfvars
echo ""
echo -e "${YELLOW}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${YELLOW}║ ⚠️ Please edit terraform.tfvars to set your domain ║${NC}"
echo -e "${YELLOW}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e " Open file: ${CYAN}$SCRIPT_DIR/terraform.tfvars${NC}"
echo ""
echo -e " At minimum, change:"
echo -e " ${CYAN}teable_domain = \"your-domain.com\"${NC}"
echo ""
echo -e " When done, run again: ${CYAN}./deploy.sh${NC}"
exit 0
fi
# Check if domain is configured
local domain=$(grep -E "^teable_domain" terraform.tfvars | grep -v "example.com" | head -1)
if [ -z "$domain" ]; then
echo -e " ${YELLOW}!${NC} Domain may not be configured"
echo ""
read -p " Have you updated teable_domain? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e " Please edit ${CYAN}terraform.tfvars${NC} to set your domain"
exit 0
fi
fi
echo -e " ${GREEN}✓${NC} Configuration file ready"
}
# Main deployment
deploy() {
echo ""
echo -e "${BLUE}▶ Step 1/5: Initializing Terraform...${NC}"
terraform init -upgrade > /dev/null 2>&1
echo -e " ${GREEN}✓${NC} Initialization complete"
echo ""
echo -e "${BLUE}▶ Step 2/5: Validating configuration...${NC}"
if terraform validate > /dev/null 2>&1; then
echo -e " ${GREEN}✓${NC} Configuration valid"
else
echo -e " ${RED}✗${NC} Configuration validation failed"
terraform validate
exit 1
fi
echo ""
echo -e "${BLUE}▶ Step 3/5: Planning deployment...${NC}"
echo ""
terraform plan -out=tfplan
echo ""
echo -e "${YELLOW}════════════════════════════════════════════════════════════${NC}"
echo -e "${YELLOW} ⚠️ About to create Azure resources (this will incur costs)${NC}"
echo -e "${YELLOW}════════════════════════════════════════════════════════════${NC}"
echo ""
read -p "Confirm deployment? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "${YELLOW}Deployment cancelled${NC}"
rm -f tfplan
exit 0
fi
echo ""
echo -e "${BLUE}▶ Step 4/5: Deploying resources (takes ~15-20 minutes)...${NC}"
echo ""
echo -e " ${CYAN}☕ This takes a while, grab a coffee...${NC}"
echo ""
terraform apply tfplan
echo -e " ${GREEN}✓${NC} Resource deployment complete"
# Get cluster credentials and setup ingress
echo ""
echo -e "${BLUE}▶ Step 5/5: Configuring Kubernetes and Ingress...${NC}"
local RG_NAME=$(terraform output -raw resource_group_name 2>/dev/null)
local AKS_NAME=$(terraform output -raw aks_cluster_name 2>/dev/null)
local TEABLE_DOMAIN=$(terraform output -raw teable_url 2>/dev/null | sed 's|https://||')
# Get AKS credentials
echo -e " Getting cluster credentials..."
az aks get-credentials --resource-group "$RG_NAME" --name "$AKS_NAME" --overwrite-existing > /dev/null 2>&1
# Install NGINX Ingress Controller
echo -e " Installing Ingress Controller..."
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.9.4/deploy/static/provider/cloud/deploy.yaml > /dev/null 2>&1
# Wait for ingress controller
echo -e " Waiting for Ingress Controller to be ready..."
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=120s > /dev/null 2>&1 || true
# Generate and apply ingress
echo -e " Configuring Ingress rules..."
sed "s/\${teable_domain}/$TEABLE_DOMAIN/g" ingress.yaml.tpl > ingress.yaml
kubectl apply -f ingress.yaml > /dev/null 2>&1
echo -e " ${GREEN}✓${NC} Ingress configuration complete"
# Get Ingress IP
echo ""
echo -e " ${CYAN}Waiting for external IP...${NC}"
sleep 30
local INGRESS_IP=$(kubectl get svc -n ingress-nginx ingress-nginx-controller -o jsonpath='{.status.loadBalancer.ingress[0].ip}' 2>/dev/null || echo "")
# Clean up
rm -f tfplan
# Final output
echo ""
echo -e "${GREEN}"
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ 🎉 Deployment Complete! ║"
echo "║ ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
echo -e "${BLUE}📍 Resources Created:${NC}"
echo -e " • Resource Group: ${CYAN}$RG_NAME${NC}"
echo -e " • AKS Cluster: ${CYAN}$AKS_NAME${NC}"
echo -e " • PostgreSQL: ${CYAN}$(terraform output -raw postgresql_fqdn 2>/dev/null)${NC}"
echo -e " • Redis: ${CYAN}$(terraform output -raw redis_hostname 2>/dev/null)${NC}"
echo ""
if [ -n "$INGRESS_IP" ]; then
echo -e "${BLUE}🌐 External IP Address:${NC}"
echo -e " ${GREEN}$INGRESS_IP${NC}"
echo ""
echo -e "${YELLOW}📋 Next Step - Configure DNS:${NC}"
echo -e " Add an A record in your domain's DNS settings:"
echo ""
echo -e " ${CYAN}$TEABLE_DOMAIN${NC} → ${GREEN}$INGRESS_IP${NC}"
echo ""
else
echo -e "${YELLOW}📋 Get External IP:${NC}"
echo -e " IP is still being provisioned. Run this command to check:"
echo -e " ${CYAN}kubectl get svc -n ingress-nginx ingress-nginx-controller${NC}"
echo ""
fi
echo -e "${BLUE}🔗 Access Teable:${NC}"
echo -e " https://$TEABLE_DOMAIN"
echo ""
echo -e "${BLUE}📊 Useful Commands:${NC}"
echo -e " Check pod status: ${CYAN}kubectl get pods -n teable${NC}"
echo -e " View logs: ${CYAN}kubectl logs -n teable -l app=teable -f${NC}"
echo -e " Check auto-scaling: ${CYAN}kubectl get hpa -n teable${NC}"
echo ""
echo -e "${YELLOW}💡 Tip: View passwords and other sensitive info${NC}"
echo -e " ${CYAN}terraform output -json${NC}"
echo ""
}
# Run
check_prerequisites
check_config
deploy