π Deployment Files Overview
This directory contains all the configuration files needed to deploy Rock Spotter to various platforms.
π File Structure
Rock-Spotter/
βββ backend/
β βββ Dockerfile # Docker image configuration
β βββ .dockerignore # Files to exclude from Docker build
β βββ .env.example # Development environment template
β βββ .env.production.example # Production environment template
βββ docker-compose.yml # Full stack Docker setup (API + MongoDB)
βββ render.yaml # Render platform configuration
βββ railway.json # Railway platform configuration
βββ Procfile # Heroku/similar platforms configuration
βββ deploy-setup.sh # Interactive deployment setup script
βββ verify-deployment.sh # Deployment verification script
βββ DEPLOYMENT.md # Complete deployment guide
βββ .github/
βββ workflows/
βββ ci.yml # GitHub Actions CI/CD pipeline
π File Descriptions
Docker Files
backend/Dockerfile
- Purpose: Creates a containerized version of the Rock Spotter API
- Base Image:
node:18-alpine (lightweight Node.js)
- What it does:
- Installs production dependencies only
- Copies application code
- Exposes port 3000
- Sets NODE_ENV to production
- Runs the API server
When to use:
- Deploying to any platform that supports Docker
- Local development with Docker
- VPS deployments (DigitalOcean, AWS EC2, etc.)
backend/.dockerignore
- Purpose: Excludes unnecessary files from Docker image
- Excludes:
node_modules (reinstalled in container)
.env files (set via environment)
- Git files
- Development files
- Logs
Why itβs important: Keeps Docker images small and fast to build
docker-compose.yml
- Purpose: Orchestrates both API and MongoDB containers
- Services:
mongodb: MongoDB 7.0 database
backend: Rock Spotter API
- Features:
- Automatic networking between services
- Persistent data storage for MongoDB
- Environment variable configuration
- Port mapping (3000 for API, 27017 for MongoDB)
When to use:
- Local development with Docker
- VPS deployments with Docker
- Testing full stack locally
- Production on your own server
Quick start:
render.yaml
- Purpose: Blueprint for deploying to Render
- Platform: Render.com
- Features:
- Auto-detects Node.js environment
- Configures build and start commands
- Sets up environment variables
- Includes health check endpoint
- Free tier available (750 hours/month)
Deployment:
- Push code to GitHub
- Connect repository to Render
- Render auto-detects
render.yaml
- Add MongoDB connection string
- Deploy!
railway.json
- Purpose: Configuration for Railway platform
- Platform: Railway.app
- Features:
- Uses Nixpacks builder (automatic detection)
- Custom build and start commands
- Health check configuration
- Restart policy
- Free $5 credit monthly
Deployment:
railway login
railway init
railway up
Procfile
- Purpose: Process configuration for Heroku and similar platforms
- Platform: Heroku, DigitalOcean App Platform, and others
- Content:
web: cd backend && npm start
- What it does: Tells the platform how to start the web server
Platforms that use Procfile:
- Heroku
- DigitalOcean App Platform
- Dokku
- Flynn
Deployment (Heroku):
heroku create rock-spotter-api
git push heroku main
Environment Configuration
backend/.env.example
- Purpose: Template for local development
- Contains:
- PORT=3000
- MONGODB_URI (localhost)
- JWT_SECRET (development key)
- Upload configuration
Usage:
cd backend
cp .env.example .env
# Edit .env with your settings
backend/.env.production.example
- Purpose: Template for production deployment
- Contains:
- Production MongoDB URI (MongoDB Atlas)
- Strong JWT secret
- CORS configuration
- Optional services (email, cloud storage)
- Logging configuration
- Feature flags
Usage: Reference this when setting environment variables in your deployment platform
Helper Scripts
deploy-setup.sh
- Purpose: Interactive deployment setup wizard
- Features:
- Checks prerequisites (Node.js, npm, git)
- Guides through deployment options
- Installs necessary tools
- Sets up environment variables
- Provides platform-specific instructions
Usage:
chmod +x deploy-setup.sh
./deploy-setup.sh
Options:
- Local Development (local MongoDB)
- Local Development (Docker)
- Deploy to Render
- Deploy to Railway
- Deploy to Heroku
verify-deployment.sh
- Purpose: Tests deployed API is working
- Tests:
- Health check endpoint
- Root endpoint
- User registration
- Authentication
- Public endpoints (rocks, hunts, achievements)
Usage:
chmod +x verify-deployment.sh
./verify-deployment.sh https://your-api-url.com
Example:
./verify-deployment.sh https://rock-spotter-api.onrender.com
CI/CD
.github/workflows/ci.yml
- Purpose: Automated testing and building
- Triggers: Push to main/develop, Pull Requests
- Jobs:
- test: Tests backend on Node 16, 18, 20
- docker: Builds and verifies Docker image
- lint: Checks code syntax and configuration
- Features:
- MongoDB service for testing
- Multi-version Node.js testing
- Docker build verification
- Syntax checking
What it does:
- Runs automatically on every push
- Catches errors before deployment
- Ensures Docker builds work
- Tests on multiple Node versions
π― Quick Start Guides
Deploy with Docker (Easiest)
# Clone repository
git clone https://github.com/jmenichole/Rock-Spotter.git
cd Rock-Spotter
# Start with Docker Compose
docker-compose up -d
# Verify
curl http://localhost:3000/api/health
Deploy to Render (Free)
- Create MongoDB Atlas database (free tier)
- Fork repository to your GitHub
- Go to Render Dashboard
- New β Blueprint
- Connect repository (auto-detects
render.yaml)
- Add environment variables:
MONGODB_URI: Your MongoDB Atlas URI
JWT_SECRET: Auto-generated or set manually
- Deploy!
Deploy to Railway (Fast)
# Install CLI
npm install -g railway
# Login and init
railway login
railway init
# Add MongoDB
railway add
# Set secret
railway variables set JWT_SECRET=$(openssl rand -hex 32)
# Deploy
railway up
Deploy to Heroku (Classic)
# Install CLI
npm install -g heroku
# Login and create app
heroku login
heroku create rock-spotter-api
# Add MongoDB
heroku addons:create mongolab:sandbox
# Set environment
heroku config:set JWT_SECRET=$(openssl rand -hex 32)
# Deploy
git push heroku main
π Security Checklist
Before deploying to production:
| Platform |
Free Tier |
Setup Time |
Auto-Deploy |
MongoDB |
Best For |
| Render |
750 hrs/mo |
5 min |
β
|
Need Atlas |
Beginners |
| Railway |
$5 credit |
2 min |
β
|
β
Included |
Speed |
| Heroku |
1000 hrs/mo |
5 min |
β
|
Add-on |
Classic |
| Docker |
N/A |
1 min |
β |
β
Included |
Full control |
| DigitalOcean |
$200/60d |
10 min |
β
|
Separate |
Production |
π Troubleshooting
βCannot connect to MongoDBβ
Solution:
- Check MongoDB Atlas IP whitelist (add
0.0.0.0/0)
- Verify connection string format
- Ensure database user has correct permissions
βPort already in useβ
Solution:
- Change PORT in environment variables
- Most platforms auto-set PORT (donβt hardcode)
βBuild failedβ
Solution:
- Check platform logs for specific error
- Verify all dependencies in
package.json
- Ensure build command is correct
βAPI returns 502/503β
Solution:
- Check if database is connected
- Verify environment variables are set
- Review application logs
- Ensure health check endpoint works
π Additional Resources
π€ Contributing
Found an issue with deployment? Please:
- Check existing issues
- Create a new issue with:
- Platform name
- Error messages
- Steps to reproduce
- Your environment details
π Support
Need help deploying?
- Check DEPLOYMENT.md for detailed guides
- Run
./deploy-setup.sh for interactive help
- Review platform documentation
- Open a GitHub issue
Happy Deploying! ππͺ¨
Choose your platform, follow the guide, and get your Rock Spotter API live in minutes!