194 lines
3.3 KiB
Markdown
194 lines
3.3 KiB
Markdown
|
|
# ASLE Deployment Guide
|
||
|
|
|
||
|
|
## Prerequisites
|
||
|
|
|
||
|
|
- Docker and Docker Compose
|
||
|
|
- Node.js 20+ (for local development)
|
||
|
|
- Foundry (for contract deployment)
|
||
|
|
- PostgreSQL 15+ (or use Docker)
|
||
|
|
- Environment variables configured
|
||
|
|
|
||
|
|
## Environment Setup
|
||
|
|
|
||
|
|
1. Copy environment files:
|
||
|
|
```bash
|
||
|
|
cp backend/.env.example backend/.env
|
||
|
|
cp frontend/.env.example frontend/.env.local
|
||
|
|
```
|
||
|
|
|
||
|
|
2. Configure environment variables in `.env` files
|
||
|
|
|
||
|
|
## Database Setup
|
||
|
|
|
||
|
|
1. Start PostgreSQL:
|
||
|
|
```bash
|
||
|
|
docker-compose up -d postgres
|
||
|
|
```
|
||
|
|
|
||
|
|
2. Run migrations:
|
||
|
|
```bash
|
||
|
|
cd backend
|
||
|
|
npm install
|
||
|
|
npx prisma migrate deploy
|
||
|
|
npx prisma generate
|
||
|
|
```
|
||
|
|
|
||
|
|
## Contract Deployment
|
||
|
|
|
||
|
|
### Local Development
|
||
|
|
|
||
|
|
```bash
|
||
|
|
cd contracts
|
||
|
|
forge build
|
||
|
|
forge test
|
||
|
|
|
||
|
|
# Deploy to local network
|
||
|
|
forge script script/Deploy.s.sol:DeployScript --rpc-url http://localhost:8545 --broadcast --private-key $PRIVATE_KEY
|
||
|
|
```
|
||
|
|
|
||
|
|
### Mainnet/Testnet Deployment
|
||
|
|
|
||
|
|
1. Set environment variables:
|
||
|
|
```bash
|
||
|
|
export PRIVATE_KEY=your_private_key
|
||
|
|
export RPC_URL=https://your-rpc-url
|
||
|
|
export DEPLOYER_ADDRESS=your_deployer_address
|
||
|
|
```
|
||
|
|
|
||
|
|
2. Deploy:
|
||
|
|
```bash
|
||
|
|
forge script script/Deploy.s.sol:DeployScript \
|
||
|
|
--rpc-url $RPC_URL \
|
||
|
|
--broadcast \
|
||
|
|
--verify \
|
||
|
|
--etherscan-api-key $ETHERSCAN_API_KEY \
|
||
|
|
--private-key $PRIVATE_KEY
|
||
|
|
```
|
||
|
|
|
||
|
|
3. Update environment files with deployed addresses
|
||
|
|
|
||
|
|
## Backend Deployment
|
||
|
|
|
||
|
|
### Local Development
|
||
|
|
|
||
|
|
```bash
|
||
|
|
cd backend
|
||
|
|
npm install
|
||
|
|
npm run dev
|
||
|
|
```
|
||
|
|
|
||
|
|
### Docker
|
||
|
|
|
||
|
|
```bash
|
||
|
|
docker-compose up -d backend
|
||
|
|
```
|
||
|
|
|
||
|
|
### Production
|
||
|
|
|
||
|
|
1. Build image:
|
||
|
|
```bash
|
||
|
|
cd backend
|
||
|
|
docker build -t asle-backend .
|
||
|
|
```
|
||
|
|
|
||
|
|
2. Run container:
|
||
|
|
```bash
|
||
|
|
docker run -d \
|
||
|
|
--name asle-backend \
|
||
|
|
-p 4000:4000 \
|
||
|
|
--env-file backend/.env \
|
||
|
|
asle-backend
|
||
|
|
```
|
||
|
|
|
||
|
|
## Frontend Deployment
|
||
|
|
|
||
|
|
### Local Development
|
||
|
|
|
||
|
|
```bash
|
||
|
|
cd frontend
|
||
|
|
npm install
|
||
|
|
npm run dev
|
||
|
|
```
|
||
|
|
|
||
|
|
### Docker
|
||
|
|
|
||
|
|
```bash
|
||
|
|
docker-compose up -d frontend
|
||
|
|
```
|
||
|
|
|
||
|
|
### Production (Vercel/Next.js)
|
||
|
|
|
||
|
|
```bash
|
||
|
|
cd frontend
|
||
|
|
npm install
|
||
|
|
npm run build
|
||
|
|
npm start
|
||
|
|
```
|
||
|
|
|
||
|
|
Or use Vercel:
|
||
|
|
```bash
|
||
|
|
vercel deploy --prod
|
||
|
|
```
|
||
|
|
|
||
|
|
## Full Stack Deployment
|
||
|
|
|
||
|
|
### Development
|
||
|
|
|
||
|
|
```bash
|
||
|
|
docker-compose up
|
||
|
|
```
|
||
|
|
|
||
|
|
### Production
|
||
|
|
|
||
|
|
1. Set production environment variables
|
||
|
|
2. Update `docker-compose.prod.yml` if needed
|
||
|
|
3. Deploy:
|
||
|
|
```bash
|
||
|
|
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
|
||
|
|
```
|
||
|
|
|
||
|
|
## Health Checks
|
||
|
|
|
||
|
|
- Backend: `http://localhost:4000/health`
|
||
|
|
- Frontend: `http://localhost:3000`
|
||
|
|
- GraphQL: `http://localhost:4000/graphql`
|
||
|
|
|
||
|
|
## Monitoring
|
||
|
|
|
||
|
|
- Check logs: `docker-compose logs -f`
|
||
|
|
- Database access: `docker-compose exec postgres psql -U asle -d asle`
|
||
|
|
- Redis access: `docker-compose exec redis redis-cli`
|
||
|
|
|
||
|
|
## Troubleshooting
|
||
|
|
|
||
|
|
1. **Database connection errors**: Check PostgreSQL is running and credentials are correct
|
||
|
|
2. **Contract deployment fails**: Verify RPC URL and private key
|
||
|
|
3. **Frontend can't connect**: Check `NEXT_PUBLIC_API_URL` is set correctly
|
||
|
|
4. **Port conflicts**: Update ports in `docker-compose.yml`
|
||
|
|
|
||
|
|
## Security Checklist
|
||
|
|
|
||
|
|
- [ ] Change all default passwords
|
||
|
|
- [ ] Use strong JWT_SECRET
|
||
|
|
- [ ] Configure CORS properly
|
||
|
|
- [ ] Enable HTTPS in production
|
||
|
|
- [ ] Set up firewall rules
|
||
|
|
- [ ] Regular security updates
|
||
|
|
- [ ] Backup database regularly
|
||
|
|
- [ ] Monitor logs for suspicious activity
|
||
|
|
|
||
|
|
## Backup and Recovery
|
||
|
|
|
||
|
|
### Database Backup
|
||
|
|
|
||
|
|
```bash
|
||
|
|
docker-compose exec postgres pg_dump -U asle asle > backup_$(date +%Y%m%d).sql
|
||
|
|
```
|
||
|
|
|
||
|
|
### Database Restore
|
||
|
|
|
||
|
|
```bash
|
||
|
|
docker-compose exec -T postgres psql -U asle asle < backup_20240101.sql
|
||
|
|
```
|
||
|
|
|