-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-supabase-vercel.sh
More file actions
executable file
Β·324 lines (265 loc) Β· 8.49 KB
/
deploy-supabase-vercel.sh
File metadata and controls
executable file
Β·324 lines (265 loc) Β· 8.49 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/bin/bash
# ============================================================
# Deployment Script: Supabase + Vercel Migration
# City Service Provider Application
# ============================================================
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to check required tools
check_requirements() {
print_status "Checking required tools..."
local missing_tools=()
if ! command_exists "node"; then
missing_tools+=("node")
fi
if ! command_exists "npm"; then
missing_tools+=("npm")
fi
if ! command_exists "supabase"; then
missing_tools+=("supabase")
fi
if ! command_exists "vercel"; then
missing_tools+=("vercel")
fi
if [ ${#missing_tools[@]} -ne 0 ]; then
print_error "Missing required tools: ${missing_tools[*]}"
echo "Please install the missing tools and try again."
echo ""
echo "Installation commands:"
echo " Node.js & npm: https://nodejs.org/"
echo " Supabase CLI: npm install -g supabase"
echo " Vercel CLI: npm install -g vercel"
exit 1
fi
print_success "All required tools are installed"
}
# Function to setup Supabase project
setup_supabase() {
print_status "Setting up Supabase project..."
# Check if already logged in
if ! supabase projects list >/dev/null 2>&1; then
print_status "Please log in to Supabase..."
supabase login
fi
# Initialize Supabase project if not already done
if [ ! -f "supabase/config.toml" ]; then
print_status "Initializing Supabase project..."
supabase init
fi
# Start local Supabase (for development)
print_status "Starting local Supabase instance..."
supabase start
# Run migrations
print_status "Running database migrations..."
supabase db reset
print_success "Supabase setup completed"
}
# Function to deploy Edge Functions
deploy_edge_functions() {
print_status "Deploying Edge Functions..."
# Deploy all functions
for func_dir in supabase/functions/*/; do
if [ -d "$func_dir" ]; then
func_name=$(basename "$func_dir")
print_status "Deploying function: $func_name"
supabase functions deploy "$func_name"
fi
done
print_success "Edge Functions deployed"
}
# Function to setup frontend
setup_frontend() {
print_status "Setting up frontend..."
cd frontend
# Install dependencies
print_status "Installing frontend dependencies..."
npm install
# Add Supabase dependencies
print_status "Installing Supabase client..."
npm install @supabase/supabase-js @supabase/auth-helpers-react
# Create environment file if it doesn't exist
if [ ! -f ".env.local" ]; then
print_warning ".env.local not found. Creating from example..."
cp env.supabase.example .env.local
print_warning "Please update .env.local with your Supabase credentials"
fi
# Build the project
print_status "Building frontend..."
npm run build
cd ..
print_success "Frontend setup completed"
}
# Function to deploy to Vercel
deploy_vercel() {
print_status "Deploying to Vercel..."
cd frontend
# Check if already logged in to Vercel
if ! vercel whoami >/dev/null 2>&1; then
print_status "Please log in to Vercel..."
vercel login
fi
# Deploy to Vercel
print_status "Deploying to Vercel..."
vercel --prod
cd ..
print_success "Vercel deployment completed"
}
# Function to run tests
run_tests() {
print_status "Running tests..."
cd frontend
# Run frontend tests
if [ -f "package.json" ] && grep -q '"test"' package.json; then
print_status "Running frontend tests..."
npm test -- --watchAll=false --coverage=false
fi
cd ..
print_success "Tests completed"
}
# Function to validate deployment
validate_deployment() {
print_status "Validating deployment..."
# Check Supabase connection
print_status "Checking Supabase connection..."
if supabase status >/dev/null 2>&1; then
print_success "Supabase is running"
else
print_warning "Supabase connection issues detected"
fi
# Check if frontend build exists
if [ -d "frontend/build" ]; then
print_success "Frontend build exists"
else
print_warning "Frontend build not found"
fi
print_success "Deployment validation completed"
}
# Function to display post-deployment information
show_deployment_info() {
echo ""
echo "============================================================"
echo "π DEPLOYMENT COMPLETED SUCCESSFULLY!"
echo "============================================================"
echo ""
echo "π Next Steps:"
echo ""
echo "1. π§ Configure Environment Variables:"
echo " - Update frontend/.env.local with your Supabase credentials"
echo " - Set Vercel environment variables in the dashboard"
echo ""
echo "2. ποΈ Database Setup:"
echo " - Run the data migration script in Supabase SQL Editor"
echo " - Configure Row Level Security policies"
echo " - Set up storage buckets"
echo ""
echo "3. π Authentication Setup:"
echo " - Configure auth providers in Supabase dashboard"
echo " - Set up email templates"
echo " - Configure redirect URLs"
echo ""
echo "4. π Go Live:"
echo " - Test all functionality"
echo " - Update DNS settings (if using custom domain)"
echo " - Monitor logs and performance"
echo ""
echo "π Documentation:"
echo " - Migration Plan: SUPABASE_VERCEL_MIGRATION_PLAN.md"
echo " - Supabase Docs: https://supabase.com/docs"
echo " - Vercel Docs: https://vercel.com/docs"
echo ""
echo "π Support:"
echo " - Check logs: supabase logs"
echo " - Vercel logs: vercel logs"
echo " - GitHub Issues: Create an issue for help"
echo ""
echo "============================================================"
}
# Main deployment function
main() {
echo "============================================================"
echo "π SUPABASE + VERCEL DEPLOYMENT"
echo "City Service Provider Application"
echo "============================================================"
echo ""
# Parse command line arguments
SKIP_SUPABASE=false
SKIP_VERCEL=false
SKIP_TESTS=false
while [[ $# -gt 0 ]]; do
case $1 in
--skip-supabase)
SKIP_SUPABASE=true
shift
;;
--skip-vercel)
SKIP_VERCEL=true
shift
;;
--skip-tests)
SKIP_TESTS=true
shift
;;
--help)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --skip-supabase Skip Supabase setup and deployment"
echo " --skip-vercel Skip Vercel deployment"
echo " --skip-tests Skip running tests"
echo " --help Show this help message"
echo ""
exit 0
;;
*)
print_error "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Run deployment steps
check_requirements
if [ "$SKIP_SUPABASE" = false ]; then
setup_supabase
deploy_edge_functions
else
print_warning "Skipping Supabase setup"
fi
setup_frontend
if [ "$SKIP_TESTS" = false ]; then
run_tests
else
print_warning "Skipping tests"
fi
if [ "$SKIP_VERCEL" = false ]; then
deploy_vercel
else
print_warning "Skipping Vercel deployment"
fi
validate_deployment
show_deployment_info
}
# Run main function with all arguments
main "$@"