update project

This commit is contained in:
ZOMBIIIIIII
2026-04-14 13:30:26 +03:00
parent a81e29807c
commit 37146f7375
65 changed files with 3782 additions and 629 deletions

208
start.bat
View File

@@ -4,7 +4,7 @@ cd /d "%~dp0"
echo.
echo ==========================================
echo CryptoWallet - Local Dev Starter
echo CryptoWallet + BITOK Auth - Local Dev
echo ==========================================
echo.
@@ -16,68 +16,123 @@ if errorlevel 1 (
exit /b 1
)
:: ── 2. Locate PostgreSQL binaries ─────────────────────────────────────────────
set "PGBIN="
if exist "C:\Program Files\PostgreSQL\16\bin\pg_isready.exe" set "PGBIN=C:\Program Files\PostgreSQL\16\bin"
if not defined PGBIN (
where pg_isready >nul 2>&1
if errorlevel 1 (
echo [ERROR] PostgreSQL 16 not found. Expected at C:\Program Files\PostgreSQL\16\bin
pause
exit /b 1
)
)
set "PGPASSWORD=postgres"
:: ── 3. Start local PostgreSQL service ────────────────────────────────────────
echo [1/4] Starting PostgreSQL...
net start postgresql-x64-16 2>nul
timeout /t 2 /nobreak >nul
set /a pg_attempts=0
:waitpg
set /a pg_attempts+=1
if !pg_attempts! gtr 15 (
echo [ERROR] PostgreSQL not responding after 30 seconds.
:: ── 2. Check Docker ──────────────────────────────────────────────────────────
where docker >nul 2>&1
if errorlevel 1 (
echo [ERROR] Docker not found. Install Docker Desktop and ensure it is running.
pause
exit /b 1
)
if defined PGBIN (
"%PGBIN%\pg_isready.exe" -U postgres -q 2>nul
) else (
pg_isready -U postgres -q 2>nul
:: ── 3. Stop local PostgreSQL (if any) so Docker gets port 5432 ─────────────────
echo [1/8] Preparing environment...
net stop postgresql-x64-16 2>nul
timeout /t 2 /nobreak >nul
:: ── 4. Wait for Docker Engine ─────────────────────────────────────────────────
echo Waiting for Docker Engine...
set /a docker_attempts=0
:waitdocker
set /a docker_attempts+=1
if !docker_attempts! gtr 30 (
echo [ERROR] Docker Engine did not respond after 60 seconds.
echo Make sure Docker Desktop is fully started ^(whale icon in tray^).
pause
exit /b 1
)
docker info >nul 2>&1
if errorlevel 1 (
timeout /t 2 /nobreak >nul
goto waitpg
goto waitdocker
)
echo PostgreSQL is ready.
echo Docker ready.
:: ── 4. Ensure DB exists (create only if missing) ────────────────────────────
echo [2/4] Ensuring database...
if defined PGBIN (
"%PGBIN%\psql.exe" -U postgres -tc "SELECT 1 FROM pg_database WHERE datname='cryptowallet_v2'" 2>nul | findstr "1" >nul 2>nul
) else (
psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname='cryptowallet_v2'" 2>nul | findstr "1" >nul 2>nul
:: ── 5. Start infrastructure via Docker Compose ────────────────────────────────
echo [2/8] Starting infrastructure (PostgreSQL, Vault, RabbitMQ, KeyDB)...
docker compose up -d postgres vault vault-init rabbitmq keydb 2>&1
if errorlevel 1 (
echo Retrying with docker-compose...
docker-compose up -d postgres vault vault-init rabbitmq keydb 2>&1
)
if errorlevel 1 (
echo Creating database cryptowallet_v2...
if defined PGBIN (
"%PGBIN%\psql.exe" -U postgres -c "CREATE DATABASE cryptowallet_v2" 2>nul
) else (
psql -U postgres -c "CREATE DATABASE cryptowallet_v2" 2>nul
)
) else (
echo Database exists.
echo.
echo [ERROR] Could not start Docker Compose.
echo.
echo Common fixes:
echo 1. Wait 30-60 sec after opening Docker Desktop
echo 2. Restart Docker Desktop ^(right-click tray icon -^> Restart^)
echo 3. Run: docker compose up -d postgres vault vault-init rabbitmq keydb
echo.
pause
exit /b 1
)
:: ── 5. Install deps + migrate ────────────────────────────────────────────────
echo [3/4] Installing dependencies...
:: Wait for PostgreSQL to be ready
set /a pg_attempts=0
:waitpg
set /a pg_attempts+=1
if !pg_attempts! gtr 30 (
echo [ERROR] PostgreSQL not responding after 60 seconds.
pause
exit /b 1
)
timeout /t 2 /nobreak >nul
docker exec cryptowallet-db pg_isready -U postgres -q 2>nul
if errorlevel 1 goto waitpg
echo PostgreSQL is ready.
:: Wait for RabbitMQ to be ready
echo Waiting for RabbitMQ...
set /a rmq_attempts=0
:waitrmq
set /a rmq_attempts+=1
if !rmq_attempts! gtr 30 (
echo [WARN] RabbitMQ slow to start, continuing anyway...
goto rmq_done
)
timeout /t 2 /nobreak >nul
docker exec cryptowallet-rabbitmq rabbitmq-diagnostics check_port_connectivity >nul 2>&1
if errorlevel 1 goto waitrmq
:rmq_done
echo RabbitMQ is ready.
:: ── 6. Create databases ──────────────────────────────────────────────────────
echo [3/8] Ensuring databases...
docker exec cryptowallet-db psql -U postgres -c "CREATE DATABASE cryptowallet_devphase3" 2>nul
if errorlevel 1 (
echo cryptowallet_devphase3 may already exist, continuing...
)
docker exec cryptowallet-db psql -U postgres -c "CREATE DATABASE bitok_dev" 2>nul
if errorlevel 1 (
echo bitok_dev may already exist, continuing...
)
echo Databases ready.
:: ── 7. Wait for vault-init to finish ─────────────────────────────────────────
echo [4/8] Waiting for Vault initialization...
set /a vault_attempts=0
:waitvault
set /a vault_attempts+=1
if !vault_attempts! gtr 30 (
echo [WARN] vault-init taking long, continuing...
goto vault_done
)
timeout /t 2 /nobreak >nul
docker inspect cryptowallet-vault-init --format="{{.State.Status}}" 2>nul | findstr /C:"exited" >nul 2>&1
if errorlevel 1 goto waitvault
:vault_done
echo Vault initialized.
:: ── 8. Update .env ───────────────────────────────────────────────────────────
echo [5/8] Updating .env...
if not exist .env (
copy .env.example .env >nul
echo Created .env from .env.example
)
powershell -NoProfile -Command "(Get-Content .env) -replace '^DB_NAME=.*', 'DB_NAME=cryptowallet_devphase3' -replace '^DATABASE_URL=.*', 'DATABASE_URL=postgresql://postgres:postgres@localhost:5432/cryptowallet_devphase3' | Set-Content .env"
echo .env updated.
:: ── 9. Install deps and run migrations ────────────────────────────────────────
echo [6/8] Installing dependencies...
call pnpm install
if errorlevel 1 (
echo [ERROR] pnpm install failed.
@@ -86,39 +141,82 @@ if errorlevel 1 (
)
echo Dependencies installed.
echo Running migrations...
echo Running database migrations...
cd apps\api
call pnpm migrate
if errorlevel 1 (
echo [ERROR] Migrations failed.
echo Migration failed - resetting DB and retrying...
call pnpm db:reset
call pnpm migrate
)
if errorlevel 1 (
echo [ERROR] Migrations failed - check output above.
pause
exit /b 1
)
cd ..\..
echo Migrations done.
:: ── 6. Stop old processes and start servers ──────────────────────────────────
echo [4/4] Starting servers...
:: ── 10. Initialize BITOK database tables ──────────────────────────────────────
echo [7/8] Initializing BITOK database...
if exist BITOK\sql\tables.sql (
docker exec -i cryptowallet-db psql -U postgres -d bitok_dev < BITOK\sql\tables.sql 2>nul
echo BITOK tables initialized.
) else (
echo BITOK/sql/tables.sql not found, skipping...
)
:: ── 11. Start BITOK auth service (Docker) ─────────────────────────────────────
echo Starting BITOK auth service...
docker compose up -d bitok-auth 2>&1
if errorlevel 1 (
echo [WARN] BITOK auth container failed to start. Check: docker logs cryptowallet-bitok
)
:: Wait briefly for BITOK to be responsive
set /a bitok_attempts=0
:waitbitok
set /a bitok_attempts+=1
if !bitok_attempts! gtr 15 (
echo [WARN] BITOK slow to start, continuing...
goto bitok_done
)
timeout /t 2 /nobreak >nul
powershell -NoProfile -Command "try { $r = Invoke-WebRequest -Uri http://localhost:8000/ping -TimeoutSec 2 -UseBasicParsing; exit 0 } catch { exit 1 }" >nul 2>&1
if errorlevel 1 goto waitbitok
:bitok_done
echo BITOK auth service ready.
:: ── 12. Stop old dev servers and clear lock ─────────────────────────────────────
echo [8/8] Starting wallet servers...
powershell -NoProfile -Command "Get-NetTCPConnection -LocalPort 3000,3001 -ErrorAction SilentlyContinue | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue }"
if exist apps\web\.next\dev\lock del apps\web\.next\dev\lock 2>nul
timeout /t 1 /nobreak >nul
:: Start wallet API and Web
start "CryptoWallet API [port 3001]" cmd /k "cd /d %~dp0apps\api && pnpm dev"
timeout /t 2 /nobreak >nul
start "CryptoWallet Web [port 3000]" cmd /k "cd /d %~dp0apps\web && pnpm dev"
:: ── Done ─────────────────────────────────────────────────────────────────────
echo.
echo ==========================================
echo All services started!
echo.
echo Web: http://localhost:3000
echo API: http://localhost:3001
echo DB: localhost:5432 / cryptowallet_v2
echo Web: http://localhost:3000
echo API: http://localhost:3001
echo BITOK: http://localhost:8000
echo RabbitMQ: http://localhost:15672 (guest/guest)
echo DB: localhost:5432
echo wallet DB: cryptowallet_devphase3
echo BITOK DB: bitok_dev
echo user: postgres pass: postgres
echo ==========================================
echo.
timeout /t 3 /nobreak >nul
start http://localhost:3000
echo Press any key to close this launcher...
pause >nul
endlocal