🚀 Setup e Deployment
Requisitos do Sistema
Software Necessário
Essenciais:
- Python 3.10 ou superior
- PostgreSQL 12 ou superior
- pip (gestor de pacotes Python)
Opcionais mas Recomendados:
- Git (para clonar o repositório)
- virtualenv ou venv (ambientes virtuais Python)
- pgAdmin ou DBeaver (gestão de BD visual)
Requisitos de Hardware
Mínimos:
- CPU: 1 core
- RAM: 512 MB
- Disco: 1 GB livre
- Internet: Conexão estável (para CoinGecko API)
Recomendados (para fundos com >20 utilizadores):
- CPU: 2+ cores
- RAM: 2 GB
- Disco: 5 GB livre (para logs e backups)
- SSD (melhor performance de BD)
Instalação Local (Desenvolvimento)
1. Clonar o Repositório
git clone https://github.com/your-repo/CryptoDashboard.git
cd CryptoDashboard
2. Configurar Ambiente Virtual
Windows:
python -m venv .venv
.venv\Scripts\activate
Linux/Mac:
python3 -m venv .venv
source .venv/bin/activate
3. Instalar Dependências
pip install -r requirements.txt
Dependências principais:
streamlit>=1.30.0
pandas>=2.1.0
plotly>=5.18.0
psycopg2-binary>=2.9.9
SQLAlchemy>=2.0.0
bcrypt>=4.1.2
python-dateutil>=2.8.2
requests>=2.31.0
4. Configurar PostgreSQL
Opção A: PostgreSQL Local
Criar Base de Dados:
# Aceder ao PostgreSQL
psql -U postgres
# Criar base de dados
CREATE DATABASE crypto_dashboard;
# Criar utilizador
CREATE USER crypto_user WITH PASSWORD 'secure_password';
# Dar permissões
GRANT ALL PRIVILEGES ON DATABASE crypto_dashboard TO crypto_user;
# Sair
\q
5. Configurar Variáveis de Ambiente
Criar ficheiro .env na raiz do projeto:
# .env
DATABASE_URL=postgresql://crypto_user:secure_password@localhost:5432/crypto_dashboard
SECRET_KEY=your-random-secret-key-here
ENVIRONMENT=development
# Opcional: CoinGecko API key (para tier pago)
COINGECKO_API_KEY=your-api-key
6. Inicializar Base de Dados
Executar Script de Setup:
psql -U crypto_user -d crypto_dashboard -f database/tablesv2.sql
7. Lançar Aplicação
streamlit run app.py
Acessar:
http://localhost:8501
Login inicial:
- Username:
admin - Password:
admin123 - ⚠️ Alterar password imediatamente!
Deployment em Produção
Opção 1: Streamlit Cloud (Mais Fácil)
Pré-requisitos:
- Repositório GitHub público ou privado
- Conta Streamlit Cloud
Passos:
- Push código para GitHub
- Deploy no Streamlit Cloud
- Configurar Secrets
- Deploy
Limitações:
- Máximo 1 GB RAM
- CPU compartilhada
- Sleep após 7 dias sem acesso
- Adequado para <50 utilizadores
Opção 2: VPS (DigitalOcean, Linode, AWS EC2)
Recomendado para controlo total e performance
Setup no Ubuntu 22.04
1. Instalar dependências:
# Python 3.10
apt install python3.10 python3.10-venv python3-pip -y
# PostgreSQL
apt install postgresql postgresql-contrib -y
# Nginx (reverse proxy)
apt install nginx -y
# Certificados SSL
apt install certbot python3-certbot-nginx -y
2. Criar serviço systemd:
nano /etc/systemd/system/crypto-dashboard.service
[Unit]
Description=Crypto Dashboard Streamlit App
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/opt/CryptoDashboard
Environment="PATH=/opt/CryptoDashboard/.venv/bin"
ExecStart=/opt/CryptoDashboard/.venv/bin/streamlit run app.py --server.port 8501 --server.address 127.0.0.1
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
3. Configurar Nginx:
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://127.0.0.1:8501;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
# Timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
}
4. SSL com Let's Encrypt:
certbot --nginx -d your-domain.com
Backup e Recuperação
Backup Automatizado
Script de Backup:
#!/bin/bash
# backup.sh
BACKUP_DIR="/backups/crypto-dashboard"
DATE=$(date +%Y%m%d_%H%M%S)
DB_NAME="crypto_dashboard"
DB_USER="crypto_user"
# Criar diretório
mkdir -p $BACKUP_DIR
# Backup PostgreSQL
pg_dump -U $DB_USER $DB_NAME > "$BACKUP_DIR/db_$DATE.sql"
# Manter apenas últimos 30 dias
find $BACKUP_DIR -type f -mtime +30 -delete
echo "Backup concluído: $DATE"
Agendar com Cron:
# Backup diário às 2h da manhã
0 2 * * * /opt/scripts/backup.sh >> /var/log/crypto-dashboard-backup.log 2>&1
Segurança
SSL/TLS
certbot --nginx -d your-domain.com
certbot renew --dry-run # Testar renovação automática
Firewall
# Instalar UFW
apt install ufw
# Permitir apenas necessário
ufw allow 22/tcp # SSH
ufw allow 80/tcp # HTTP
ufw allow 443/tcp # HTTPS
# Ativar
ufw enable
ufw status