This guide provides instructions for deploying the Bat-Com Research Platform to various environments.
- Prerequisites
- Environment Setup
- Database Setup
- Application Deployment
- Replit Deployment
- Custom Server Deployment
- Docker Deployment
- CI/CD Setup
- Post-Deployment Verification
- Troubleshooting
Before deployment, ensure you have:
- Node.js 18+ installed
- npm 8+ installed
- PostgreSQL 14+ database access
- Git for version control
- Access to the deployment environment
Create a .env file with the following variables:
# Database
POSTGRES_URL=postgresql://username:password@localhost:5432/database_name
POSTGRES_CA_CERT=<optional base64-encoded CA cert>
# Server
PORT=5120
NODE_ENV=production
# Security
JWT_SECRET="your-secure-session-secret"
JWT_EXPIRES_IN="7d"
ADMIN_PASSWORD="temporary-admin-password"
For production environments, use environment-specific configuration systems:
- Replit: Set secrets in the Replit Secrets panel
- Custom Server: Use environment variables or a secure .env file
- Docker: Pass environment variables through Docker Compose or Kubernetes
-
Create a PostgreSQL database:
CREATE DATABASE batcom; CREATE USER batcom_user WITH ENCRYPTED PASSWORD 'secure_password'; GRANT ALL PRIVILEGES ON DATABASE batcom TO batcom_user;
-
Set up the connection string in your environment:
POSTGRES_URL=postgresql://batcom_user:secure_password@localhost:5432/batcom POSTGRES_CA_CERT=<optional base64-encoded CA cert>
Run the following command to set up the database schema:
npm run db:pushThis will:
- Create all necessary tables
- Set up relationships
- Apply any pending migrations
-
Install dependencies:
npm install
-
Build the frontend assets:
npm run build
-
Start the server:
npm start
- Fork the repository on Replit
- Set up environment secrets in the Replit Secrets panel:
POSTGRES_URLJWT_SECRET
- Run the database initialization:
npm run db:push
- Start the application:
npm run dev
- Use the Replit "Run" button to start the application
- Click the "Deploy" button to make the application publicly accessible
- Go to your Replit project
- Click on the "Deploy" tab
- Click "Add a custom domain"
- Follow the instructions to set up DNS records
-
Clone the repository:
git clone https://gitlab.coko.foundation/kotahi/batcom.git cd batcom -
Install dependencies:
npm install
-
Create a
.envfile with environment variables -
Build the application:
npm run build
-
Start the server:
npm start
For production environments, use PM2 to manage the Node.js process:
-
Install PM2:
npm install -g pm2
-
Start the application with PM2:
pm2 start npm --name "batcom" -- start -
Set up PM2 to start on system boot:
pm2 startup pm2 save
Configure Nginx as a reverse proxy:
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:5120;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}Set up SSL with Let's Encrypt:
sudo certbot --nginx -d your-domain.com- Create a
docker-compose.ymlfile:
version: '3'
services:
app:
build: .
ports:
- '5120:5120'
environment:
- POSTGRES_URL=postgresql://batcom_user:secure_password@db:5432/batcom
- POSTGRES_CA_CERT=<optional base64-encoded CA cert>
- NODE_ENV=production
- PORT=5120
- JWT_SECRET="your-secure-session-secret"
- JWT_EXPIRES_IN="7d"
- ADMIN_PASSWORD="temporary-admin-password"
depends_on:
- db
restart: always
db:
image: postgres:14
ports:
- '5432:5432'
environment:
- POSTGRES_USER=batcom_user
- POSTGRES_PASSWORD=secure_password
- POSTGRES_DB=batcom
volumes:
- postgres_data:/var/lib/postgresql/data
restart: always
volumes:
postgres_data:-
Start the services:
docker-compose up -d
-
Run database migrations:
docker-compose exec app npm run db:push
For deploying to Kubernetes, create the following manifests:
deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: batcom
spec:
replicas: 2
selector:
matchLabels:
app: batcom
template:
metadata:
labels:
app: batcom
spec:
containers:
- name: batcom
image: your-registry/batcom:latest
ports:
- containerPort: 5120
env:
- name: POSTGRES_URL
valueFrom:
secretKeyRef:
name: batcom-secrets
key: database-url
- name: NODE_ENV
value: 'production'
- name: PORT
value: '5120'
- name: SESSION_SECRET
valueFrom:
secretKeyRef:
name: batcom-secrets
key: session-secretservice.yaml:
apiVersion: v1
kind: Service
metadata:
name: batcom
spec:
selector:
app: batcom
ports:
- port: 80
targetPort: 5120
type: ClusterIPingress.yaml:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: batcom
annotations:
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
rules:
- host: your-domain.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: batcom
port:
number: 80
tls:
- hosts:
- your-domain.com
secretName: batcom-tls- Apply the manifests:
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl apply -f ingress.yamlCreate a .github/workflows/deploy.yml file:
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Build application
run: npm run build
- name: Run database migrations
run: npm run db:push
env:
POSTGRES_URL: ${{ secrets.POSTGRES_URL }}
- name: Deploy to production
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
cd /path/to/deployment
git pull
npm ci
npm run build
pm2 restart batcomAfter deployment, verify that:
- The application is accessible via the configured domain
- All pages load correctly
- Database operations work as expected
- User authentication functions properly
- File uploads and processing work correctly
- Analytics tracking is operational
Run the following checks:
# Check server status
curl -I https://your-domain.com
# Verify API endpoints
curl https://your-domain.com/api/virus-categories
# Check database connection
npm run db:verifyIf you encounter database connection issues:
- Verify the
POSTGRES_URLenvironment variable is correct - Check that PostgreSQL is running and accessible
- Ensure the database exists and permissions are set correctly
- Check network connectivity between the application and database servers
If the application fails to start:
-
Check the logs for error messages:
npm run logs # or if using PM2 pm2 logs batcom -
Verify environment variables are set correctly
-
Check for port conflicts:
netstat -tuln | grep 5120
If static assets fail to load:
- Check that the build process completed successfully
- Verify the asset paths in the HTML
- Check for CORS or CSP issues in the browser console
If file uploads don't work:
- Verify the upload directory exists and has proper permissions
- Check maximum file size settings
- Verify the Multer configuration in the server code