-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·87 lines (78 loc) · 3.5 KB
/
Copy pathstart.sh
File metadata and controls
executable file
·87 lines (78 loc) · 3.5 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
#!/usr/bin/env bash
# bash.social launcher — one command for macOS / Linux / any bash shell.
# It detects the environment and picks the best path automatically:
# 1) Docker Compose — starts app + PostgreSQL + Redis in containers;
# 2) Native run — starts Redis, creates .venv, installs deps, runs uvicorn.
# Everything stays separated (each service runs on its own), but YOU type one line.
set -euo pipefail
cd "$(dirname "$0")"
#* .env from the template on the first run.
#? .env из шаблона при первом запуске.
if [ ! -f .env ]; then
cp .env.example .env
fi
#* Detect a working docker compose (v2 plugin or standalone docker-compose).
#? Ищем рабочий docker compose (плагин v2 или отдельный docker-compose).
COMPOSE=""
if command -v docker >/dev/null 2>&1; then
if docker compose version >/dev/null 2>&1; then
COMPOSE="docker compose"
elif command -v docker-compose >/dev/null 2>&1; then
COMPOSE="docker-compose"
fi
fi
if [ -n "$COMPOSE" ]; then
if docker info >/dev/null 2>&1; then
echo "==> bash.social: starting app + postgres + redis in containers"
$COMPOSE up -d --build
echo "==> Open http://localhost:8000"
exit 0
else
echo "==> Docker is installed but the daemon is not running."
echo " Start Docker Desktop / the daemon, then run ./start.sh again."
exit 1
fi
fi
echo "==> Docker not found — using the native path (Redis + uvicorn)."
#* Native path: Redis must be up (it is a separate service).
#? Нативный путь: Redis должен работать (это отдельный сервис).
if ! command -v redis-cli >/dev/null 2>&1 || ! redis-cli ping >/dev/null 2>&1; then
echo "==> Redis is not running. Trying to start it..."
if command -v brew >/dev/null 2>&1; then
brew services start redis
elif command -v systemctl >/dev/null 2>&1; then
sudo systemctl start redis-server 2>/dev/null || sudo systemctl start redis 2>/dev/null || true
fi
sleep 1
if ! redis-cli ping >/dev/null 2>&1; then
echo "==> Redis could not be started automatically."
echo " Install/start Redis manually, then run ./start.sh again."
exit 1
fi
fi
if ! command -v python3 >/dev/null 2>&1; then
echo "==> python3 is required for the native path."
exit 1
fi
#* Virtualenv with dependencies (installed once).
#? Виртуальное окружение с зависимостями (ставится один раз).
[ -d .venv ] || python3 -m venv .venv
# shellcheck disable=SC1091
source .venv/bin/activate
if [ ! -f .venv/.deps-installed ]; then
pip install -q -e ".[dev]"
touch .venv/.deps-installed
fi
#* The template .env points at the docker-internal host "db", which does not
#* exist natively. Unless the user exported BS_DATABASE_URL themselves or set
#* their own PostgreSQL in .env, fall back to SQLite.
#? Шаблон .env указывает на внутренний docker-хост "db", которого нет в нативном
#? режиме. Если пользователь сам не задал BS_DATABASE_URL и не прописал свой
#? PostgreSQL — откатываемся на SQLite.
if [ -z "${BS_DATABASE_URL:-}" ] && grep -q 'db:5432' .env; then
export BS_DATABASE_URL="sqlite+aiosqlite:///./dev.db"
echo "==> No local PostgreSQL configured — using SQLite."
echo " To use Postgres, set BS_DATABASE_URL in .env or export it."
fi
echo "==> bash.social: http://localhost:8000 (Ctrl+C to stop)"
exec uvicorn app.main:app --host 0.0.0.0 --port "${PORT:-8000}"