Skip to content

Commit f28bcdb

Browse files
Auto-Start Development Servers Module (#316)
# Auto-Start Development Servers Module ## Summary /claim #204 Implements automatic detection and startup of development servers based on project detection as requested in #204. - ✅ **Multi-language support**: Node.js, Rails, Django, Flask, Spring Boot, Go, PHP, Rust, .NET - ✅ **Background execution**: Servers start automatically without user intervention - ✅ **Devcontainer.json integration**: Uses custom start commands when available - ✅ **Smart fallback**: Creates sample project when no existing projects found - ✅ **Comprehensive logging**: Full activity logs for troubleshooting https://github.com/user-attachments/assets/2eddf67c-3ac1-4e55-a5ba-79292d61e918 ## Addresses GitHub Issue Closes #204 - "Auto-start development servers based on project detection" --------- Co-authored-by: DevCats <[email protected]> Co-authored-by: DevCats <[email protected]>
1 parent cb55320 commit f28bcdb

File tree

5 files changed

+924
-0
lines changed

5 files changed

+924
-0
lines changed

registry/mavrickrishi/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ participating in LFX CNCF programs, and helping the developer community grow.
1919
## Modules
2020

2121
- **aws-ami-snapshot**: Create and manage AMI snapshots for Coder workspaces with restore capabilities
22+
- [auto-start-dev-server](modules/auto-start-dev-server/README.md) - Automatically detect and start development servers for various project types
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
---
2+
display_name: Auto-Start Development Servers
3+
description: Automatically detect and start development servers for various project types
4+
icon: ../../../../.icons/server.svg
5+
verified: false
6+
tags: [development, automation, servers]
7+
---
8+
9+
# Auto-Start Development Servers
10+
11+
Automatically detect and start development servers for various project types when a workspace starts. This module scans your workspace for common project structures and starts the appropriate development servers in the background without manual intervention.
12+
13+
```tf
14+
module "auto_start_dev_servers" {
15+
source = "registry.coder.com/mavrickrishi/auto-start-dev-server/coder"
16+
version = "1.0.0"
17+
agent_id = coder_agent.main.id
18+
}
19+
```
20+
21+
## Features
22+
23+
- **Multi-language support**: Detects and starts servers for Node.js, Python (Django/Flask), Ruby (Rails), Java (Spring Boot), Go, PHP, Rust, and .NET projects
24+
- **Smart script prioritization**: Prioritizes `dev` scripts over `start` scripts for better development experience
25+
- **Intelligent frontend detection**: Automatically identifies frontend projects (React, Vue, Angular, Next.js, Nuxt, Svelte, Vite) and prioritizes them for preview apps
26+
- **Devcontainer integration**: Respects custom start commands defined in `.devcontainer/devcontainer.json`
27+
- **Configurable scanning**: Adjustable directory scan depth and project type toggles
28+
- **Non-blocking startup**: Servers start in the background with configurable startup delay
29+
- **Comprehensive logging**: All server output and detection results logged to a central file
30+
- **Smart detection**: Uses project-specific files and configurations to identify project types
31+
- **Integrated live preview**: Automatically creates a preview app for the primary frontend project
32+
33+
## Supported Project Types
34+
35+
| Framework/Language | Detection Files | Start Commands (in priority order) |
36+
| ------------------ | -------------------------------------------- | ----------------------------------------------------- |
37+
| **Node.js/npm** | `package.json` | `npm run dev`, `npm run serve`, `npm start` (or yarn) |
38+
| **Ruby on Rails** | `Gemfile` with rails gem | `bundle exec rails server` |
39+
| **Django** | `manage.py` | `python manage.py runserver` |
40+
| **Flask** | `requirements.txt` with Flask | `python app.py/main.py/run.py` |
41+
| **Spring Boot** | `pom.xml` or `build.gradle` with spring-boot | `mvn spring-boot:run`, `gradle bootRun` |
42+
| **Go** | `go.mod` | `go run main.go` |
43+
| **PHP** | `composer.json` | `php -S 0.0.0.0:8080` |
44+
| **Rust** | `Cargo.toml` | `cargo run` |
45+
| **.NET** | `*.csproj` | `dotnet run` |
46+
47+
## Examples
48+
49+
### Basic Usage
50+
51+
```hcl
52+
module "auto_start" {
53+
source = "./modules/auto-start-dev-server"
54+
version = "1.0.0"
55+
agent_id = coder_agent.main.id
56+
}
57+
```
58+
59+
### Advanced Usage
60+
61+
```hcl
62+
module "auto_start_dev_servers" {
63+
source = "./modules/auto-start-dev-server"
64+
version = "1.0.0"
65+
agent_id = coder_agent.main.id
66+
67+
# Optional: Configure which project types to detect
68+
enable_npm = true
69+
enable_rails = true
70+
enable_django = true
71+
enable_flask = true
72+
enable_spring_boot = true
73+
enable_go = true
74+
enable_php = true
75+
enable_rust = true
76+
enable_dotnet = true
77+
78+
# Optional: Enable devcontainer.json integration
79+
enable_devcontainer = true
80+
81+
# Optional: Workspace directory to scan (supports environment variables)
82+
workspace_directory = "$HOME"
83+
84+
# Optional: Directory scan depth (1-5)
85+
scan_depth = 2
86+
87+
# Optional: Startup delay in seconds
88+
startup_delay = 10
89+
90+
# Optional: Log file path
91+
log_path = "/tmp/dev-servers.log"
92+
93+
# Optional: Enable automatic preview app (default: true)
94+
enable_preview_app = true
95+
}
96+
```
97+
98+
### Disable Preview App
99+
100+
```hcl
101+
module "auto_start" {
102+
source = "./modules/auto-start-dev-server"
103+
version = "1.0.0"
104+
agent_id = coder_agent.main.id
105+
106+
# Disable automatic preview app creation
107+
enable_preview_app = false
108+
}
109+
```
110+
111+
### Selective Project Types
112+
113+
```hcl
114+
module "auto_start" {
115+
source = "./modules/auto-start-dev-server"
116+
version = "1.0.0"
117+
agent_id = coder_agent.main.id
118+
119+
# Only enable web development projects
120+
enable_npm = true
121+
enable_rails = true
122+
enable_django = true
123+
enable_flask = true
124+
125+
# Disable other project types
126+
enable_spring_boot = false
127+
enable_go = false
128+
enable_php = false
129+
enable_rust = false
130+
enable_dotnet = false
131+
}
132+
```
133+
134+
### Deep Workspace Scanning
135+
136+
```hcl
137+
module "auto_start" {
138+
source = "./modules/auto-start-dev-server"
139+
version = "1.0.0"
140+
agent_id = coder_agent.main.id
141+
142+
workspace_directory = "/workspaces"
143+
scan_depth = 3
144+
startup_delay = 5
145+
log_path = "/var/log/dev-servers.log"
146+
}
147+
```
148+
149+
## License
150+
151+
This module is provided under the same license as the Coder Registry.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import { describe, expect, it } from "bun:test";
2+
import {
3+
runTerraformApply,
4+
runTerraformInit,
5+
testRequiredVariables,
6+
} from "~test";
7+
8+
describe("auto-start-dev-server", async () => {
9+
await runTerraformInit(import.meta.dir);
10+
11+
testRequiredVariables(import.meta.dir, {
12+
agent_id: "test-agent-123",
13+
});
14+
15+
it("validates scan_depth range", () => {
16+
const t1 = async () => {
17+
await runTerraformApply(import.meta.dir, {
18+
agent_id: "test-agent-123",
19+
scan_depth: "0",
20+
});
21+
};
22+
expect(t1).toThrow("Scan depth must be between 1 and 5");
23+
24+
const t2 = async () => {
25+
await runTerraformApply(import.meta.dir, {
26+
agent_id: "test-agent-123",
27+
scan_depth: "6",
28+
});
29+
};
30+
expect(t2).toThrow("Scan depth must be between 1 and 5");
31+
});
32+
33+
it("applies successfully with default values", async () => {
34+
await runTerraformApply(import.meta.dir, {
35+
agent_id: "test-agent-123",
36+
});
37+
});
38+
39+
it("applies successfully with all project types enabled", async () => {
40+
await runTerraformApply(import.meta.dir, {
41+
agent_id: "test-agent-123",
42+
enable_npm: "true",
43+
enable_rails: "true",
44+
enable_django: "true",
45+
enable_flask: "true",
46+
enable_spring_boot: "true",
47+
enable_go: "true",
48+
enable_php: "true",
49+
enable_rust: "true",
50+
enable_dotnet: "true",
51+
enable_devcontainer: "true",
52+
});
53+
});
54+
55+
it("applies successfully with all project types disabled", async () => {
56+
await runTerraformApply(import.meta.dir, {
57+
agent_id: "test-agent-123",
58+
enable_npm: "false",
59+
enable_rails: "false",
60+
enable_django: "false",
61+
enable_flask: "false",
62+
enable_spring_boot: "false",
63+
enable_go: "false",
64+
enable_php: "false",
65+
enable_rust: "false",
66+
enable_dotnet: "false",
67+
enable_devcontainer: "false",
68+
});
69+
});
70+
71+
it("applies successfully with custom configuration", async () => {
72+
await runTerraformApply(import.meta.dir, {
73+
agent_id: "test-agent-123",
74+
workspace_directory: "/custom/workspace",
75+
scan_depth: "3",
76+
startup_delay: "5",
77+
log_path: "/var/log/custom-dev-servers.log",
78+
display_name: "Custom Dev Server Startup",
79+
});
80+
});
81+
82+
it("validates scan_depth boundary values", async () => {
83+
// Test valid boundary values
84+
await runTerraformApply(import.meta.dir, {
85+
agent_id: "test-agent-123",
86+
scan_depth: "1",
87+
});
88+
89+
await runTerraformApply(import.meta.dir, {
90+
agent_id: "test-agent-123",
91+
scan_depth: "5",
92+
});
93+
});
94+
95+
it("applies with selective project type configuration", async () => {
96+
await runTerraformApply(import.meta.dir, {
97+
agent_id: "test-agent-123",
98+
enable_npm: "true",
99+
enable_django: "true",
100+
enable_go: "true",
101+
enable_rails: "false",
102+
enable_flask: "false",
103+
enable_spring_boot: "false",
104+
enable_php: "false",
105+
enable_rust: "false",
106+
enable_dotnet: "false",
107+
});
108+
});
109+
});

0 commit comments

Comments
 (0)