2026-01-29 02:16:01 +00:00
|
|
|
package devops
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"path/filepath"
|
2026-02-04 15:22:55 +00:00
|
|
|
|
|
|
|
|
"github.com/host-uk/core/pkg/io"
|
2026-01-29 02:16:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// ServeOptions configures the dev server.
|
|
|
|
|
type ServeOptions struct {
|
|
|
|
|
Port int // Port to serve on (default 8000)
|
|
|
|
|
Path string // Subdirectory to serve (default: current dir)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Serve mounts the project and starts a dev server.
|
|
|
|
|
func (d *DevOps) Serve(ctx context.Context, projectDir string, opts ServeOptions) error {
|
|
|
|
|
running, err := d.IsRunning(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if !running {
|
|
|
|
|
return fmt.Errorf("dev environment not running (run 'core dev boot' first)")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if opts.Port == 0 {
|
|
|
|
|
opts.Port = 8000
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
servePath := projectDir
|
|
|
|
|
if opts.Path != "" {
|
|
|
|
|
servePath = filepath.Join(projectDir, opts.Path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mount project directory via SSHFS
|
|
|
|
|
if err := d.mountProject(ctx, servePath); err != nil {
|
|
|
|
|
return fmt.Errorf("failed to mount project: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Detect and run serve command
|
2026-02-04 15:22:55 +00:00
|
|
|
serveCmd := DetectServeCommand(d.medium, servePath)
|
2026-01-29 02:16:01 +00:00
|
|
|
fmt.Printf("Starting server: %s\n", serveCmd)
|
|
|
|
|
fmt.Printf("Listening on http://localhost:%d\n", opts.Port)
|
|
|
|
|
|
|
|
|
|
// Run serve command via SSH
|
|
|
|
|
return d.sshShell(ctx, []string{"cd", "/app", "&&", serveCmd})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// mountProject mounts a directory into the VM via SSHFS.
|
|
|
|
|
func (d *DevOps) mountProject(ctx context.Context, path string) error {
|
|
|
|
|
absPath, err := filepath.Abs(path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use reverse SSHFS mount
|
|
|
|
|
// The VM connects back to host to mount the directory
|
|
|
|
|
cmd := exec.CommandContext(ctx, "ssh",
|
feat: infrastructure packages and lint cleanup (#281)
* ci: consolidate duplicate workflows and merge CodeQL configs
Remove 17 duplicate workflow files that were split copies of the
combined originals. Each family (CI, CodeQL, Coverage, PR Build,
Alpha Release) had the same job duplicated across separate
push/pull_request/schedule/manual trigger files.
Merge codeql.yml and codescan.yml into a single codeql.yml with
a language matrix covering go, javascript-typescript, python,
and actions — matching the previous default setup coverage.
Remaining workflows (one per family):
- ci.yml (push + PR + manual)
- codeql.yml (push + PR + schedule, all languages)
- coverage.yml (push + PR + manual)
- alpha-release.yml (push + manual)
- pr-build.yml (PR + manual)
- release.yml (tag push)
- agent-verify.yml, auto-label.yml, auto-project.yml
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat: add collect, config, crypt, plugin packages and fix all lint issues
Add four new infrastructure packages with CLI commands:
- pkg/config: layered configuration (defaults → file → env → flags)
- pkg/crypt: crypto primitives (Argon2id, AES-GCM, ChaCha20, HMAC, checksums)
- pkg/plugin: plugin system with GitHub-based install/update/remove
- pkg/collect: collection subsystem (GitHub, BitcoinTalk, market, papers, excavate)
Fix all golangci-lint issues across the entire codebase (~100 errcheck,
staticcheck SA1012/SA1019/ST1005, unused, ineffassign fixes) so that
`core go qa` passes with 0 issues.
Closes #167, #168, #170, #250, #251, #252, #253, #254, #255, #256
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 11:34:43 +00:00
|
|
|
"-o", "StrictHostKeyChecking=accept-new",
|
|
|
|
|
"-o", "UserKnownHostsFile=~/.core/known_hosts",
|
2026-01-29 02:16:01 +00:00
|
|
|
"-o", "LogLevel=ERROR",
|
|
|
|
|
"-R", "10000:localhost:22", // Reverse tunnel for SSHFS
|
|
|
|
|
"-p", "2222",
|
|
|
|
|
"root@localhost",
|
|
|
|
|
fmt.Sprintf("mkdir -p /app && sshfs -p 10000 %s@localhost:%s /app -o allow_other", os.Getenv("USER"), absPath),
|
|
|
|
|
)
|
|
|
|
|
return cmd.Run()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DetectServeCommand auto-detects the serve command for a project.
|
2026-02-04 15:22:55 +00:00
|
|
|
func DetectServeCommand(m io.Medium, projectDir string) string {
|
2026-01-29 02:16:01 +00:00
|
|
|
// Laravel/Octane
|
2026-02-04 15:22:55 +00:00
|
|
|
if hasFile(m, projectDir, "artisan") {
|
2026-01-29 02:16:01 +00:00
|
|
|
return "php artisan octane:start --host=0.0.0.0 --port=8000"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Node.js with dev script
|
2026-02-04 15:22:55 +00:00
|
|
|
if hasFile(m, projectDir, "package.json") {
|
|
|
|
|
if hasPackageScript(m, projectDir, "dev") {
|
2026-01-29 02:16:01 +00:00
|
|
|
return "npm run dev -- --host 0.0.0.0"
|
|
|
|
|
}
|
2026-02-04 15:22:55 +00:00
|
|
|
if hasPackageScript(m, projectDir, "start") {
|
2026-01-29 02:16:01 +00:00
|
|
|
return "npm start"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PHP with composer
|
2026-02-04 15:22:55 +00:00
|
|
|
if hasFile(m, projectDir, "composer.json") {
|
2026-01-29 02:16:01 +00:00
|
|
|
return "frankenphp php-server -l :8000"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Go
|
2026-02-04 15:22:55 +00:00
|
|
|
if hasFile(m, projectDir, "go.mod") {
|
|
|
|
|
if hasFile(m, projectDir, "main.go") {
|
2026-01-29 02:16:01 +00:00
|
|
|
return "go run ."
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Python Django
|
2026-02-04 15:22:55 +00:00
|
|
|
if hasFile(m, projectDir, "manage.py") {
|
2026-01-29 02:16:01 +00:00
|
|
|
return "python manage.py runserver 0.0.0.0:8000"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fallback: simple HTTP server
|
|
|
|
|
return "python3 -m http.server 8000"
|
|
|
|
|
}
|