|
|
@@ -4,6 +4,7 @@ import (
|
|
|
"context"
|
|
|
"encoding/base64"
|
|
|
"net/http"
|
|
|
+ "sort"
|
|
|
"strings"
|
|
|
|
|
|
"github.com/porter-dev/porter/internal/kubernetes"
|
|
|
@@ -167,6 +168,31 @@ func (c *PorterYAMLFromRevisionHandler) ServeHTTP(w http.ResponseWriter, r *http
|
|
|
app = formatForExport(app, c.Config().ServerConf.AppRootDomain)
|
|
|
}
|
|
|
|
|
|
+ // sort services by name
|
|
|
+ sortedServices := app.Services
|
|
|
+ sort.Slice(sortedServices, func(i, j int) bool {
|
|
|
+ serviceTypeSortPriorityA, ok := serviceTypeSortPriority[sortedServices[i].Type]
|
|
|
+ if !ok {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ serviceTypeSortPriorityB, ok := serviceTypeSortPriority[sortedServices[j].Type]
|
|
|
+ if !ok {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if serviceTypeSortPriorityA != serviceTypeSortPriorityB {
|
|
|
+ return serviceTypeSortPriorityA < serviceTypeSortPriorityB
|
|
|
+ }
|
|
|
+ return sortedServices[i].Name < sortedServices[j].Name
|
|
|
+ })
|
|
|
+ app.Services = sortedServices
|
|
|
+
|
|
|
+ // sort env variables by key
|
|
|
+ sortedEnv := app.Env
|
|
|
+ sort.Slice(sortedEnv, func(i, j int) bool {
|
|
|
+ return sortedEnv[i].Key < sortedEnv[j].Key
|
|
|
+ })
|
|
|
+ app.Env = sortedEnv
|
|
|
+
|
|
|
porterYAMLString, err := yaml.Marshal(app)
|
|
|
if err != nil {
|
|
|
err = telemetry.Error(ctx, span, err, "error marshaling porter yaml")
|
|
|
@@ -443,3 +469,9 @@ func zeroOutValues(app v2.PorterApp) v2.PorterApp {
|
|
|
|
|
|
return app
|
|
|
}
|
|
|
+
|
|
|
+var serviceTypeSortPriority = map[v2.ServiceType]int{
|
|
|
+ v2.ServiceType_Web: 0,
|
|
|
+ v2.ServiceType_Worker: 1,
|
|
|
+ v2.ServiceType_Job: 2,
|
|
|
+}
|