-
Notifications
You must be signed in to change notification settings - Fork 210
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·268 lines (234 loc) · 9.69 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·268 lines (234 loc) · 9.69 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
#!/usr/bin/env bash
# =============================================================================
# Evo CRM Community — Interactive Setup Script
# =============================================================================
# This script sets up the entire Evo CRM platform from scratch.
# It checks prerequisites, builds Docker images, seeds the database,
# and starts all services.
#
# Usage:
# bash setup.sh
# =============================================================================
set -e
# ---------------------------------------------------------------------------
# Colors (with fallback for no-color terminals)
# ---------------------------------------------------------------------------
if [ -t 1 ] && command -v tput > /dev/null 2>&1; then
GREEN=$(tput setaf 2)
CYAN=$(tput setaf 6)
RED=$(tput setaf 1)
YELLOW=$(tput setaf 3)
BOLD=$(tput bold)
RESET=$(tput sgr0)
else
GREEN="" CYAN="" RED="" YELLOW="" BOLD="" RESET=""
fi
# ---------------------------------------------------------------------------
# Helper functions
# ---------------------------------------------------------------------------
info() { echo "${CYAN}[INFO]${RESET} $1"; }
success() { echo "${GREEN}[OK]${RESET} $1"; }
warn() { echo "${YELLOW}[WARN]${RESET} $1"; }
fail() { echo "${RED}[ERROR]${RESET} $1"; exit 1; }
spinner() {
local pid=$1
local msg=$2
local spin='|/-\'
local i=0
while kill -0 "$pid" 2>/dev/null; do
i=$(( (i+1) % 4 ))
printf "\r${CYAN}[....]${RESET} %s %s" "$msg" "${spin:$i:1}"
sleep 0.3
done
printf "\r${GREEN}[OK]${RESET} %s \n" "$msg"
}
# ---------------------------------------------------------------------------
# Banner
# ---------------------------------------------------------------------------
echo ""
echo "${GREEN}${BOLD}"
echo " ╔═══════════════════════════════════════════╗"
echo " ║ Evo CRM Community Setup ║"
echo " ║ Open-Source AI-Powered CRM Platform ║"
echo " ╚═══════════════════════════════════════════╝"
echo "${RESET}"
echo ""
# ---------------------------------------------------------------------------
# Step 1: Check prerequisites
# ---------------------------------------------------------------------------
info "Checking prerequisites..."
# Git
if command -v git > /dev/null 2>&1; then
success "Git found: $(git --version)"
else
fail "Git is not installed. Install it from https://git-scm.com/downloads"
fi
# Docker
if command -v docker > /dev/null 2>&1; then
success "Docker found: $(docker --version)"
else
fail "Docker is not installed. Install Docker Desktop from https://www.docker.com/products/docker-desktop/"
fi
# Docker Compose (v2)
if docker compose version > /dev/null 2>&1; then
success "Docker Compose found: $(docker compose version --short)"
else
fail "Docker Compose v2 not found. Please update Docker Desktop to the latest version."
fi
# Docker daemon running
if docker info > /dev/null 2>&1; then
success "Docker daemon is running"
else
fail "Docker daemon is not running. Please start Docker Desktop and try again."
fi
echo ""
# ---------------------------------------------------------------------------
# Step 2: Initialize submodules
# ---------------------------------------------------------------------------
info "Checking Git submodules..."
SUBMODULE_DIRS=(
"evo-auth-service-community"
"evo-ai-crm-community"
"evo-ai-frontend-community"
"evo-ai-processor-community"
"evo-ai-core-service-community"
"evo-bot-runtime"
"evo-flow-community"
)
needs_init=false
for dir in "${SUBMODULE_DIRS[@]}"; do
if [ ! -f "$dir/Dockerfile" ] && [ ! -f "$dir/docker/Dockerfile" ] && [ ! -f "$dir/package.json" ]; then
needs_init=true
break
fi
done
if [ "$needs_init" = true ]; then
info "Initializing submodules (this may take a few minutes)..."
git submodule update --init --recursive
success "Submodules initialized"
else
success "Submodules already initialized"
fi
echo ""
# ---------------------------------------------------------------------------
# Step 3: Configure environment
# ---------------------------------------------------------------------------
info "Configuring environment..."
if [ -f .env ]; then
warn ".env file already exists."
read -r -p " Overwrite with defaults? [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
cp .env.example .env
success "Overwrote .env with defaults"
;;
*)
success "Keeping existing .env"
;;
esac
else
cp .env.example .env
success "Created .env from .env.example"
fi
echo ""
# ---------------------------------------------------------------------------
# Step 4: Build Docker images
# ---------------------------------------------------------------------------
info "Building Docker images (this takes 5-15 minutes on first run)..."
echo ""
docker compose build
echo ""
success "All images built successfully"
echo ""
# ---------------------------------------------------------------------------
# Step 5: Start infrastructure (Postgres + Redis)
# ---------------------------------------------------------------------------
info "Starting database and cache..."
docker compose up -d postgres redis mailhog
info "Waiting for PostgreSQL to be ready..."
retries=0
max_retries=30
until docker compose exec -T postgres pg_isready -U postgres > /dev/null 2>&1; do
retries=$((retries + 1))
if [ "$retries" -ge "$max_retries" ]; then
fail "PostgreSQL did not become ready in time. Check: docker compose logs postgres"
fi
sleep 2
done
success "PostgreSQL is ready"
info "Waiting for Redis to be ready..."
retries=0
until docker compose exec -T redis redis-cli -a evoai_redis_pass ping > /dev/null 2>&1; do
retries=$((retries + 1))
if [ "$retries" -ge "$max_retries" ]; then
fail "Redis did not become ready in time. Check: docker compose logs redis"
fi
sleep 2
done
success "Redis is ready"
echo ""
# ---------------------------------------------------------------------------
# Step 6: Seed the database (canonical flow — mirrors `make seed`)
# ---------------------------------------------------------------------------
# The CRM owns the master schema. Load it first, then mark the auth service's
# migrations as already applied (the schema:load already created their tables),
# then run the application seeds. This is the same sequence the Makefile uses;
# keep them in sync.
info "Loading CRM master schema..."
docker compose run --rm evo-crm bundle exec rails db:create db:schema:load
success "CRM schema loaded"
info "Marking auth migrations as applied..."
docker compose run --rm evo-auth bundle exec rails runner \
"Dir['db/migrate/*.rb'].sort.map { |f| File.basename(f).split('_').first }.each { |v| begin; ActiveRecord::Base.connection.schema_migration.create_version(v); rescue ActiveRecord::RecordNotUnique; end }"
success "Auth migrations marked"
info "Seeding CRM service..."
docker compose run --rm evo-crm bundle exec rails db:seed
success "CRM service seeded"
info "Seeding Auth service..."
docker compose run --rm evo-auth bundle exec rails db:seed
success "Auth service seeded"
echo ""
# ---------------------------------------------------------------------------
# Step 7: Start all services
# ---------------------------------------------------------------------------
info "Starting all services..."
docker compose up -d
echo ""
info "Waiting for services to become healthy (this may take 1-2 minutes)..."
sleep 10
echo ""
echo "${GREEN}${BOLD}"
echo " ╔═══════════════════════════════════════════════════════╗"
echo " ║ Evo CRM Community is running! ║"
echo " ╚═══════════════════════════════════════════════════════╝"
echo "${RESET}"
echo ""
echo " ${BOLD}Service URLs:${RESET}"
echo " ─────────────────────────────────────────────"
echo " Frontend: ${CYAN}http://localhost:5173${RESET}"
echo " CRM API: ${CYAN}http://localhost:3010${RESET}"
echo " Auth API: ${CYAN}http://localhost:3011${RESET}"
echo " Processor: ${CYAN}http://localhost:8011${RESET}"
echo " Core API: ${CYAN}http://localhost:5565${RESET}"
echo " Bot Runtime: ${CYAN}http://localhost:8092${RESET}"
echo " Mailhog: ${CYAN}http://localhost:18025${RESET} (email testing)"
echo ""
echo " ${BOLD}First Access:${RESET}"
echo " ─────────────────────────────────────────────"
echo " Open ${GREEN}http://localhost:5173/setup${RESET} and create your admin"
echo " user through the setup wizard (no default login is pre-seeded)."
echo ""
echo " ${BOLD}Useful Commands:${RESET}"
echo " ─────────────────────────────────────────────"
echo " make status — Check service status"
echo " make logs — View logs (all services)"
echo " make stop — Stop all services"
echo " make start — Start all services"
echo " make clean — Remove all data and start fresh"
echo ""
echo " ${BOLD}Documentation:${RESET}"
echo " ─────────────────────────────────────────────"
echo " Setup Guide: docs/SETUP-GUIDE.md"
echo " Troubleshooting: docs/TROUBLESHOOTING.md"
echo " Contributing: CONTRIBUTING.md"
echo ""