mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-01-09 15:17:59 -05:00
## Summary This PR adds the frontend service to the Docker Compose configuration, enabling `docker compose up` to run the complete stack including the frontend. It also implements comprehensive environment variable improvements and fixes Docker networking issues. ## Key Changes ### 🐳 Docker Compose Improvements - **Added frontend service** to `docker-compose.yml` and `docker-compose.platform.yml` - **Production build**: Uses `pnpm build + serve` instead of dev server for better stability and lower memory usage - **Service dependencies**: Frontend now waits for backend services (`rest_server`, `websocket_server`) to be ready - **YAML anchors**: Implemented DRY configuration to avoid duplicating environment values ### 🔧 Environment Variable Architecture - **Dual environment strategy**: - Server-side code uses Docker service names (`http://rest_server:8006/api`) - Client-side code uses localhost URLs (`http://localhost:8006/api`) - **Comprehensive config**: Added build args and runtime environment variables - **Network compatibility**: Fixes connection issues between frontend and backend containers ### 🛠️ Code Improvements - **Centralized env-config helper** (`/frontend/src/lib/env-config.ts`) with server-side priority - **Updated all frontend code** to use shared environment helpers instead of direct `process.env` access - **Consistent API**: All environment variable access now goes through helper functions ### 🔗 Files Changed - `docker-compose.yml` & `docker-compose.platform.yml` - Added frontend service - `frontend/Dockerfile` - Added build args for environment variables - `frontend/src/lib/env-config.ts` - New centralized environment configuration - Multiple frontend files - Updated to use env helpers ## Benefits - ✅ **Single command deployment**: `docker compose up` now runs everything - ✅ **Better reliability**: Production build reduces memory usage and crashes - ✅ **Network compatibility**: Proper container-to-container communication - ✅ **Maintainable config**: Centralized environment variable management - ✅ **Development friendly**: Works in both Docker and local development ## Testing - ✅ Verified Docker service communication works correctly - ✅ Frontend responds and serves content properly - ✅ Environment variables are correctly resolved in both server and client contexts - ✅ No connection errors after implementing service dependencies 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude <noreply@anthropic.com>
278 lines
8.5 KiB
YAML
278 lines
8.5 KiB
YAML
name: AutoGPT Platform - Frontend CI
|
|
|
|
on:
|
|
push:
|
|
branches: [master, dev]
|
|
paths:
|
|
- ".github/workflows/platform-frontend-ci.yml"
|
|
- "autogpt_platform/frontend/**"
|
|
pull_request:
|
|
paths:
|
|
- ".github/workflows/platform-frontend-ci.yml"
|
|
- "autogpt_platform/frontend/**"
|
|
merge_group:
|
|
|
|
defaults:
|
|
run:
|
|
shell: bash
|
|
working-directory: autogpt_platform/frontend
|
|
|
|
jobs:
|
|
setup:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
cache-key: ${{ steps.cache-key.outputs.key }}
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "21"
|
|
|
|
- name: Enable corepack
|
|
run: corepack enable
|
|
|
|
- name: Generate cache key
|
|
id: cache-key
|
|
run: echo "key=${{ runner.os }}-pnpm-${{ hashFiles('autogpt_platform/frontend/pnpm-lock.yaml', 'autogpt_platform/frontend/package.json') }}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Cache dependencies
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.pnpm-store
|
|
key: ${{ steps.cache-key.outputs.key }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pnpm-${{ hashFiles('autogpt_platform/frontend/pnpm-lock.yaml') }}
|
|
${{ runner.os }}-pnpm-
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
lint:
|
|
runs-on: ubuntu-latest
|
|
needs: setup
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "21"
|
|
|
|
- name: Enable corepack
|
|
run: corepack enable
|
|
|
|
- name: Restore dependencies cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.pnpm-store
|
|
key: ${{ needs.setup.outputs.cache-key }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pnpm-${{ hashFiles('autogpt_platform/frontend/pnpm-lock.yaml') }}
|
|
${{ runner.os }}-pnpm-
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: Run lint
|
|
run: pnpm lint
|
|
|
|
type-check:
|
|
runs-on: ubuntu-latest
|
|
needs: setup
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "21"
|
|
|
|
- name: Enable corepack
|
|
run: corepack enable
|
|
|
|
- name: Restore dependencies cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.pnpm-store
|
|
key: ${{ needs.setup.outputs.cache-key }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pnpm-${{ hashFiles('autogpt_platform/frontend/pnpm-lock.yaml') }}
|
|
${{ runner.os }}-pnpm-
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: Run tsc check
|
|
run: pnpm type-check
|
|
|
|
chromatic:
|
|
runs-on: ubuntu-latest
|
|
needs: setup
|
|
# Only run on dev branch pushes or PRs targeting dev
|
|
if: github.ref == 'refs/heads/dev' || github.base_ref == 'dev'
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "21"
|
|
|
|
- name: Enable corepack
|
|
run: corepack enable
|
|
|
|
- name: Restore dependencies cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.pnpm-store
|
|
key: ${{ needs.setup.outputs.cache-key }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pnpm-${{ hashFiles('autogpt_platform/frontend/pnpm-lock.yaml') }}
|
|
${{ runner.os }}-pnpm-
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: Run Chromatic
|
|
uses: chromaui/action@latest
|
|
with:
|
|
projectToken: chpt_9e7c1a76478c9c8
|
|
onlyChanged: true
|
|
workingDir: autogpt_platform/frontend
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
exitOnceUploaded: true
|
|
|
|
test:
|
|
runs-on: big-boi
|
|
needs: setup
|
|
strategy:
|
|
fail-fast: false
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
submodules: recursive
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "21"
|
|
|
|
- name: Enable corepack
|
|
run: corepack enable
|
|
|
|
- name: Copy default supabase .env
|
|
run: |
|
|
cp ../.env.example ../.env
|
|
|
|
- name: Copy backend .env
|
|
run: |
|
|
cp ../backend/.env.example ../backend/.env
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Cache Docker layers
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: /tmp/.buildx-cache
|
|
key: ${{ runner.os }}-buildx-frontend-test-${{ hashFiles('autogpt_platform/docker-compose.yml', 'autogpt_platform/backend/Dockerfile', 'autogpt_platform/backend/pyproject.toml', 'autogpt_platform/backend/poetry.lock') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-buildx-frontend-test-
|
|
|
|
- name: Run docker compose
|
|
run: |
|
|
NEXT_PUBLIC_PW_TEST=true docker compose -f ../docker-compose.yml up -d
|
|
env:
|
|
DOCKER_BUILDKIT: 1
|
|
BUILDX_CACHE_FROM: type=local,src=/tmp/.buildx-cache
|
|
BUILDX_CACHE_TO: type=local,dest=/tmp/.buildx-cache-new,mode=max
|
|
|
|
- name: Move cache
|
|
run: |
|
|
rm -rf /tmp/.buildx-cache
|
|
if [ -d "/tmp/.buildx-cache-new" ]; then
|
|
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
|
|
fi
|
|
|
|
- name: Wait for services to be ready
|
|
run: |
|
|
echo "Waiting for rest_server to be ready..."
|
|
timeout 60 sh -c 'until curl -f http://localhost:8006/health 2>/dev/null; do sleep 2; done' || echo "Rest server health check timeout, continuing..."
|
|
echo "Waiting for database to be ready..."
|
|
timeout 60 sh -c 'until docker compose -f ../docker-compose.yml exec -T db pg_isready -U postgres 2>/dev/null; do sleep 2; done' || echo "Database ready check timeout, continuing..."
|
|
|
|
- name: Create E2E test data
|
|
run: |
|
|
echo "Creating E2E test data..."
|
|
# First try to run the script from inside the container
|
|
if docker compose -f ../docker-compose.yml exec -T rest_server test -f /app/autogpt_platform/backend/test/e2e_test_data.py; then
|
|
echo "✅ Found e2e_test_data.py in container, running it..."
|
|
docker compose -f ../docker-compose.yml exec -T rest_server sh -c "cd /app/autogpt_platform && python backend/test/e2e_test_data.py" || {
|
|
echo "❌ E2E test data creation failed!"
|
|
docker compose -f ../docker-compose.yml logs --tail=50 rest_server
|
|
exit 1
|
|
}
|
|
else
|
|
echo "⚠️ e2e_test_data.py not found in container, copying and running..."
|
|
# Copy the script into the container and run it
|
|
docker cp ../backend/test/e2e_test_data.py $(docker compose -f ../docker-compose.yml ps -q rest_server):/tmp/e2e_test_data.py || {
|
|
echo "❌ Failed to copy script to container"
|
|
exit 1
|
|
}
|
|
docker compose -f ../docker-compose.yml exec -T rest_server sh -c "cd /app/autogpt_platform && python /tmp/e2e_test_data.py" || {
|
|
echo "❌ E2E test data creation failed!"
|
|
docker compose -f ../docker-compose.yml logs --tail=50 rest_server
|
|
exit 1
|
|
}
|
|
fi
|
|
|
|
- name: Restore dependencies cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.pnpm-store
|
|
key: ${{ needs.setup.outputs.cache-key }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pnpm-${{ hashFiles('autogpt_platform/frontend/pnpm-lock.yaml') }}
|
|
${{ runner.os }}-pnpm-
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: Setup .env
|
|
run: cp .env.example .env
|
|
|
|
- name: Build frontend
|
|
run: pnpm build --turbo
|
|
# uses Turbopack, much faster and safe enough for a test pipeline
|
|
|
|
- name: Install Browser 'chromium'
|
|
run: pnpm playwright install --with-deps chromium
|
|
|
|
- name: Run Playwright tests
|
|
run: pnpm test:no-build
|
|
|
|
- name: Upload Playwright artifacts
|
|
if: failure()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: playwright-report
|
|
path: playwright-report
|
|
|
|
- name: Print Final Docker Compose logs
|
|
if: always()
|
|
run: docker compose -f ../docker-compose.yml logs
|