Postgres & Redis Infrastructure
Relevant source files
The following files were used as context for generating this wiki page:
Postgres and Redis serve as foundational infrastructure components within the FLEXT ecosystem, primarily providing persistent storage and high-speed caching/session management for various services. These services are managed through a centralized Docker architecture, ensuring consistent environments across development, testing, and production-like integration scenarios.
The infrastructure is tightly integrated with the flext_tests toolkit (tk), which automates the lifecycle of these containers during testing phases, including automatic cleanup and dirty state management to ensure test isolation.
Architectural Overview
The FLEXT project employs a centralized management strategy for all Docker-based infrastructure. Postgres and Redis are defined within specific compose files and are consumed by multiple packages, such as flext-auth and flext-meltano.
This diagram shows the relationship between centralized compose definitions, the core database services, and the test automation toolkit.
Sources: [docker/README.md:12-25], [docker/docker-compose.flext-auth.yml:1-40]
PostgreSQL Infrastructure
PostgreSQL is used as the primary relational database for enterprise features like authentication and integration testing. FLEXT supports multiple versions of Postgres depending on the service requirements.
Configuration and Deployment
Postgres instances are typically configured with health checks to ensure service availability before dependent services (like the Auth API) start.
| Feature | Description | Source |
|---|---|---|
| Images | Uses postgres:15 or postgres:17 | [docker-compose.flext-auth.yml:6], [docker-compose.meltano-test.yml:64] |
| Default Port | 5432 (mapped to 5433 in some test scenarios) | [docker-compose.flext-auth.yml:14], [docker-compose.meltano-test.yml:71] |
| Persistence | Named volumes like postgres_data or postgres_test_data | [docker-compose.flext-auth.yml:16], [docker-compose.meltano-test.yml:73] |
| Health Check | Uses pg_isready to validate database availability | [docker-compose.flext-auth.yml:18-23] |
Initialization Logic
For the flext-auth service, the Postgres container includes an initialization step where init.sql is mounted to /docker-entrypoint-initdb.d/, ensuring the flext_auth database is correctly provisioned upon startup.
Sources: [docker/docker-compose.flext-auth.yml:17], [docker/docker-compose.meltano-test.yml:65-69]
Redis Infrastructure
Redis is utilized as a high-performance key-value store for caching and session persistence. It is standard across the FLEXT ecosystem for handling transient data.
Configuration and Deployment
Redis is consistently deployed using the redis:7-alpine image to minimize container footprint while providing modern features.
The Redis infrastructure flow for caching and its internal health monitoring.
| Parameter | Value | Source |
|---|---|---|
| Image | redis:7-alpine | [docker-compose.flext-auth.yml:26] |
| Ports | 6379 (default) or 6380 (test) | [docker-compose.flext-auth.yml:30], [docker-compose.meltano-test.yml:78] |
| Health Check | redis-cli ping | [docker-compose.flext-auth.yml:33-37] |
Sources: [docker/docker-compose.flext-auth.yml:25-37], [docker/docker-compose.meltano-test.yml:76-80]
Lifecycle and Test Integration
FLEXT utilizes a specific toolkit (tk) for managing Postgres and Redis containers during testing. This ensures that every test run starts with a clean database state.
Automated State Management
- Test Isolation: Each test receives a clean container state.
- Dirty Marking: If a test fails, the container is marked as "dirty" in
~/.flext/docker_state.json. - Automatic Recreation: Dirty containers are stopped, removed (including volumes), and recreated from scratch on the next run.
Fixtures
FLEXT provides centralized pytest fixtures for developers to easily interact with these services:
postgres_container: Provides a connection to a PostgreSQL instance.redis_container: Provides access to a Redis instance.
from flext_tests import postgres_container, redis_container
def test_database_logic(postgres_container):
# Container is automatically started and managed
connection_string = postgres_container
# Perform tests...
Sources: [docker/README.md:46-53], [docker/README.md:105-125]
Development Environment Support
The project enforces a "no local Dockerfile" policy to maintain standardization. All infrastructure components must be accessed through the centralized docker/ directory or via the tk API.
| Requirement | Command / Path |
|---|---|
| Centralized Compose | ~/flext/docker/docker-compose.*.yml |
| Centralized Images | ~/flext/docker/images/Dockerfile.* |
| Dependency Mgmt | types-psycopg2, types-redis in pyproject.toml |
Sources: [docker/README.md:154-175], [pyproject.toml:110-111]
Summary
The Postgres and Redis infrastructure in FLEXT is designed for modularity and reliability. By centralizing Docker configurations and integrating them with the flext_tests toolkit, the platform ensures that developers have immediate access to consistent database and caching services while maintaining high standards for test isolation and environment stability. This infrastructure supports critical enterprise paths including the Authentication API and various data integration taps and targets.