Files
ghaymah_dev2 618e74277a
ci / build (push) Canceled after 0s
gy CLI: deploy any directory to a live URL
Commands: login/logout/whoami, deploy (TUI + plain/JSON/CI), logs, status, open, list, version.

- deploy pipeline: tar.gz source (gitignore/dockerignore aware) -> presigned upload -> cloud kaniko/buildpacks build -> live URL
- bubbletea/lipgloss TUI with upload progress + live log streaming; auto-falls-back to plain output in CI
- apiclient against the gateway /v1/deployments + /v1/apps endpoints
- GitHub Action (action.yml) + example workflow + install script
2026-10-24 05:18:43 -04:00

101 lines
2.2 KiB
Go

package source
import (
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
)
// Detection result for a project directory.
type Detection struct {
Strategy string // "auto" (the server cascades dockerfile → buildpacks)
HasDockerfile bool
Port int
Name string // sanitized app name derived from the folder
}
// Detect inspects dir and returns build strategy + port + a safe app name.
func Detect(dir string) Detection {
d := Detection{Strategy: "auto"}
if _, err := os.Stat(filepath.Join(dir, "Dockerfile")); err == nil {
d.HasDockerfile = true
}
d.Port = detectPort(dir, d.HasDockerfile)
d.Name = sanitizeName(filepath.Base(dir))
return d
}
// detectPort returns the app's HTTP port: Dockerfile EXPOSE, then ghaymah.yml
// run.port, then the default 8080.
func detectPort(dir string, hasDockerfile bool) int {
if hasDockerfile {
if p := parseExpose(filepath.Join(dir, "Dockerfile")); p > 0 {
return p
}
}
if p := yamlPort(dir); p > 0 {
return p
}
return 8080
}
var exposeRe = regexp.MustCompile(`(?mi)^\s*EXPOSE\s+(\d+)`)
func parseExpose(path string) int {
data, err := os.ReadFile(path)
if err != nil {
return 0
}
matches := exposeRe.FindAllSubmatch(data, -1)
if len(matches) == 0 {
return 0
}
var p int
for _, m := range matches {
p, _ = strconv.Atoi(string(m[1]))
}
return p
}
var yamlPortRe = regexp.MustCompile(`(?m)^\s*port\s*:\s*(\d+)`)
func yamlPort(dir string) int {
for _, name := range []string{"ghaymah.yml", "ghaymah.yaml"} {
data, err := os.ReadFile(filepath.Join(dir, name))
if err != nil {
continue
}
m := yamlPortRe.FindSubmatch(data)
if len(m) == 2 {
if p, err := strconv.Atoi(string(m[1])); err == nil && p > 0 {
return p
}
}
}
return 0
}
// sanitizeName lowercases and replaces invalid Cumin app-name characters.
func sanitizeName(s string) string {
s = strings.ToLower(strings.TrimSpace(s))
var b strings.Builder
for _, r := range s {
switch {
case r >= 'a' && r <= 'z', r >= '0' && r <= '9', r == '-', r == '.', r == '_':
b.WriteRune(r)
default:
b.WriteRune('-')
}
}
out := strings.Trim(b.String(), "-._")
if out == "" {
out = "app"
}
if len(out) > 50 {
out = out[:50]
}
return out
}