-
Notifications
You must be signed in to change notification settings - Fork 11
[CLI-24] Update service versions from the registry #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
akalipetis
merged 4 commits into
main
from
cli-24-platformify-does-not-have-the-latest-runtime-versions
Nov 17, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dadb141
feat(registry): update versions from the registry
akalipetis 7e3058f
feat(registry): automatically generate version file from registry
akalipetis 9f7636c
feat(services): regenerate services with ClickHouse/MySQL updates
akalipetis 2156164
fix(lint): weird gofmt fix
akalipetis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,288 @@ | ||
| //go:build ignore | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "fmt" | ||
| "go/format" | ||
| "io" | ||
| "log" | ||
| "net/http" | ||
| "os" | ||
| "path/filepath" | ||
| "sort" | ||
| "strings" | ||
| "text/template" | ||
| ) | ||
|
|
||
| const registryURL = "https://raw.githubusercontent.com/platformsh/platformsh-docs/main/shared/data/registry.json" | ||
|
|
||
| type Registry map[string]Service | ||
|
|
||
| type Service struct { | ||
| Description string `json:"description"` | ||
| Disk bool `json:"disk"` | ||
| Runtime bool `json:"runtime"` | ||
| Type string `json:"type"` | ||
| Versions map[string][]string `json:"versions"` | ||
| } | ||
|
|
||
| // Mapping from registry service names to our ServiceName constants | ||
| var serviceMapping = map[string]string{ | ||
| "chrome-headless": "ChromeHeadless", | ||
| "influxdb": "InfluxDB", | ||
| "kafka": "Kafka", | ||
| "mariadb": "MariaDB", | ||
| "memcached": "Memcached", | ||
| "mysql": "MySQL", | ||
| "network-storage": "NetworkStorage", | ||
| "opensearch": "OpenSearch", | ||
| "oracle-mysql": "OracleMySQL", | ||
| "postgresql": "PostgreSQL", | ||
| "rabbitmq": "RabbitMQ", | ||
| "redis": "Redis", | ||
| "solr": "Solr", | ||
| "varnish": "Varnish", | ||
| "vault-kms": "VaultKMS", | ||
| } | ||
|
|
||
| // Mapping from registry runtime names to our Runtime constants | ||
| var runtimeMapping = map[string]string{ | ||
| "dotnet": "DotNet", | ||
| "elixir": "Elixir", | ||
| "golang": "Golang", | ||
| "java": "Java", | ||
| "nodejs": "NodeJS", | ||
| "php": "PHP", | ||
| "python": "Python", | ||
| "ruby": "Ruby", | ||
| "rust": "Rust", | ||
| } | ||
|
|
||
| const versionTemplate = `//go:generate go run generate_versions.go | ||
| package models | ||
| var ( | ||
| LanguageTypeVersions = map[Runtime][]string{ | ||
| {{- range .Languages }} | ||
| {{ .Name }}: {{ .Versions }}, | ||
| {{- end }} | ||
| } | ||
| ServiceTypeVersions = map[ServiceName][]string{ | ||
| {{- range .Services }} | ||
| {{ .Name }}: {{ .Versions }}, | ||
| {{- end }} | ||
| } | ||
| ) | ||
| func DefaultVersionForRuntime(r Runtime) string { | ||
| versions := LanguageTypeVersions[r] | ||
| if len(versions) == 0 { | ||
| return "" | ||
| } | ||
| return versions[0] | ||
| } | ||
| ` | ||
|
|
||
| type TemplateData struct { | ||
| Languages []TypeVersion | ||
| Services []TypeVersion | ||
| } | ||
|
|
||
| type TypeVersion struct { | ||
| Name string | ||
| Versions string | ||
| } | ||
|
|
||
| func main() { | ||
| // Fetch the registry data | ||
| resp, err := http.Get(registryURL) | ||
| if err != nil { | ||
| log.Fatalf("Failed to fetch registry: %v", err) | ||
| } | ||
| defer resp.Body.Close() | ||
akalipetis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| body, err := io.ReadAll(resp.Body) | ||
| if err != nil { | ||
| log.Fatalf("Failed to read response: %v", err) | ||
| } | ||
|
|
||
| var registry Registry | ||
| if err := json.Unmarshal(body, ®istry); err != nil { | ||
| log.Fatalf("Failed to parse JSON: %v", err) | ||
| } | ||
|
|
||
| var languages []TypeVersion | ||
| var services []TypeVersion | ||
|
|
||
| // Process runtimes (languages) | ||
| for serviceName, service := range registry { | ||
| if !service.Runtime { | ||
| continue | ||
| } | ||
|
|
||
| constantName, exists := runtimeMapping[serviceName] | ||
| if !exists { | ||
| continue // Skip runtimes we don't support | ||
| } | ||
|
|
||
| supported := service.Versions["supported"] | ||
| if len(supported) == 0 { | ||
| continue | ||
| } | ||
|
|
||
| versions := formatVersionSlice(supported) | ||
| languages = append(languages, TypeVersion{ | ||
| Name: constantName, | ||
| Versions: versions, | ||
| }) | ||
| } | ||
|
|
||
| // Process services | ||
| for serviceName, service := range registry { | ||
| if service.Runtime { | ||
| continue | ||
| } | ||
|
|
||
| constantName, exists := serviceMapping[serviceName] | ||
| if !exists { | ||
| continue // Skip services we don't support | ||
| } | ||
|
|
||
| supported := service.Versions["supported"] | ||
| if len(supported) == 0 { | ||
| continue | ||
| } | ||
|
|
||
| versions := formatVersionSlice(supported) | ||
| services = append(services, TypeVersion{ | ||
| Name: constantName, | ||
| Versions: versions, | ||
| }) | ||
|
|
||
| // Add RedisPersistent right after Redis | ||
| if serviceName == "redis" { | ||
| services = append(services, TypeVersion{ | ||
| Name: "RedisPersistent", | ||
| Versions: versions, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // Sort for consistent output | ||
| sort.Slice(languages, func(i, j int) bool { | ||
| return languages[i].Name < languages[j].Name | ||
| }) | ||
| sort.Slice(services, func(i, j int) bool { | ||
| return services[i].Name < services[j].Name | ||
| }) | ||
|
|
||
| // Generate the Go code | ||
| tmpl, err := template.New("version").Parse(versionTemplate) | ||
| if err != nil { | ||
| log.Fatalf("Failed to parse template: %v", err) | ||
| } | ||
|
|
||
| var buf bytes.Buffer | ||
| data := TemplateData{ | ||
| Languages: languages, | ||
| Services: services, | ||
| } | ||
|
|
||
| if err := tmpl.Execute(&buf, data); err != nil { | ||
| log.Fatalf("Failed to execute template: %v", err) | ||
| } | ||
|
|
||
| // Format the generated Go code | ||
| formatted, err := format.Source(buf.Bytes()) | ||
| if err != nil { | ||
| log.Fatalf("Failed to format Go code: %v", err) | ||
| } | ||
|
|
||
| // Write to version.go file | ||
| dir, err := os.Getwd() | ||
| if err != nil { | ||
| log.Fatalf("Failed to get working directory: %v", err) | ||
| } | ||
|
|
||
| outputPath := filepath.Join(dir, "version.go") | ||
| if err := os.WriteFile(outputPath, formatted, 0644); err != nil { | ||
| log.Fatalf("Failed to write version.go: %v", err) | ||
| } | ||
|
|
||
| fmt.Printf("Successfully generated %s\n", outputPath) | ||
| } | ||
|
|
||
| func formatVersionSlice(versions []string) string { | ||
| if len(versions) == 0 { | ||
| return "{}" | ||
| } | ||
|
|
||
| // Sort versions from latest to oldest | ||
| sortedVersions := make([]string, len(versions)) | ||
| copy(sortedVersions, versions) | ||
|
|
||
| sort.Slice(sortedVersions, func(i, j int) bool { | ||
| return compareVersions(sortedVersions[i], sortedVersions[j]) | ||
| }) | ||
|
|
||
| quoted := make([]string, len(sortedVersions)) | ||
| for i, v := range sortedVersions { | ||
| quoted[i] = fmt.Sprintf(`"%s"`, v) | ||
| } | ||
|
|
||
| return fmt.Sprintf("{%s}", strings.Join(quoted, ", ")) | ||
| } | ||
|
|
||
| // compareVersions returns true if version a is greater than version b | ||
| func compareVersions(a, b string) bool { | ||
| // Parse version parts | ||
| aParts := parseVersion(a) | ||
| bParts := parseVersion(b) | ||
|
|
||
| // Compare each part | ||
| maxLen := len(aParts) | ||
| if len(bParts) > maxLen { | ||
| maxLen = len(bParts) | ||
| } | ||
|
|
||
| for i := 0; i < maxLen; i++ { | ||
| aVal := 0 | ||
| bVal := 0 | ||
|
|
||
| if i < len(aParts) { | ||
| aVal = aParts[i] | ||
| } | ||
| if i < len(bParts) { | ||
| bVal = bParts[i] | ||
| } | ||
|
|
||
| if aVal > bVal { | ||
| return true | ||
| } | ||
| if aVal < bVal { | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| return false // versions are equal | ||
| } | ||
|
|
||
| // parseVersion parses a version string into numeric parts | ||
| func parseVersion(version string) []int { | ||
| parts := strings.Split(version, ".") | ||
| nums := make([]int, 0, len(parts)) | ||
|
|
||
| for _, part := range parts { | ||
| // Handle cases like "25.05" or "1.0" or just "1" | ||
| num := 0 | ||
| fmt.Sscanf(part, "%d", &num) | ||
| nums = append(nums, num) | ||
| } | ||
|
|
||
| return nums | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,6 @@ | |
| {{ else }} | ||
| # relationships | ||
| # db: | ||
| # type: postgresql:14 | ||
| # type: postgresql:17 | ||
| # disk: 1024 | ||
| {{ end -}} | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.