cp .env.example .envpython -c "import secrets; print('SECRET_KEY=' + secrets.token_urlsafe(32))" >> .envdocker-compose up -dThis will:
- Start PostgreSQL on port 5432
- Run database migrations automatically
- Start the web server on http://localhost:5000
docker-compose exec web python -c "
from app import app, db
from app.models.models import User
with app.app_context():
u = User(username='admin', role='admin')
u.set_password('admin')
db.session.add(u)
db.session.commit()
print('Admin user created: admin/admin')
"docker-compose logs -f web
docker-compose logs -f postgresdocker-compose downdocker-compose down -vdocker-compose exec web alembic upgrade headdocker-compose exec postgres psql -U adventure -d adventure_muddocker-compose exec web pytest -vDATABASE_URL - PostgreSQL connection string
- Local Docker:
postgresql://adventure:adventure_dev_password@localhost:5432/adventure_mud - Production:
postgresql://username:password@hostname:5432/database_name
SECRET_KEY - Flask secret key for sessions
- Development: Any string (not secure)
- Production: Generate with
python -c "import secrets; print(secrets.token_urlsafe(32))"
CORS_ALLOWED_ORIGINS - CORS configuration (default: *)
SOCKETIO_ASYNC_MODE - SocketIO mode (default: auto-detect)
- Options:
gevent,threading
ENGINEIO_LOGGER - Enable SocketIO logging (default: 1)
DUNGEON_ALLOW_HIDDEN_AREAS - Enable hidden dungeon areas (default: 0)
DUNGEON_ENABLE_GENERATION_METRICS - Track generation metrics (default: 1)
TEST_DATABASE_URL - Separate database for tests (optional)
For production, update your .env file:
# Strong database password
DATABASE_URL=postgresql://adventure:STRONG_PASSWORD_HERE@postgres:5432/adventure_mud
# Secure secret key (generate new one!)
SECRET_KEY=your-generated-secret-key-here
# Restrict CORS to your domain
CORS_ALLOWED_ORIGINS=https://yourdomain.com
# Disable debug logging
ENGINEIO_LOGGER=0Also update docker-compose.yml to use the environment variable for the database password:
services:
postgres:
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}# Check if PostgreSQL is ready
docker-compose exec postgres pg_isready -U adventure
# Restart PostgreSQL
docker-compose restart postgres# View migration history
docker-compose exec web alembic current
# Rollback one migration
docker-compose exec web alembic downgrade -1
# Upgrade to latest
docker-compose exec web alembic upgrade headIf port 5000 or 5432 is already in use, edit docker-compose.yml:
services:
web:
ports:
- "8000:5000" # Use port 8000 insteadThe application code is mounted as a volume, so changes are reflected immediately (you may need to restart the web container for some changes):
docker-compose restart web# Add to requirements.txt, then:
docker-compose build web
docker-compose up -d web# Backup
docker-compose exec postgres pg_dump -U adventure adventure_mud > backup.sql
# Restore
docker-compose exec -T postgres psql -U adventure adventure_mud < backup.sql