Deployment with Docker
Relevant source files
The following files were used as context for generating this wiki page:The project utilizes Docker and Docker Compose to provide a containerized, consistent, and scalable deployment environment for the Sentiment Analysis system. This approach encapsulates the backend API, the Next.js dashboard, and the database into isolated services, simplifying setup and ensuring portability across different environments. Several deployment scripts and configurations are provided to cater to different needs, from a simple in-memory setup to a full production deployment on a VPS.
Sources: deploy.sh, deploy-from-github.sh, deploy-simple.sh, deploy-vps.sh
Deployment Architecture
The primary deployment strategy involves a multi-container setup managed by Docker Compose. This architecture consists of a backend API service, a frontend dashboard service, and an optional database service for persistent storage.
This diagram illustrates the services and their connections as defined in the full deployment configuration.
Sources: deploy-vps.sh
Docker Services
The project defines services within docker-compose.yml and docker-compose.simple.yml. The full deployment includes a PostgreSQL database, while the simple version runs without a persistent database.
| Service | Build Context / Image | Ports | Key Environment Variables | Description |
|---|---|---|---|---|
| dashboard | dashboard-next | 3000:3000 | NEXT_PUBLIC_API_URL | The Next.js frontend application. |
| api | src | 8000:8000 | DATABASE_URL, YOUTUBE_API_KEY | The FastAPI backend for sentiment analysis. |
| postgres | postgres:13-alpine | 5432:5432 | POSTGRES_PASSWORD, POSTGRES_USER, POSTGRES_DB | The PostgreSQL database for data persistence. |
| Sources: deploy-vps.sh, dashboard-next/DEPLOYMENT_CHECKLIST.md |
Deployment Options
The repository offers multiple ways to deploy the application using Docker, catering to different environments and requirements.
Full Deployment (with PostgreSQL)
This is the recommended production setup, utilizing a PostgreSQL database for data persistence. The deploy-vps.sh script is designed to facilitate this deployment on a Virtual Private Server (VPS). It checks for a .env.production file and creates a template if one doesn't exist.
The script uses docker-compose.yml to build and run the services.
Environment Configuration
The deploy-vps.sh script expects a .env.production file with the following variables:
| Variable | Default/Example Value | Description |
|---|---|---|
DB_PASSWORD | change_this_password_123 | Password for the PostgreSQL database user. |
DATABASE_URL | postgresql://admin:change_this_password_123@postgres:5432/sentiment_analysis | Connection string for the API to connect to the database. |
NODE_ENV | production | Sets the Node.js environment to production. |
NEXTAUTH_SECRET | change_this_secret_key | A secret key for NextAuth. |
YOUTUBE_API_KEY | your_youtube_api_key_here | API key for fetching YouTube comments. |
| Sources: deploy-vps.sh:5-15 |
Simple Deployment (In-Memory)
For a lightweight, database-free setup, the docker-compose.simple.yml configuration can be used. This is ideal for low-spec VPS or quick testing. It uses in-memory storage with periodic JSON backups. The deploy-simple.sh script automates this process.
Key features of the simple deployment include:
- Zero database setup required.
- Fast performance (~2-5MB RAM usage).
- Automatic backups every 5 minutes.
Sources: deploy-simple.sh:25-30
Manual Docker Build (Dashboard Only)
The dashboard-next application can be built and run as a standalone Docker container. This is useful for deploying only the frontend.
An example Dockerfile is provided in the deployment checklist:
# Create Dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]
Sources: dashboard-next/DEPLOYMENT_CHECKLIST.md:46-55
To build and run this container manually:
# Build and run
docker build -t sentiment-dashboard .
docker run -p 3000:3000 sentiment-dashboard
Sources: dashboard-next/DEPLOYMENT_CHECKLIST.md:57-59
Deployment Automation Scripts
Several shell scripts are included to automate the deployment process.
deploy-from-github.sh
This script provides a fully automated deployment pipeline directly from the GitHub repository. It handles dependency installation, cloning or updating the project, and launching the Docker containers.
The deployment flow is as follows:
Sources: [deploy-from-github.sh]
Other Scripts
The repository contains other specialized scripts for different deployment scenarios.
| Script | Purpose | Docker Compose File |
|---|---|---|
deploy.sh | A general-purpose script to build and run containers using the default docker-compose.yml. | docker-compose.yml |
deploy-vps.sh | Prepares a VPS environment and runs the full production deployment. | docker-compose.yml |
deploy-simple.sh | Runs the lightweight, in-memory deployment. | docker-compose.simple.yml |
| Sources: deploy.sh, deploy-vps.sh, deploy-simple.sh |
Deployment Checklist & Monitoring
The DEPLOYMENT_CHECKLIST.md file provides a comprehensive guide for pre-deployment, testing, and post-deployment steps. This includes build verification, functionality tests, and performance benchmarks.
After deployment, services can be monitored by viewing the container logs. The deployment scripts typically end by tailing the logs.
# Show logs
docker-compose logs -f
Sources: deploy.sh:26, deploy-from-github.sh:39
To check the status of running services:
docker-compose ps
Sources: deploy-vps.sh:26, deploy-simple.sh:21