-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.sh
More file actions
224 lines (193 loc) · 6 KB
/
quickstart.sh
File metadata and controls
224 lines (193 loc) · 6 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
#!/bin/bash
# BrainSAIT B2B Quick Start Script
# One-command deployment with Zapier integration
set -e
echo "🚀 BrainSAIT B2B Platform - Quick Start"
echo "======================================"
echo ""
# Check if Docker is running
if ! docker info > /dev/null 2>&1; then
echo "❌ Docker is not running. Please start Docker Desktop first."
exit 1
fi
echo "✅ Docker is running"
# Create environment file
if [ ! -f .env ]; then
echo "📝 Creating environment configuration..."
cat > .env << 'EOF'
# BrainSAIT B2B Environment
ENVIRONMENT=development
# Database
DB_PASSWORD=BrainSAIT2024!
REDIS_PASSWORD=Redis2024!
# Security
SECRET_KEY=$(openssl rand -hex 32 || echo "dev-secret-key-change-in-production")
JWT_SECRET=$(openssl rand -hex 32 || echo "dev-jwt-secret-change-in-production")
# Zapier Integration
ZAPIER_APP_KEY=brainsait_app_key
ZAPIER_WEBHOOK_URL=https://hooks.zapier.com/hooks/catch/
# Payment Gateways
STRIPE_SECRET_KEY=sk_test_51234567890
STRIPE_PUBLISHABLE_KEY=pk_test_51234567890
MADA_MERCHANT_ID=MADA_TEST_MERCHANT
MADA_API_KEY=mada_test_key
# Cloudflare
CLOUDFLARE_ACCOUNT_ID=519d80ce438f427d096a3e3bdd98a7e0
CLOUDFLARE_API_TOKEN=your_token_here
# Default Admin
ADMIN_EMAIL=admin@brainsait.com
ADMIN_PASSWORD=Admin2024!
EOF
echo "✅ Environment file created"
else
echo "✅ Environment file exists"
fi
# Pull required Docker images
echo "📦 Pulling Docker images..."
docker pull postgres:15-alpine
docker pull redis:7-alpine
docker pull nginx:alpine
# Start core services only
echo "🔧 Starting core services..."
docker-compose up -d postgres redis
# Wait for PostgreSQL to be ready
echo "⏳ Waiting for database..."
sleep 5
# Initialize database
echo "🗄️ Initializing database..."
docker-compose exec -T postgres psql -U brainsait -d brainsait_b2b << 'SQL'
-- Create schemas for multi-tenancy
CREATE SCHEMA IF NOT EXISTS public;
CREATE SCHEMA IF NOT EXISTS tenant_demo;
-- Enable extensions
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
-- Create tenants table
CREATE TABLE IF NOT EXISTS public.tenants (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name VARCHAR(255) NOT NULL,
subdomain VARCHAR(100) UNIQUE NOT NULL,
plan VARCHAR(50) DEFAULT 'starter',
zapier_webhook_url TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Create demo tenant
INSERT INTO public.tenants (name, subdomain, plan)
VALUES ('Demo Company', 'demo', 'starter')
ON CONFLICT (subdomain) DO NOTHING;
-- Create API keys table
CREATE TABLE IF NOT EXISTS public.api_keys (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
tenant_id UUID REFERENCES public.tenants(id),
key_hash VARCHAR(255) NOT NULL,
name VARCHAR(100),
last_used TIMESTAMP,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
GRANT ALL PRIVILEGES ON SCHEMA public TO brainsait;
GRANT ALL PRIVILEGES ON SCHEMA tenant_demo TO brainsait;
SQL
echo "✅ Database initialized"
# Create quick API test
echo "🧪 Creating API test endpoint..."
mkdir -p test-api
cat > test-api/server.js << 'EOF'
const express = require('express');
const app = express();
app.use(express.json());
// CORS for Zapier
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
if (req.method === 'OPTIONS') return res.sendStatus(200);
next();
});
// Root endpoint
app.get('/', (req, res) => {
res.json({
message: 'BrainSAIT B2B API',
version: '1.0.0',
endpoints: {
health: '/health',
zapier_webhook: '/webhooks/zapier',
test_trigger: '/trigger/test'
}
});
});
// Health check
app.get('/health', (req, res) => {
res.json({ status: 'healthy', timestamp: new Date() });
});
// Zapier webhook receiver
app.post('/webhooks/zapier', (req, res) => {
console.log('Zapier webhook received:', req.body);
res.json({
status: 'received',
data: req.body,
message: 'Webhook processed successfully'
});
});
// Test trigger for Zapier
app.post('/trigger/test', (req, res) => {
const testData = {
id: 'test_' + Date.now(),
type: 'test_event',
data: {
customer: 'أحمد محمد',
amount: 2999,
currency: 'SAR',
timestamp: new Date()
}
};
console.log('Triggering test event:', testData);
res.json(testData);
});
const PORT = process.env.PORT || 8000;
app.listen(PORT, () => {
console.log(`🚀 BrainSAIT API running on http://localhost:${PORT}`);
});
EOF
# Check if Node.js is available and start test server
if command -v node > /dev/null 2>&1; then
cd test-api
npm init -y > /dev/null 2>&1
npm install express > /dev/null 2>&1
node server.js &
TEST_SERVER_PID=$!
cd ..
echo "✅ Test API server started (PID: $TEST_SERVER_PID)"
else
echo "⚠️ Node.js not found - skipping test API server"
fi
echo ""
echo "=========================================="
echo "✅ BrainSAIT B2B Platform Ready!"
echo "=========================================="
echo ""
echo "🔗 Access Points:"
echo " • API Test: http://localhost:8000"
echo " • Database: postgresql://localhost:5432/brainsait_b2b"
echo " • Redis: redis://localhost:6379"
echo ""
echo "🔌 Zapier Integration:"
echo " 1. Go to: https://zapier.com/app/editor"
echo " 2. Create new Zap with Webhooks by Zapier"
echo " 3. Use webhook URL: http://localhost:8000/webhooks/zapier"
echo " 4. Test with: curl -X POST http://localhost:8000/trigger/test"
echo ""
echo "📚 Next Steps:"
echo " 1. Configure your Zapier account"
echo " 2. Set up webhook automations"
echo " 3. Connect payment gateways"
echo " 4. Deploy to production"
echo ""
echo "💡 Quick Commands:"
echo " • Stop services: docker-compose down"
echo " • View logs: docker-compose logs -f"
echo " • Reset all: docker-compose down -v"
echo ""
echo "📧 Support: support@brainsait.com"
echo "📅 Book Demo: https://calendly.com/fadil369"
echo ""