Skip to content

u11d-com/blog_test-stack-in-gh-actions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Test Stack in GitHub Actions

A FastAPI blog application demonstrating how to use Terraform as a one-shot initialization container in Docker Compose. This eliminates "works on my machine" problems by ensuring identical infrastructure setup across local development, CI, and production environments.

What This Demonstrates

  • Deterministic infrastructure setup - Terraform runs automatically before your app starts
  • Local ↔ CI parity - Same containers, same flow everywhere
  • Real integration tests - Tests run against actual Elasticsearch, not mocks
  • No manual setup steps - docker compose up creates everything you need

Quick Start

  1. Clone and start the stack:
git clone https://github.com/u11d-com/blog_test-stack-in-gh-actions
cd blog_test-stack-in-gh-actions
docker compose up -d
  1. Wait for Terraform to finish setup:
# Check that terraform container exited successfully
docker compose ps terraform
  1. Run tests:
uv sync --group dev
uv run pytest -v
  1. Start the API server:
uv run fastapi dev

Then navigate to http://localhost:8000/docs to explore the API using Swagger UI.

How It Works

The stack starts services in a specific order:

  1. MinIO (S3-compatible storage for Terraform state)
  2. Elasticsearch (document database)
  3. Terraform (creates indices and API keys, then exits)
  4. Your app can now start with guaranteed infrastructure

The key insight: infrastructure setup is code that runs automatically, not manual steps in a README.

Architecture

├── app/                 # FastAPI application
│   ├── blogs/          # Blog CRUD endpoints
│   └── main.py         # App entry point
├── terraform/          # Infrastructure as code
│   ├── elasticsearch.tf    # Index and API key definitions
│   └── local.tfvars        # Local environment config
├── tests/              # Integration tests
└── compose.yaml        # Complete development stack

Testing Philosophy

Tests run against the real infrastructure stack, not mocks:

  • Elasticsearch indices with proper mappings
  • Actual API key authentication
  • Full CRUD operations with audit logging
  • Data validation at the database level

When tests pass, you know the entire system works together.

Production Deployment

The same Terraform code deploys to production with different variables:

  1. Update terraform/prod.tfvars with production Elasticsearch URL
  2. Run terraform apply -var-file=prod.tfvars
  3. Deploy app with production environment variables

No configuration drift, no manual setup, no surprises.

Related Content

This project accompanies the blog post: "From 'It Worked On My Machine' to Deterministic Confidence"

About

Guide how to initialize your test stack in GitHub Actions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors