Skip to main content
FootyCollect uses environment variables for all configuration. This guide covers all production environment variables based on deploy/env.example.

Environment File Locations

Depending on your deployment method, environment variables are stored in different locations:
Split into two files:
  • .envs/.production/.django - Django application settings
  • .envs/.production/.postgres - PostgreSQL database settings
Both files are loaded by docker-compose.production.yml.
Use deploy/env.example as your template. It contains all available variables with descriptions.

Required Variables

These variables must be set for production deployment:

Django Core Settings

Generate a secure SECRET_KEY:
Never use default values or commit SECRET_KEY to version control.

Database Configuration

If using Docker, also create .envs/.production/.postgres:

Redis Configuration

Security Settings

Configure security headers and HTTPS enforcement:

SSL/TLS Settings

These settings are validated by Django’s deployment checks in config/checks.py:334.

Content Security Policy (CSP)

Update DJANGO_CSP_IMG_SRC to include your S3/R2 bucket URL and any external image sources (e.g., Football Kit Archive CDN).

API Rate Limiting

Email Configuration

FootyCollect uses SendGrid for email delivery:
  1. Sign up at SendGrid
  2. Navigate to Settings > API Keys
  3. Create a new API key with “Mail Send” permissions
  4. Copy the key (shown only once)
  5. Add to SENDGRID_API_KEY
  1. In SendGrid, go to Settings > Sender Authentication
  2. Verify your domain (yourdomain.com)
  3. Add DNS records as instructed
  4. Use verified domain in DJANGO_DEFAULT_FROM_EMAIL

Storage Configuration

Configure S3-compatible storage for static and media files:

Storage Backend Selection

AWS S3 Storage

  1. Log into AWS Console
  2. Navigate to S3 > Create bucket
  3. Choose a unique bucket name
  4. Select region (e.g., us-east-1)
  5. Uncheck “Block all public access” (static files need public read)
  6. Create bucket
  1. Navigate to IAM > Users > Add user
  2. Enable “Programmatic access”
  3. Attach policy: AmazonS3FullAccess (or create custom policy)
  4. Save Access Key ID and Secret Access Key
  5. Add to environment variables
Add public read policy for static files:

Cloudflare R2 Storage

  1. Log into Cloudflare Dashboard
  2. Navigate to R2 > Create bucket
  3. Choose a bucket name
  4. Create bucket
  1. In R2, go to Manage R2 API Tokens
  2. Create API token
  3. Set permissions: Read and Write
  4. Save Access Key ID and Secret Access Key
  5. Note the endpoint URL (contains your account ID)
If serving fonts or static assets from a custom domain, configure CORS:
Or manually add in Cloudflare Dashboard > R2 > bucket > Settings > CORS Policy.
  1. In R2 bucket settings, click “Connect Custom Domain”
  2. Enter your subdomain (e.g., cdn.yourdomain.com)
  3. Add CNAME record to your DNS:
    • Type: CNAME
    • Name: cdn
    • Target: (provided by Cloudflare)
  4. Set CLOUDFLARE_R2_CUSTOM_DOMAIN=cdn.yourdomain.com
Why Cloudflare R2? R2 offers S3-compatible API with free egress (no bandwidth charges), significantly reducing costs compared to AWS S3.

Error Tracking (Sentry)

Configure Sentry for error monitoring and performance tracking:
  1. Sign up at Sentry.io
  2. Create a new project (Django)
  3. Copy the DSN from project settings
  4. Add to SENTRY_DSN
SENTRY_TRACES_SAMPLE_RATE controls performance monitoring:
  • 0.0 - Disabled (no performance tracking)
  • 0.1 - 10% of requests tracked
  • 1.0 - 100% of requests tracked (high volume)
Start with 0.0 or 0.1 to avoid quota limits.
Sentry is highly recommended for production. It provides:
  • Real-time error alerts
  • Stack traces and context
  • Performance monitoring
  • Release tracking

External Integrations

Football Kit Archive API (FKAPI)

FKAPI is optional but provides Football Kit Archive integration for searching and adding kits. See FKAPI repository for setup.

Rotating Proxy (Optional)

Use a rotating proxy if:
  • Downloading many images from external sources
  • Getting rate-limited by image hosts
  • Need to distribute requests across multiple IPs
Supports HTTP, HTTPS, and SOCKS5 proxies.

Performance Settings

Compression

Connection Pooling

CONN_MAX_AGE=60 keeps database connections alive for 60 seconds, reducing connection overhead. Set to 0 to disable pooling.

Complete Environment File Example

Here’s a complete production environment file (deploy/env.example:1):

Environment File Security

Protect Your Environment FilesEnvironment files contain sensitive credentials. Follow these security practices:

File Permissions

Version Control

Credential Rotation

  • Rotate DJANGO_SECRET_KEY periodically (requires user re-login)
  • Rotate database passwords quarterly
  • Rotate API keys when team members leave
  • Use unique credentials per environment (dev/staging/prod)

Secrets Management

For enhanced security, consider using:
  • AWS Secrets Manager - Store credentials in AWS
  • HashiCorp Vault - Centralized secrets management
  • Environment-specific encryption - Encrypt .env files at rest

Validation

Verify your environment configuration:

Django Deployment Checks

This validates (config/checks.py:1):
  • ✓ DEBUG is disabled
  • ✓ SECRET_KEY is secure (length, uniqueness)
  • ✓ Required environment variables are set
  • ✓ Database connectivity
  • ✓ Redis connectivity
  • ✓ Storage credentials (S3/R2)
  • ✓ ALLOWED_HOSTS configured
  • ✓ SSL/HTTPS settings

Manual Verification

Environment Variables Reference

Quick Reference Table

See deploy/env.example:1 for the complete list with descriptions.

Next Steps

Docker Deployment

Deploy with Docker Compose using environment files

Bare Metal Deployment

Deploy on VPS with environment file

Production Checklist

Verify configuration with deployment checklist