Configuration
This guide explains how to configure the Tracker System, including both the API and Admin Panel.
API Configuration
The API is configured using environment variables, which can be set in a .env file in the root directory of the project.
Environment Variables
The following environment variables are used to configure the API:
Database Configuration
POSTGRES_SERVER: PostgreSQL server hostname (default:db)POSTGRES_USER: PostgreSQL username (default:postgres)POSTGRES_PASSWORD: PostgreSQL password (required)POSTGRES_DB: PostgreSQL database name (default:postgres)POSTGRES_PORT: PostgreSQL server port (default:5432)
Security Configuration
SECRET_KEY: Secret key for JWT token generation and validation (required)ACCESS_TOKEN_EXPIRE_MINUTES: Expiration time for access tokens in minutes (default:30)REFRESH_TOKEN_EXPIRE_DAYS: Expiration time for refresh tokens in days (default:7)
CORS Configuration
CORS_ORIGINS: Comma-separated list of allowed origins for CORS (default:*)
Redis Configuration
REDIS_HOST: Redis server hostname (default:dragonfly)REDIS_PORT: Redis server port (default:6379)REDIS_USERNAME: Redis server username (optional, used for AWS Valkey)REDIS_PASSWORD: Redis server password (required)REDIS_CLUSTER_MODE: Whether Redis is running in cluster mode (default:false)REDIS_CACHE_TTL: Time-to-live for cached data in seconds (default:3600)REDIS_TLS_ENABLED: Enable TLS for Redis connections (default:false)REDIS_TLS_CERT_REQS: Certificate verification mode (default:none, options:none,optional,required)REDIS_TLS_CA_CERTS_FILE: Path to CA certificate file for verifying the server's certificateREDIS_TLS_CERTFILE: Path to client certificate file (optional)REDIS_TLS_KEYFILE: Path to client key file (optional)
Debug Configuration
DEBUG_WAIT_FOR_CLIENT: Whether to wait for a debugger to attach (default:false)
Example .env File
POSTGRES_SERVER=db
POSTGRES_USER=postgres
POSTGRES_PASSWORD=mysecretpassword
POSTGRES_DB=tracker
POSTGRES_PORT=5432
SECRET_KEY=mysupersecretkey
ACCESS_TOKEN_EXPIRE_MINUTES=30
REFRESH_TOKEN_EXPIRE_DAYS=7
CORS_ORIGINS=http://localhost:3000,http://localhost:8080
REDIS_HOST=dragonfly
REDIS_PORT=6379
REDIS_PASSWORD=myredispassword
REDIS_CLUSTER_MODE=false
REDIS_CACHE_TTL=3600
DEBUG_WAIT_FOR_CLIENT=false
Admin Panel Configuration
The Admin Panel is configured using environment variables, which can be set in a .env file in the tracker-admin directory.
Environment Variables
The following environment variables are used to configure the Admin Panel:
VITE_API_URL: URL of the API (default:/api/v1)
Example .env File
VITE_API_URL=http://localhost:8100/api/v1
Docker Compose Configuration
When using Docker Compose, the configuration is specified in the compose.yml file. The environment variables for each service are defined in the environment section of the service definition.
Example compose.yml Configuration
services:
api:
build:
context: .
dockerfile: build/api/Dockerfile
ports:
- 8000:8000
environment:
- POSTGRES_SERVER=db
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD?REQUIRED}
- POSTGRES_DB=${POSTGRES_DB:-postgres}
- POSTGRES_PORT=${POSTGRES_PORT:-5432}
- SECRET_KEY=${SECRET_KEY?REQUIRED}
- REDIS_HOST=${REDIS_HOST:-dragonfly}
- REDIS_PORT=${REDIS_PORT:-6379}
- REDIS_PASSWORD=${REDIS_PASSWORD?REQUIRED}
- REDIS_CLUSTER_MODE=${REDIS_CLUSTER_MODE:-false}
- REDIS_CACHE_TTL=${REDIS_CACHE_TTL:-3600}
# ...
admin:
build:
context: ./tracker-admin
dockerfile: Dockerfile
ports:
- 8080:80
# ...
# ...
Configuration Best Practices
- Use Environment Variables: Always use environment variables for configuration, especially for sensitive information like passwords and secret keys.
- Provide Defaults: Provide sensible defaults for optional configuration values.
- Validate Required Values: Validate that required configuration values are provided.
- Use Docker Secrets: In production, consider using Docker secrets for sensitive information.
- Document Configuration: Document all configuration options and their default values.
- Separate Development and Production: Use different configuration values for development and production environments.