-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
177 lines (150 loc) · 4.4 KB
/
Copy pathinstall.sh
File metadata and controls
177 lines (150 loc) · 4.4 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
#!/usr/bin/env bash
set -euo pipefail
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; NC='\033[0m'
log() { echo -e "${BLUE}[vencore]${NC} $*"; }
ok() { echo -e "${GREEN}[vencore]${NC} $*"; }
warn() { echo -e "${YELLOW}[vencore]${NC} $*"; }
err() { echo -e "${RED}[vencore]${NC} ERROR: $*" >&2; exit 1; }
INSTALL_DIR="${VENCORE_DIR:-$HOME/vencore}"
check_deps() {
command -v docker >/dev/null 2>&1 || err "Docker not found. Install from https://docs.docker.com/get-docker/"
docker compose version >/dev/null 2>&1 || err "Docker Compose v2 plugin not found. Update Docker Desktop or run: apt-get install docker-compose-plugin"
command -v openssl >/dev/null 2>&1 || err "openssl not found. Install it: apt-get install openssl"
}
gen_secret() { openssl rand -hex 32; }
detect_ip() {
hostname -I 2>/dev/null | awk '{print $1}' || \
ip route get 1 2>/dev/null | awk '{print $NF;exit}' || \
echo "localhost"
}
write_compose() {
cat > "$INSTALL_DIR/docker-compose.yml" <<'COMPOSE'
services:
web:
image: ghcr.io/vencorehq/vencore-web:latest
ports:
- "80:3000"
env_file: .env
depends_on:
api:
condition: service_healthy
restart: unless-stopped
api:
image: ghcr.io/vencorehq/vencore-api:latest
env_file: .env
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://localhost:3001/api/setup/status || exit 1"]
interval: 5s
timeout: 3s
retries: 20
restart: unless-stopped
worker:
image: ghcr.io/vencorehq/vencore-worker:latest
env_file: .env
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
restart: unless-stopped
db:
image: postgres:16-alpine
environment:
POSTGRES_USER: vencore
POSTGRES_PASSWORD: vencore
POSTGRES_DB: vencore
volumes:
- db_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U vencore"]
interval: 5s
timeout: 3s
retries: 10
restart: unless-stopped
redis:
image: redis:7-alpine
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
restart: unless-stopped
volumes:
db_data:
redis_data:
COMPOSE
}
write_env() {
cat > "$INSTALL_DIR/.env" << EOF
# Database (internal Docker network — do not change hostnames)
DATABASE_URL=postgresql://vencore:vencore@db:5432/vencore
REDIS_URL=redis://redis:6379
# Secrets (auto-generated — keep private)
JWT_SECRET=$(gen_secret)
CRON_SECRET=$(gen_secret)
AGENT_SIGNING_SECRET=$(gen_secret)
# App
NODE_ENV=production
NEXT_PUBLIC_API_URL=http://api:3001
COOKIE_SECURE=false
EOF
}
wait_for_api() {
log "Waiting for API to be ready..."
local attempts=0
while [ $attempts -lt 30 ]; do
if docker compose -f "$INSTALL_DIR/docker-compose.yml" exec -T api \
wget -qO- http://localhost:3001/api/setup/status >/dev/null 2>&1; then
return 0
fi
attempts=$((attempts + 1))
sleep 3
done
warn "API health check timed out. Check logs: cd $INSTALL_DIR && docker compose logs api"
}
main() {
echo ""
echo " Vencore Installer"
echo " ─────────────────"
echo ""
log "Checking dependencies..."
check_deps
ok "Dependencies OK."
log "Creating install directory: $INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
log "Writing docker-compose.yml..."
write_compose
if [ -f "$INSTALL_DIR/.env" ]; then
warn ".env already exists — skipping secret generation."
warn "To regenerate secrets: rm $INSTALL_DIR/.env && bash $0"
else
log "Generating secrets and writing .env..."
write_env
ok ".env written."
fi
log "Pulling images (first run may take a few minutes)..."
docker compose -f "$INSTALL_DIR/docker-compose.yml" pull
log "Starting Vencore..."
docker compose -f "$INSTALL_DIR/docker-compose.yml" up -d
wait_for_api
SERVER_IP=$(detect_ip)
echo ""
ok "Vencore is running!"
echo ""
echo " → Open http://$SERVER_IP in your browser to complete setup."
echo ""
echo " Useful commands:"
echo " cd $INSTALL_DIR"
echo " docker compose logs -f # View logs"
echo " docker compose down # Stop"
echo " docker compose pull && docker compose up -d # Update"
echo ""
}
main "$@"