fix: Run backend/frontend natively to avoid stale prebuild code

The previous approach would build backend/frontend Docker images during
prebuild, but those images would contain the prebuild branch's code (dev),
not the PR branch being reviewed.

Now:
- Prebuild caches: dependency images, Python/Node packages
- Prebuild does NOT cache: backend/frontend code
- Backend/Frontend run natively with hot-reload
- Always uses current branch's code
This commit is contained in:
Otto-AGPT
2026-02-11 16:45:50 +00:00
parent 582754256e
commit 7195f7e298
4 changed files with 83 additions and 52 deletions

View File

@@ -11,10 +11,29 @@ This dev container provides a complete development environment for the AutoGPT P
2. **Wait for setup** (~60 seconds with prebuild, ~5-10 min without)
3. **Start developing!**
- Frontend auto-opens at `http://localhost:3000`
3. **Start the servers:**
```bash
# Terminal 1
make run-backend
# Terminal 2
make run-frontend
```
4. **Start developing!**
- Frontend: `http://localhost:3000`
- Login with: `test123@gmail.com` / `testpassword123`
## 🏗️ Architecture
**Dependencies run in Docker** (cached by prebuild):
- PostgreSQL, Redis, RabbitMQ, Supabase Auth
**Backend & Frontend run natively** (not cached):
- This ensures you're always running the current branch's code
- Enables hot-reload during development
- VS Code debugger can attach directly
## 📍 Available Services
| Service | URL | Notes |

View File

@@ -2,9 +2,14 @@
# =============================================================================
# ONCREATE SCRIPT - Runs during prebuild
# =============================================================================
# This script is executed during the prebuild phase. Its job is to do all the
# heavy lifting that takes time: installing dependencies, pulling Docker images,
# generating code, etc. This makes codespace creation nearly instant.
# This script runs during the prebuild phase (GitHub Actions).
# It caches everything that's safe to cache:
# ✅ Dependency Docker images (postgres, redis, rabbitmq, etc.)
# ✅ Python packages (poetry install)
# ✅ Node packages (pnpm install)
#
# It does NOT build backend/frontend Docker images because those would
# contain stale code from the prebuild branch, not the PR being reviewed.
# =============================================================================
set -e # Exit on error
@@ -32,7 +37,7 @@ fi
# Install Python dependencies
poetry install --no-interaction --no-ansi
# Generate Prisma client (can be done without DB)
# Generate Prisma client (schema only, no DB needed)
echo "🔧 Generating Prisma client..."
poetry run prisma generate || true
poetry run gen-prisma-stub || true
@@ -55,34 +60,36 @@ fi
# Install Node dependencies
pnpm install --frozen-lockfile
# Generate API client types (if possible without backend running)
pnpm generate:api-client || echo "API client generation skipped (backend not running)"
cd ..
# =============================================================================
# Pull Docker Images (in parallel for speed)
# Pull Dependency Docker Images ONLY
# =============================================================================
echo "🐳 Pulling Docker images..."
# We only pull infrastructure images. Backend/Frontend run natively
# to ensure we always use the current branch's code.
# =============================================================================
echo "🐳 Pulling dependency Docker images..."
# Start Docker daemon if using docker-in-docker
if [ -e /var/run/docker-host.sock ]; then
sudo ln -sf /var/run/docker-host.sock /var/run/docker.sock || true
fi
# Pull images in parallel using background processes
# Pull dependency images in parallel
docker pull supabase/gotrue:v2.170.0 &
docker pull supabase/studio:20250224-d10db0f &
docker pull kong:2.8.1 &
docker pull supabase/postgres:15.8.1.060 &
docker pull redis:latest &
docker pull rabbitmq:management &
docker pull clamav/clamav-debian:latest &
# Wait for all pulls to complete
wait
echo "✅ Docker images pulled"
echo "✅ Dependency images pulled"
# NOTE: We intentionally do NOT build backend/frontend images here.
# Those need to use the current branch's code, not prebuild's code.
# =============================================================================
# Copy environment files
@@ -114,6 +121,13 @@ echo "=============================================="
echo "✅ PREBUILD COMPLETE"
echo "=============================================="
echo ""
echo "Dependencies installed, images pulled."
echo "Cached:"
echo " ✅ Python packages (poetry)"
echo " ✅ Node packages (pnpm)"
echo " ✅ Dependency Docker images"
echo ""
echo "NOT cached (intentionally):"
echo " ❌ Backend/Frontend containers (would have stale code)"
echo ""
echo "The postcreate script will start services."
echo ""

View File

@@ -3,7 +3,10 @@
# POSTCREATE SCRIPT - Runs after container creation
# =============================================================================
# This script runs once when a codespace is first created. It starts the
# services, runs migrations, and seeds the database with test data.
# dependency services and prepares the environment for development.
#
# NOTE: Backend and Frontend run NATIVELY (not in Docker) to ensure you're
# always running the current branch's code, not stale prebuild code.
# =============================================================================
set -e # Exit on error
@@ -25,11 +28,14 @@ timeout 60 bash -c 'until docker info &>/dev/null; do sleep 1; done'
echo "✅ Docker is ready"
# =============================================================================
# Start Core Services
# Start Dependency Services ONLY
# =============================================================================
echo "🐳 Starting Docker services..."
# We only start infrastructure deps in Docker.
# Backend/Frontend run natively to use the current branch's code.
# =============================================================================
echo "🐳 Starting dependency services..."
# Start services (Supabase DB, Auth, Kong, Redis, RabbitMQ)
# Start core dependencies (DB, Auth, Redis, RabbitMQ)
docker compose up -d db redis rabbitmq kong auth
# Wait for PostgreSQL to be healthy
@@ -42,11 +48,12 @@ done
'
echo "✅ PostgreSQL is ready"
# Wait for other services
# Wait for Redis
echo "⏳ Waiting for Redis..."
timeout 60 bash -c 'until docker compose exec -T redis redis-cli ping &>/dev/null; do sleep 1; done'
echo "✅ Redis is ready"
# Wait for RabbitMQ
echo "⏳ Waiting for RabbitMQ..."
timeout 90 bash -c 'until docker compose exec -T rabbitmq rabbitmq-diagnostics -q ping &>/dev/null; do sleep 2; done'
echo "✅ RabbitMQ is ready"
@@ -69,9 +76,9 @@ poetry run gen-prisma-stub || true
cd ..
# =============================================================================
# Seed Test Data
# Seed Test Data (Minimal)
# =============================================================================
echo "🌱 Seeding test data..."
echo "🌱 Checking test data..."
cd backend
@@ -96,17 +103,6 @@ fi
cd ..
# =============================================================================
# Start Backend Services (optional - for immediate use)
# =============================================================================
echo "🚀 Starting backend services..."
# Start remaining services
docker compose up -d migrate
sleep 5 # Wait for migration container
docker compose up -d rest_server executor websocket_server database_manager
# =============================================================================
# Print Welcome Message
# =============================================================================
@@ -115,20 +111,21 @@ echo "=============================================="
echo "🎉 CODESPACE READY!"
echo "=============================================="
echo ""
echo "📍 Quick Links (will auto-forward):"
echo " Frontend: http://localhost:3000"
echo " API: http://localhost:8006"
echo " Supabase: http://localhost:8000"
echo "📍 Services Running (Docker):"
echo " PostgreSQL: localhost:5432"
echo " Redis: localhost:6379"
echo " RabbitMQ: localhost:5672 (mgmt: 15672)"
echo " Supabase: localhost:8000"
echo ""
echo "🚀 Start Development:"
echo " make run-backend # Start backend (localhost:8006)"
echo " make run-frontend # Start frontend (localhost:3000)"
echo ""
echo " Or run both in separate terminals!"
echo ""
echo "🔑 Test Account:"
echo " Email: test123@gmail.com"
echo " Password: testpassword123"
echo ""
echo "🛠️ Development Commands:"
echo " make run-frontend # Start frontend dev server"
echo " make run-backend # Start backend dev server"
echo " make start-core # Start only core services"
echo " make test-data # Regenerate test data"
echo ""
echo "📚 See README.md for more info"
echo "📚 Full docs: .devcontainer/README.md"
echo ""

View File

@@ -7,10 +7,11 @@
# 2. Codespace resumes from stopped state
# 3. Codespace rebuilds
#
# It ensures services are running without doing heavy setup work.
# It ensures dependency services are running. Backend/Frontend are run
# manually by the developer for hot-reload during development.
# =============================================================================
echo "🔄 Starting services..."
echo "🔄 Starting dependency services..."
cd /workspaces/AutoGPT/autogpt_platform
@@ -25,19 +26,19 @@ timeout 30 bash -c 'until docker info &>/dev/null; do sleep 1; done' || {
exit 0
}
# Start all services (will be no-op for already running ones)
docker compose up -d
# Start only dependency services (not backend/frontend)
docker compose up -d db redis rabbitmq kong auth
# Quick health check
echo "⏳ Waiting for services..."
sleep 5
# Check if key services are running
if docker compose ps | grep -q "running"; then
echo "✅ Services are running"
echo "✅ Dependency services are running"
echo ""
echo "📍 Frontend: http://localhost:3000"
echo "📍 API: http://localhost:8006"
echo "🚀 Start development with:"
echo " make run-backend # Terminal 1"
echo " make run-frontend # Terminal 2"
else
echo "⚠️ Some services may not be running. Try: docker compose up -d"
fi