Systems Library / Infrastructure / How to Build a Development Environment Setup Automator
Infrastructure developer tools

How to Build a Development Environment Setup Automator

Set up development environments automatically with one command.

Jay Banlasan

Jay Banlasan

The AI Systems Guy

Automating development environment setup with a single script saves hours every time you onboard a new machine, a new team member, or recover from a system wipe. I keep a setup script in every project repo. One command installs dependencies, creates config files, seeds the database, and verifies everything works.

What You Need Before Starting

Step 1: Create the Setup Script

#!/bin/bash
set -e

echo "$(date '+%Y-%m-%d %H:%M:%S') Starting environment setup..."

PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$PROJECT_DIR"

# Check prerequisites
check_command() {
    if ! command -v "$1" &> /dev/null; then
        echo "ERROR: $1 is not installed. Install it first."
        exit 1
    fi
    echo "  Found $1: $(command -v $1)"
}

echo "Checking prerequisites..."
check_command python3
check_command pip
check_command node
check_command git

Step 2: Handle Python Dependencies

echo "Setting up Python environment..."

if [ ! -d ".venv" ]; then
    python3 -m venv .venv
    echo "  Created virtual environment"
fi

source .venv/bin/activate
pip install -r requirements.txt --quiet
echo "  Python dependencies installed"

Step 3: Create Config Files from Templates

echo "Setting up configuration..."

setup_config() {
    local template="$1"
    local target="$2"
    
    if [ -f "$target" ]; then
        echo "  $target already exists, skipping"
        return
    fi
    
    if [ -f "$template" ]; then
        cp "$template" "$target"
        echo "  Created $target from template"
    else
        echo "  WARNING: Template $template not found"
    fi
}

setup_config ".env.example" ".env"
setup_config "config/settings.example.json" "config/settings.json"

Step 4: Set Up the Database

echo "Setting up database..."

if [ ! -f "data/app.db" ]; then
    mkdir -p data
    python3 -c "
from app.database import init_db
init_db('data/app.db')
print('  Database initialized')
"
    
    if [ -f "scripts/seed_data.py" ]; then
        python3 scripts/seed_data.py
        echo "  Seed data loaded"
    fi
else
    echo "  Database already exists, skipping"
fi

Step 5: Run Verification

echo "Verifying setup..."

verify_step() {
    local description="$1"
    local command="$2"
    
    if eval "$command" > /dev/null 2>&1; then
        echo "  PASS: $description"
    else
        echo "  FAIL: $description"
        FAILURES=$((FAILURES + 1))
    fi
}

FAILURES=0

verify_step "Python imports" "python3 -c 'import anthropic; import fastapi; import sqlite3'"
verify_step "Database exists" "test -f data/app.db"
verify_step "Env file exists" "test -f .env"
verify_step "API key configured" "grep -q 'ANTHROPIC_API_KEY=sk-' .env"

if [ "$FAILURES" -gt 0 ]; then
    echo ""
    echo "Setup completed with $FAILURES warnings. Fix the issues above."
    exit 1
fi

echo ""
echo "Setup complete. Run: source .venv/bin/activate && python3 app/main.py"

Step 6: Make It Idempotent

The script should be safe to run multiple times. Every step checks if work already exists before doing it. That way a partial failure can be fixed by re-running.

Save the full script as setup.sh in your project root:

chmod +x setup.sh

Run it:

./setup.sh

What to Build Next

Add a teardown.sh that cleanly removes the environment for testing fresh installs. Also add a doctor.sh that checks the health of an existing environment without changing anything.

Related Reading

Want this system built for your business?

Get a free assessment. We will map every system your business needs and show you the ROI.

Get Your Free Assessment

Related Systems