-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·314 lines (283 loc) · 12.1 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·314 lines (283 loc) · 12.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
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
#!/usr/bin/env bash
set -e
REPO="https://github.com/fropa/pyxis.git"
DIR="/opt/pyxis"
BOLD="\033[1m"
GREEN="\033[32m"
YELLOW="\033[33m"
RED="\033[31m"
RESET="\033[0m"
info() { echo -e "${GREEN}▶ $*${RESET}"; }
warn() { echo -e "${YELLOW}⚠ $*${RESET}"; }
error() { echo -e "${RED}✗ $*${RESET}"; exit 1; }
echo -e "${BOLD}"
cat <<'EOF'
____ _
| _ \ _ ___ _(_)___
| |_) | | | \ \/ / / __|
| __/| |_| |> <| \__ \
|_| \__, /_/\_\_|___/
|___/
AI-powered infrastructure observability
EOF
echo -e "${RESET}"
# ── 1. Check OS ────────────────────────────────────────────────────────────────
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
else
error "Cannot detect Linux distribution."
fi
# ── 2. Install Docker if missing ───────────────────────────────────────────────
if ! command -v docker &>/dev/null; then
info "Installing Docker..."
case "$OS" in
ubuntu|debian|linuxmint|pop)
sudo apt-get update -qq
sudo apt-get install -y -qq ca-certificates curl gnupg lsb-release
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/$OS/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/$OS $(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update -qq
sudo apt-get install -y -qq docker-ce docker-ce-cli containerd.io docker-compose-plugin
;;
centos|rhel|almalinux|rocky)
sudo yum install -y -q yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y -q docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo systemctl enable --now docker
;;
fedora)
sudo dnf install -y -q dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
sudo dnf install -y -q docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo systemctl enable --now docker
;;
arch|manjaro)
sudo pacman -Sy --noconfirm docker docker-compose
sudo systemctl enable --now docker
;;
*)
error "Unsupported distribution: $OS. Install Docker manually: https://docs.docker.com/engine/install/"
;;
esac
sudo usermod -aG docker "$USER" || true
info "Docker installed."
else
info "Docker already installed: $(docker --version)"
fi
# ── 3. Install nginx if missing ────────────────────────────────────────────────
if ! command -v nginx &>/dev/null; then
info "Installing nginx..."
case "$OS" in
ubuntu|debian|linuxmint|pop)
sudo apt-get install -y -qq nginx ;;
centos|rhel|almalinux|rocky)
sudo yum install -y -q nginx
sudo systemctl enable --now nginx ;;
fedora)
sudo dnf install -y -q nginx
sudo systemctl enable --now nginx ;;
arch|manjaro)
sudo pacman -Sy --noconfirm nginx
sudo systemctl enable --now nginx ;;
esac
info "nginx installed."
else
info "nginx already installed: $(nginx -v 2>&1)"
fi
# ── 4. Clone or update repo ────────────────────────────────────────────────────
if [ -d "$DIR/.git" ]; then
info "Updating Pyxis..."
cd "$DIR"
sudo git fetch --quiet origin
sudo git reset --hard origin/main --quiet # restore any deleted tracked files
else
info "Cloning Pyxis into $DIR..."
sudo git clone --quiet "$REPO" "$DIR"
cd "$DIR"
fi
# ── 5. Configure environment ───────────────────────────────────────────────────
if [ ! -f backend/.env ]; then
info "Creating default backend/.env..."
SECRET=$(openssl rand -hex 16 2>/dev/null || cat /proc/sys/kernel/random/uuid | tr -d '-')
sudo tee backend/.env > /dev/null <<EOF
DATABASE_URL=postgresql+asyncpg://pyxis:pyxis@postgres:5432/pyxis
REDIS_URL=redis://redis:6379
ANTHROPIC_API_KEY=sk-ant-...
SECRET_KEY=${SECRET}
DEBUG=false
EOF
fi
# ── 6. Start the stack ─────────────────────────────────────────────────────────
info "Starting Pyxis (this may take a few minutes on first run)..."
docker compose up -d --build
# ── 7. Wait for backend ────────────────────────────────────────────────────────
info "Waiting for backend to be ready..."
for i in $(seq 1 30); do
if curl -sf http://localhost:8000/health > /dev/null 2>&1; then
break
fi
sleep 2
done
if ! curl -sf http://localhost:8000/health > /dev/null 2>&1; then
warn "Backend didn't respond in time. Check: docker compose logs backend"
exit 1
fi
# ── 8. Configure Anthropic API key ────────────────────────────────────────────
_configure_api_key() {
echo ""
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}"
echo -e "${BOLD} Anthropic API Key${RESET}"
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}"
CURRENT_KEY=$(grep "^ANTHROPIC_API_KEY=" backend/.env | cut -d'=' -f2-)
NEED_RESTART=false
if [[ "$CURRENT_KEY" == sk-ant-* ]]; then
MASKED="${CURRENT_KEY:0:18}…${CURRENT_KEY: -4}"
echo ""
echo -e " Current key: ${YELLOW}${MASKED}${RESET}"
echo ""
printf " Replace it? [y/N]: " >&2
read -r ANSWER </dev/tty
if [[ "${ANSWER,,}" == "y" || "${ANSWER,,}" == "yes" ]]; then
printf " Paste new Anthropic API key: " >&2
read -r NEW_KEY </dev/tty
if [[ -n "$NEW_KEY" ]]; then
sed -i "s|^ANTHROPIC_API_KEY=.*|ANTHROPIC_API_KEY=$NEW_KEY|" backend/.env
info "API key updated."
NEED_RESTART=true
else
warn "No key entered — keeping existing key."
fi
else
info "Keeping existing key."
fi
else
echo ""
echo " Pyxis uses Claude AI for root cause analysis, runbooks,"
echo " post-mortems, and the on-call assistant."
echo ""
echo " Get a free key at: https://console.anthropic.com"
echo ""
echo -e " Type ${YELLOW}offline${RESET} to skip AI features for now."
echo ""
printf " Paste your Anthropic API key: " >&2
read -r INPUT </dev/tty
echo ""
if [[ "${INPUT,,}" == "offline" || -z "$INPUT" ]]; then
warn "Offline mode — AI features disabled."
warn "To enable later: edit backend/.env, set ANTHROPIC_API_KEY, then run: docker compose restart backend worker"
else
sed -i "s|^ANTHROPIC_API_KEY=.*|ANTHROPIC_API_KEY=$INPUT|" backend/.env
info "API key saved."
NEED_RESTART=true
fi
fi
echo ""
if [[ "$NEED_RESTART" == "true" ]]; then
info "Restarting backend to apply new key..."
docker compose restart backend worker
fi
}
_configure_api_key
# ── 10. Create default tenant ─────────────────────────────────────────────────
RESPONSE=$(curl -sf -X POST http://localhost:8000/api/v1/tenants/ \
-H "Content-Type: application/json" \
-d '{"name":"default","contact_email":"admin@localhost"}' 2>/dev/null || echo "")
if [ -n "$RESPONSE" ]; then
API_KEY=$(echo "$RESPONSE" | grep -o '"api_key":"[^"]*"' | cut -d'"' -f4)
else
API_KEY=$(curl -sf http://localhost:8000/api/v1/tenants/ 2>/dev/null | grep -o '"api_key":"[^"]*"' | head -1 | cut -d'"' -f4)
fi
# ── 9. Configure nginx ─────────────────────────────────────────────────────────
info "Configuring nginx..."
SERVER_IP=$(hostname -I | awk '{print $1}')
NGINX_CONF=/etc/nginx/sites-available/pyxis
sudo tee "$NGINX_CONF" > /dev/null <<NGINX
server {
listen 80 default_server;
server_name _;
# Backend routes → FastAPI :8000
location /api/ {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_read_timeout 120s;
}
location /ws/ {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$host;
proxy_read_timeout 3600s;
}
location /docs {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Host \$host;
}
location /openapi.json {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Host \$host;
}
location /redoc {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Host \$host;
}
location /install {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Host \$host;
}
location /health {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Host \$host;
}
# Everything else → Vite frontend :5173
location / {
proxy_pass http://127.0.0.1:5173;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$host;
}
}
NGINX
# Enable site — handle both sites-enabled (Debian/Ubuntu) and conf.d (RHEL/Fedora/Arch)
if [ -d /etc/nginx/sites-enabled ]; then
sudo ln -sf "$NGINX_CONF" /etc/nginx/sites-enabled/pyxis
# Disable the default site so it doesn't conflict on port 80
sudo rm -f /etc/nginx/sites-enabled/default
elif [ -d /etc/nginx/conf.d ]; then
sudo ln -sf "$NGINX_CONF" /etc/nginx/conf.d/pyxis.conf
# Remove the default welcome page config
sudo rm -f /etc/nginx/conf.d/default.conf
fi
if sudo nginx -t 2>/dev/null; then
sudo systemctl reload nginx
info "nginx configured and reloaded."
else
warn "nginx config test failed — check: sudo nginx -t"
fi
# ── 10. Done ───────────────────────────────────────────────────────────────────
echo ""
echo -e "${BOLD}${GREEN}✓ Pyxis is running!${RESET}"
echo ""
echo -e " Dashboard → ${BOLD}http://${SERVER_IP}${RESET}"
echo -e " API docs → ${BOLD}http://${SERVER_IP}/docs${RESET}"
echo ""
if [ -n "$API_KEY" ]; then
echo -e " API key: ${BOLD}${API_KEY}${RESET}"
echo ""
echo " Paste into Settings, or run in browser console:"
echo -e " ${YELLOW}localStorage.setItem('pyxis-store', JSON.stringify({state:{apiKey:'${API_KEY}'},version:0})); location.reload();${RESET}"
fi
echo ""