Internal
Public Access
- Add Dockerfile for production (multi-stage build) - Add Dockerfile.dev for development with hot reload - Add docker-compose.yml with 5 services (web, mariadb, redis, celery-worker, celery-beat) - Add docker-compose.dev.yml for development overrides - Add .dockerignore for optimized builds - Add docker/entrypoint.sh startup script - Add .env.docker.example template - Add Makefile for common commands - Add deploy.sh for one-command deployment - Update config/settings/selfhosted.py to support MariaDB via DATABASE_URL - Add mysqlclient to requirements.txt for MariaDB support - Update .gitignore to exclude .env.docker 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
134 lines
4.2 KiB
Python
134 lines
4.2 KiB
Python
"""
|
|
Self-hosted settings for KeepItGoing.
|
|
|
|
Use this for users running their own instance.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import dj_database_url
|
|
from .base import *
|
|
|
|
# Security
|
|
SECRET_KEY = os.environ.get('SECRET_KEY')
|
|
if not SECRET_KEY:
|
|
raise ValueError(
|
|
"SECRET_KEY environment variable is required for self-hosted deployment. "
|
|
"Generate one with: python -c \"from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())\""
|
|
)
|
|
|
|
# Validate SECRET_KEY strength
|
|
if len(SECRET_KEY) < 50:
|
|
print("WARNING: SECRET_KEY is too short. Use at least 50 characters for security.", file=sys.stderr)
|
|
|
|
DEBUG = os.environ.get('DEBUG', 'False').lower() == 'true'
|
|
|
|
# Force DEBUG to False in self-hosted mode for security
|
|
if DEBUG:
|
|
print("WARNING: DEBUG=True in self-hosted mode is a security risk!", file=sys.stderr)
|
|
|
|
ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', 'localhost,127.0.0.1').split(',')
|
|
|
|
# Database - Support both PostgreSQL and MariaDB/MySQL via DATABASE_URL
|
|
# DATABASE_URL format examples:
|
|
# PostgreSQL: postgresql://user:password@host:5432/dbname
|
|
# MariaDB/MySQL: mysql://user:password@host:3306/dbname
|
|
database_url = os.environ.get('DATABASE_URL')
|
|
|
|
if database_url:
|
|
# Use DATABASE_URL for flexible database backend (PostgreSQL, MariaDB, MySQL, etc.)
|
|
DATABASES = {
|
|
'default': dj_database_url.config(
|
|
default=database_url,
|
|
conn_max_age=600,
|
|
conn_health_checks=True,
|
|
)
|
|
}
|
|
|
|
# Add MariaDB/MySQL specific options if using MySQL backend
|
|
if 'mysql' in database_url.lower():
|
|
DATABASES['default']['OPTIONS'] = {
|
|
'charset': 'utf8mb4',
|
|
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
|
|
}
|
|
else:
|
|
# Fallback to manual configuration (backwards compatibility)
|
|
# Supports both PostgreSQL and MariaDB/MySQL
|
|
db_engine = os.environ.get('DB_ENGINE', 'django.db.backends.postgresql')
|
|
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': db_engine,
|
|
'NAME': os.environ.get('DB_NAME', os.environ.get('POSTGRES_DB', 'keepitgoing')),
|
|
'USER': os.environ.get('DB_USER', os.environ.get('POSTGRES_USER', 'keepitgoing')),
|
|
'PASSWORD': os.environ.get('DB_PASSWORD', os.environ.get('POSTGRES_PASSWORD', 'keepitgoing')),
|
|
'HOST': os.environ.get('DB_HOST', os.environ.get('POSTGRES_HOST', 'db')),
|
|
'PORT': os.environ.get('DB_PORT', os.environ.get('POSTGRES_PORT', '5432')),
|
|
}
|
|
}
|
|
|
|
# Add MariaDB/MySQL specific options if using MySQL backend
|
|
if 'mysql' in db_engine:
|
|
DATABASES['default']['OPTIONS'] = {
|
|
'charset': 'utf8mb4',
|
|
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
|
|
}
|
|
|
|
# Redis/Celery
|
|
REDIS_URL = os.environ.get('REDIS_URL', 'redis://redis:6379/0')
|
|
CELERY_BROKER_URL = REDIS_URL
|
|
CELERY_RESULT_BACKEND = REDIS_URL
|
|
|
|
# Cache
|
|
CACHES = {
|
|
'default': {
|
|
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
|
|
'LOCATION': REDIS_URL,
|
|
}
|
|
}
|
|
|
|
# CORS - configurable for self-hosted
|
|
CORS_ALLOWED_ORIGINS = os.environ.get(
|
|
'CORS_ALLOWED_ORIGINS',
|
|
'http://localhost:8000'
|
|
).split(',')
|
|
|
|
# Static files
|
|
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
|
|
|
# Email - configurable
|
|
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
|
EMAIL_HOST = os.environ.get('EMAIL_HOST', '')
|
|
EMAIL_PORT = int(os.environ.get('EMAIL_PORT', 587))
|
|
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER', '')
|
|
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD', '')
|
|
EMAIL_USE_TLS = os.environ.get('EMAIL_USE_TLS', 'True').lower() == 'true'
|
|
DEFAULT_FROM_EMAIL = os.environ.get('DEFAULT_FROM_EMAIL', 'noreply@localhost')
|
|
|
|
# Self-hosted mode - no billing
|
|
SAAS_MODE = False
|
|
BILLING_ENABLED = False
|
|
USAGE_LIMITS_ENABLED = False
|
|
|
|
# Logging
|
|
LOGGING = {
|
|
'version': 1,
|
|
'disable_existing_loggers': False,
|
|
'formatters': {
|
|
'verbose': {
|
|
'format': '{levelname} {asctime} {module} {message}',
|
|
'style': '{',
|
|
},
|
|
},
|
|
'handlers': {
|
|
'console': {
|
|
'class': 'logging.StreamHandler',
|
|
'formatter': 'verbose',
|
|
},
|
|
},
|
|
'root': {
|
|
'handlers': ['console'],
|
|
'level': 'INFO',
|
|
},
|
|
}
|