Files
vrbattles-api/DEPLOY.md
2026-01-20 05:41:25 +00:00

139 lines
4.2 KiB
Markdown

# Deploying VRBattles API with Dokploy
## Prerequisites
- Dokploy installed on your server
- Git repository (Gitea, GitHub, GitLab, etc.)
## Quick Start
### Step 1: Push to Git
```bash
git add .
git commit -m "Add production deployment configs"
git push origin main
```
### Step 2: Create Project in Dokploy
1. Open Dokploy dashboard
2. Click **"Create Project"** → Give it a name (e.g., "VRBattles")
3. Click **"Add Service"** → Select **"Compose"**
### Step 3: Configure the Compose Service
1. **Source**: Select your Git provider and repository
2. **Branch**: `main` (or your default branch)
3. **Compose Path**: `docker-compose.prod.yml`
### Step 4: Set Environment Variables
In Dokploy's Environment tab, add these **required** variables:
| Variable | Example | Description |
|----------|---------|-------------|
| `JWT_SECRET` | `$(openssl rand -base64 32)` | Generate a secure random string |
| `POSTGRES_PASSWORD` | `your_secure_db_password` | Database password |
| `FRONTEND_URL` | `https://vrbattles.com` | Your frontend URL |
| `BASE_URL` | `https://api.vrbattles.com` | API base URL |
**Optional variables** (for S3 storage):
- `S3_BUCKET`
- `S3_REGION`
- `AWS_ACCESS_KEY_ID`
- `AWS_SECRET_ACCESS_KEY`
### Step 5: Configure Domain (Optional)
1. Go to **Domains** tab in Dokploy
2. Add your domain: `api.yourdomain.com`
3. Dokploy will auto-configure SSL via Let's Encrypt
### Step 6: Deploy!
Click **"Deploy"** and watch the logs.
---
## Architecture
```
┌─────────────────────────────────────────────────┐
│ Dokploy │
│ ┌─────────────────────────────────────────┐ │
│ │ docker-compose.prod.yml │ │
│ │ ┌─────────────┐ ┌──────────────┐ │ │
│ │ │ api:3000 │────│ db:5432 │ │ │
│ │ │ (Rust API) │ │ (PostgreSQL) │ │ │
│ │ └─────────────┘ └──────────────┘ │ │
│ │ │ │ │ │
│ │ ▼ ▼ │ │
│ │ uploads_data postgres_data │ │
│ │ (volume) (volume) │ │
│ └─────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ Traefik (reverse proxy) │
│ SSL termination │
└─────────────────────────────────────────────────┘
https://api.yourdomain.com
```
---
## Useful Commands
### View Logs
In Dokploy UI → Logs tab, or SSH to server:
```bash
docker compose -f docker-compose.prod.yml logs -f api
```
### Access Database
```bash
docker compose -f docker-compose.prod.yml exec db psql -U postgres -d vrbattles
```
### Manual Deploy
```bash
docker compose -f docker-compose.prod.yml up -d --build
```
### Backup Database
```bash
docker compose -f docker-compose.prod.yml exec db pg_dump -U postgres vrbattles > backup.sql
```
---
## Troubleshooting
### API won't start
1. Check logs in Dokploy
2. Verify `DATABASE_URL` is correct
3. Ensure `JWT_SECRET` is set
### Database connection failed
1. Check if db service is healthy
2. Verify `POSTGRES_PASSWORD` matches in both services
### Uploads not working
1. Check `uploads_data` volume is mounted
2. Verify `BASE_URL` is set correctly
3. For S3: check AWS credentials
---
## Migrating Data
If you have existing data to import:
```bash
# Copy SQL dump to server
scp backup.sql user@server:/tmp/
# Import into running container
docker compose -f docker-compose.prod.yml exec -T db psql -U postgres -d vrbattles < /tmp/backup.sql
```