Source:
ocean/docs/STAGING_ENVIRONMENT_STRATEGY.md| ✏️ Edit on GitHub
Staging Environment Strategy
This document outlines the strategy for creating a high-fidelity, cost-effective staging environment for the Ocean/Ebisu platform. The approach is based on replicating the production architecture and leveraging existing automation.
Core Principles
- Mirror Production Architecture: The staging environment should mimic the production setup (PostgreSQL Logical Replication from a publisher to subscribers) to ensure issues are caught before they reach users.
- Leverage Existing Automation: The
ebisu-databaserepository contains the scripts and documentation that serve as a blueprint. We will adapt, not reinvent, this automation. - Isolate Environments: Staging and production must be completely separate, from the database instances to the authentication provider and API keys.
- Cost-Effectiveness: Use low-cost, non-production-grade cloud resources for the staging infrastructure.
Staging Architecture Components
A complete staging environment requires a parallel version of each piece of the production stack:
- Staging Ebisu Publisher DB: A simple PostgreSQL instance that acts as the master database for the staging environment.
- Staging Ebisu Subscriber DB: A second PostgreSQL instance that acts as a tenant database, receiving data from the publisher via logical replication.
- Staging Supabase Project: A separate, free-tier Supabase project for isolated user authentication and for hosting the staging versions of the database orchestration Edge Functions.
- Vercel Preview Deployments: The
oceanfrontend and API layer will continue to be deployed via Vercel, with preview branches configured to point to the staging backend components.
Actionable Plan
Step 1: Provision Staging Database Infrastructure
The first step is to create the core database resources.
- Action: Provision a small, single cloud VM (e.g., AWS EC2 t3.micro, DigitalOcean Droplet) running two PostgreSQL instances. The existing
ebisu-database/docker-compose.ymlprovides a perfect template for this using Docker.- Instance 1:
staging-ebisu-publisher - Instance 2:
staging-ebisu-subscriber
- Instance 1:
- Justification: This provides the necessary database infrastructure at a very low cost, perfectly simulating the separate publisher/subscriber model.
Step 2: Adapt the Publisher Setup Script
The ebisu-database repository contains a script for setting up the production Crunchy Bridge publisher. We will adapt this for our generic staging publisher.
- Action: Create a new script,
ebisu-database/scripts/configure-staging-postgres.sh. - Implementation: This script will perform the same logical steps found in the
REPLICATION_SETUP.md's "Manual Setup" section, using standardpsqlcommands:- Ensure the PostgreSQL instance's
wal_levelis set tological. - Connect to the
staging-ebisu-publisherdatabase. CREATE ROLE replicator WITH LOGIN REPLICATION PASSWORD '...';CREATE PUBLICATION ebisu_master_data FOR ALL TABLES;GRANT SELECT ON ALL TABLES IN SCHEMA public TO replicator;
- Ensure the PostgreSQL instance's
- Automation: This script should be integrated into a CI/CD pipeline that runs whenever the
stagingbranch ofebisu-databaseis updated.
Step 3: Deploy and Configure Staging Services
With the databases ready, the application and orchestration layers can be configured.
-
Create Staging Supabase Project:
- Action: Create a new, free-tier Supabase project named
ocean-staging-auth. - Configure: Deploy the existing Edge Functions (
provision-tenant-resources,monitor-replication, etc.) to this project.
- Action: Create a new, free-tier Supabase project named
-
Set Staging Environment Variables:
- Action: In both the new Supabase project's secrets and the Vercel project settings for "Preview" deployments, create a complete set of environment variables for staging. These must be kept separate from production keys.
# Staging Database
STAGING_EBISU_HOST=<IP of your staging VM>
STAGING_EBISU_PORT=5432
STAGING_EBISU_DATABASE=staging_ebisu_publisher
STAGING_EBISU_REPLICATOR_PASSWORD=<your new replicator password>
STAGING_EBISU_CERT_PEM=<self-signed cert if needed, or empty>
# Staging Supabase Auth
NEXT_PUBLIC_SUPABASE_URL=<URL of your staging Supabase project>
NEXT_PUBLIC_SUPABASE_ANON_KEY=<Anon key of your staging Supabase project>
# Other Services
STRIPE_API_KEY=<Stripe Test Mode Key>
End-to-End Staging Workflow
The resulting workflow provides a seamless development and testing experience:
- DB Schema Change: A developer merges a migration into the
stagingbranch ofebisu-database. The CI/CD pipeline automatically applies this migration to thestaging-ebisu-publisherdatabase. - App Feature Change: A developer opens a pull request in the
oceanrepository. - Vercel Deployment: Vercel builds a preview deployment. It automatically uses the
STAGING_*andNEXT_PUBLIC_SUPABASE_*variables configured for preview builds. - Testing Replication: The developer can make an API call to the
provision-tenant-resourcesendpoint on the staging Supabase instance. This function connects thestaging-ebisu-subscriberto thestaging-ebisu-publisher, and logical replication begins. - Validation: The Vercel preview deployment can now read replicated data from the
staging-ebisu-subscriber, providing a full, high-fidelity test of the entire system.