-
Notifications
You must be signed in to change notification settings - Fork 548
feat: add support for external server mode with Docker integration #376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+330
−21
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ import { | |
| verifySession, | ||
| checkSandboxEnvironment, | ||
| getServerUrlSync, | ||
| checkExternalServerMode, | ||
| isExternalServerMode, | ||
| } from '@/lib/http-api-client'; | ||
| import { Toaster } from 'sonner'; | ||
| import { ThemeOption, themeOptions } from '@/config/theme-options'; | ||
|
|
@@ -188,13 +190,16 @@ function RootLayoutContent() { | |
| // Initialize API key for Electron mode | ||
| await initApiKey(); | ||
|
|
||
| // In Electron mode, we're always authenticated via header | ||
| if (isElectronMode()) { | ||
| // Check if running in external server mode (Docker API) | ||
| const externalMode = await checkExternalServerMode(); | ||
|
|
||
| // In Electron mode (but NOT external server mode), we're always authenticated via header | ||
| if (isElectronMode() && !externalMode) { | ||
| useAuthStore.getState().setAuthState({ isAuthenticated: true, authChecked: true }); | ||
| return; | ||
| } | ||
|
|
||
| // In web mode, verify the session cookie is still valid | ||
| // In web mode OR external server mode, verify the session cookie is still valid | ||
| // by making a request to an authenticated endpoint | ||
| const isValid = await verifySession(); | ||
|
|
||
|
|
@@ -235,17 +240,20 @@ function RootLayoutContent() { | |
| }; | ||
| }, []); | ||
|
|
||
| // Routing rules (web mode): | ||
| // Routing rules (web mode and external server mode): | ||
| // - If not authenticated: force /login (even /setup is protected) | ||
| // - If authenticated but setup incomplete: force /setup | ||
| useEffect(() => { | ||
| if (!setupHydrated) return; | ||
|
|
||
| // Check if we need session-based auth (web mode OR external server mode) | ||
| const needsSessionAuth = !isElectronMode() || isExternalServerMode() === true; | ||
|
|
||
| // Wait for auth check to complete before enforcing any redirects | ||
| if (!isElectronMode() && !authChecked) return; | ||
| if (needsSessionAuth && !authChecked) return; | ||
|
|
||
| // Unauthenticated -> force /login | ||
| if (!isElectronMode() && !isAuthenticated) { | ||
| if (needsSessionAuth && !isAuthenticated) { | ||
| if (location.pathname !== '/login') { | ||
| navigate({ to: '/login' }); | ||
| } | ||
|
|
@@ -351,18 +359,21 @@ function RootLayoutContent() { | |
| ); | ||
| } | ||
|
|
||
| // Wait for auth check before rendering protected routes (web mode only) | ||
| if (!isElectronMode() && !authChecked) { | ||
| // Check if we need session-based auth (web mode OR external server mode) | ||
| const needsSessionAuth = !isElectronMode() || isExternalServerMode() === true; | ||
|
Comment on lines
+362
to
+363
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| // Wait for auth check before rendering protected routes (web mode and external server mode) | ||
| if (needsSessionAuth && !authChecked) { | ||
| return ( | ||
| <main className="flex h-screen items-center justify-center" data-testid="app-container"> | ||
| <LoadingState message="Loading..." /> | ||
| </main> | ||
| ); | ||
| } | ||
|
|
||
| // Redirect to login if not authenticated (web mode) | ||
| // Redirect to login if not authenticated (web mode and external server mode) | ||
| // Show loading state while navigation to login is in progress | ||
| if (!isElectronMode() && !isAuthenticated) { | ||
| if (needsSessionAuth && !isAuthenticated) { | ||
| return ( | ||
| <main className="flex h-screen items-center justify-center" data-testid="app-container"> | ||
| <LoadingState message="Redirecting to login..." /> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| # Automaker Docker Compose - Server Only (Development Mode) | ||
| # Runs only the backend API in a container for use with local Electron. | ||
| # | ||
| # Usage: | ||
| # docker compose -f docker-compose.dev-server.yml up | ||
| # Then run Electron locally which connects to http://localhost:3008 | ||
| # | ||
| # This mode: | ||
| # - Runs only the backend server in a container | ||
| # - Mounts source code as volumes (live reload) | ||
| # - Server runs with tsx watch for TypeScript changes | ||
| # - Electron runs locally on host machine | ||
|
|
||
| services: | ||
| # Development server (backend API only) | ||
| server: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile.dev | ||
| container_name: automaker-dev-server-only | ||
| restart: unless-stopped | ||
| ports: | ||
| - '3008:3008' | ||
| environment: | ||
| # Required | ||
| - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} | ||
|
|
||
| # Optional - Claude CLI OAuth credentials | ||
| - CLAUDE_OAUTH_CREDENTIALS=${CLAUDE_OAUTH_CREDENTIALS:-} | ||
|
|
||
| # Optional - Cursor CLI OAuth token | ||
| - CURSOR_AUTH_TOKEN=${CURSOR_AUTH_TOKEN:-} | ||
|
|
||
| # Optional - authentication | ||
| - AUTOMAKER_API_KEY=${AUTOMAKER_API_KEY:-} | ||
|
|
||
| # Development settings | ||
| - NODE_ENV=development | ||
| - PORT=3008 | ||
| - CORS_ORIGIN=http://localhost:3007 | ||
|
|
||
| # Optional - restrict to specific directory within container | ||
| - ALLOWED_ROOT_DIRECTORY=${ALLOWED_ROOT_DIRECTORY:-/projects} | ||
| - DATA_DIR=/data | ||
|
|
||
| # Internal - indicates containerized environment | ||
| - IS_CONTAINERIZED=true | ||
| volumes: | ||
| # Mount source code for live reload | ||
| - .:/app:cached | ||
|
|
||
| # Use named volume for node_modules to avoid platform conflicts | ||
| # This ensures native modules are built for the container's architecture | ||
| - automaker-dev-node-modules:/app/node_modules | ||
|
|
||
| # Persist data across restarts | ||
| - automaker-data:/data | ||
|
|
||
| # Persist CLI configurations | ||
| - automaker-claude-config:/home/automaker/.claude | ||
| - automaker-cursor-config:/home/automaker/.cursor | ||
|
|
||
| # Note: Workspace mount (/projects) comes from docker-compose.override.yml | ||
|
|
||
| # Install deps, build packages, then start server in watch mode | ||
| # Note: We override the entrypoint to handle permissions properly | ||
| entrypoint: /bin/sh | ||
| command: | ||
| - -c | ||
| - | | ||
| # Fix permissions on node_modules (created as root by Docker volume) | ||
| echo 'Fixing node_modules permissions...' | ||
| chown -R automaker:automaker /app/node_modules 2>/dev/null || true | ||
|
|
||
| # Run the rest as automaker user | ||
| exec gosu automaker sh -c " | ||
| echo 'Installing dependencies...' && | ||
| npm install && | ||
| echo 'Building shared packages...' && | ||
| npm run build:packages && | ||
| echo 'Starting server in development mode...' && | ||
| npm run _dev:server | ||
| " | ||
| healthcheck: | ||
| test: ['CMD', 'curl', '-f', 'http://localhost:3008/api/health'] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
| start_period: 60s | ||
|
|
||
| volumes: | ||
| automaker-dev-node-modules: | ||
| name: automaker-dev-node-modules | ||
| # Named volume for container-specific node_modules | ||
|
|
||
| automaker-data: | ||
| name: automaker-data | ||
|
|
||
| automaker-claude-config: | ||
| name: automaker-claude-config | ||
|
|
||
| automaker-cursor-config: | ||
| name: automaker-cursor-config |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of
as anyto accessisExternalServerModeindicates that the type definition forwindow.electronAPI(likelyElectronAPI) is missing this new property. While this works, it bypasses TypeScript's type safety. To improve maintainability and type safety, theElectronAPIinterface should be updated to include the optionalisExternalServerModemethod. This would remove the need for the type assertion.