DodoApp: Support PHP 8.2

Change-Id: I7cfe082c66a0efe0b3b9c85433a96623466ced5c
diff --git a/core/installer/welcome/app-tmpl/php-8.2-apache/app.cue.gotmpl b/core/installer/welcome/app-tmpl/php-8.2-apache/app.cue.gotmpl
new file mode 100755
index 0000000..fa925fe
--- /dev/null
+++ b/core/installer/welcome/app-tmpl/php-8.2-apache/app.cue.gotmpl
@@ -0,0 +1,8 @@
+app: {
+	type: "php:8.2-apache"
+	ingress: {
+		network: "{{ .Network.Name }}"
+		subdomain: "{{ .Subdomain }}"
+		auth: enabled: false
+	}
+}
diff --git a/core/installer/welcome/app-tmpl/php-8.2-apache/index.php b/core/installer/welcome/app-tmpl/php-8.2-apache/index.php
new file mode 100644
index 0000000..bb93008
--- /dev/null
+++ b/core/installer/welcome/app-tmpl/php-8.2-apache/index.php
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <title>dodo app: php 8.2</title>
+    </head>
+    <body>
+        <?php echo '<p>Hello from dodo: app</p>'; ?>
+		// <?php phpinfo(); ?>
+    </body>
+</html>
diff --git a/core/installer/welcome/app_tmpl.go b/core/installer/welcome/app_tmpl.go
index dae56f8..33f8d8d 100644
--- a/core/installer/welcome/app_tmpl.go
+++ b/core/installer/welcome/app_tmpl.go
@@ -4,6 +4,7 @@
 	"fmt"
 	"io"
 	"io/fs"
+	"sort"
 	"strings"
 	"text/template"
 
@@ -46,6 +47,16 @@
 	for t := range s.tmpls {
 		ret = append(ret, t)
 	}
+	sort.Slice(ret, func(i, j int) bool {
+		a := strings.SplitN(ret[i], ":", 2)
+		b := strings.SplitN(ret[j], ":", 2)
+		langCmp := strings.Compare(a[0], b[0])
+		if langCmp != 0 {
+			return langCmp < 0
+		}
+		// TODO(gio): compare semver?
+		return strings.Compare(a[1], b[1]) > 0
+	})
 	return ret
 }
 
diff --git a/core/installer/welcome/app_tmpl_test.go b/core/installer/welcome/app_tmpl_test.go
index fca6d12..ddd142c 100644
--- a/core/installer/welcome/app_tmpl_test.go
+++ b/core/installer/welcome/app_tmpl_test.go
@@ -81,3 +81,22 @@
 		t.Fatal(err)
 	}
 }
+
+func TestAppTmplPHP82(t *testing.T) {
+	d, err := fs.Sub(appTmpl, "app-tmpl")
+	if err != nil {
+		t.Fatal(err)
+	}
+	store, err := NewAppTmplStoreFS(d)
+	if err != nil {
+		t.Fatal(err)
+	}
+	a, err := store.Find("php-8.2-apache")
+	if err != nil {
+		t.Fatal(err)
+	}
+	out := soft.NewBillyRepoFS(memfs.New())
+	if err := a.Render(network, "testapp", out); err != nil {
+		t.Fatal(err)
+	}
+}
diff --git a/core/installer/welcome/dodo_app.go b/core/installer/welcome/dodo_app.go
index afcd627..87b003a 100644
--- a/core/installer/welcome/dodo_app.go
+++ b/core/installer/welcome/dodo_app.go
@@ -44,8 +44,6 @@
 	userCtx        = "user"
 )
 
-var types = []string{"golang:1.22.0", "golang:1.20.0", "hugo:latest"}
-
 type dodoAppTmplts struct {
 	index     *template.Template
 	appStatus *template.Template
@@ -373,6 +371,10 @@
 		http.Error(w, err.Error(), http.StatusInternalServerError)
 		return
 	}
+	var types []string
+	for _, t := range s.appTmpls.Types() {
+		types = append(types, strings.Replace(t, "-", ":", 1))
+	}
 	data := statusData{apps, networks, types}
 	if err := s.tmplts.index.Execute(w, data); err != nil {
 		http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -869,7 +871,7 @@
 }
 
 func (s *DodoAppServer) initRepo(repo soft.RepoIO, appType string, network installer.Network, subdomain string) error {
-	appType = strings.ReplaceAll(appType, ":", "-")
+	appType = strings.Replace(appType, ":", "-", 1)
 	appTmpl, err := s.appTmpls.Find(appType)
 	if err != nil {
 		return err
@@ -925,9 +927,8 @@
 		}
 	}
 	for _, t := range s.appTmpls.Types() {
-		ret.Types = append(ret.Types, strings.ReplaceAll(t, "-", ":"))
+		ret.Types = append(ret.Types, strings.Replace(t, "-", ":", 1))
 	}
-	w.Header().Set("Access-Control-Allow-Origin", "*")
 	if err := json.NewEncoder(w).Encode(ret); err != nil {
 		http.Error(w, err.Error(), http.StatusInternalServerError)
 		return