Skip to content

Commit 409547d

Browse files
Antonis Kalipetisclaude
authored andcommitted
refactor(registry): load runtime and service versions from JSON
Replace hardcoded string constants for Runtime and ServiceName types with struct types loaded from an embedded registry.json file at init time. This makes it possible to update supported versions without code changes. - Add registry.go and registry.json (embedded JSON data for all runtimes and services with their supported versions) - Rewrite Runtime from string const to struct with Name, Type, Versions, Docs fields - Rewrite ServiceName from string const to struct with Name, Type, Versions, Disk, Docs fields - Update RuntimeForStack to look up runtimes by type string - Update all callers to use runtime.Type string comparisons instead of const equality - Remove version.go and generate_versions.go (superseded by registry) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e504f9c commit 409547d

15 files changed

Lines changed: 1608 additions & 500 deletions

internal/question/build_steps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (q *BuildSteps) Ask(ctx context.Context) error {
4848
"pip install -r requirements.txt",
4949
)
5050
case models.Yarn, models.Npm:
51-
if answers.Type.Runtime != models.NodeJS {
51+
if answers.Type.Runtime.Type != "nodejs" {
5252
if _, ok := answers.Dependencies["nodejs"]; !ok {
5353
answers.Dependencies["nodejs"] = map[string]string{}
5454
}

internal/question/build_steps_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ import (
88
"github.com/platformsh/platformify/internal/question/models"
99
)
1010

11+
func runtimeByType(t *testing.T, typ string) *models.Runtime {
12+
t.Helper()
13+
r, err := models.Runtimes.RuntimeByType(typ)
14+
if err != nil {
15+
t.Fatalf("runtime %q not found in registry", typ)
16+
}
17+
return r
18+
}
19+
1120
func TestBuildSteps_Ask(t *testing.T) {
1221
type args struct {
1322
answers models.Answers
@@ -24,7 +33,7 @@ func TestBuildSteps_Ask(t *testing.T) {
2433
q: &BuildSteps{},
2534
args: args{models.Answers{
2635
Stack: models.NextJS,
27-
Type: models.RuntimeType{Runtime: models.NodeJS, Version: "20.0"},
36+
Type: models.RuntimeType{Runtime: runtimeByType(t, "nodejs"), Version: "20.0"},
2837
Dependencies: map[string]map[string]string{},
2938
DependencyManagers: []models.DepManager{models.Yarn},
3039
Environment: map[string]string{},
@@ -37,7 +46,7 @@ func TestBuildSteps_Ask(t *testing.T) {
3746
q: &BuildSteps{},
3847
args: args{models.Answers{
3948
Stack: models.NextJS,
40-
Type: models.RuntimeType{Runtime: models.NodeJS, Version: "20.0"},
49+
Type: models.RuntimeType{Runtime: runtimeByType(t, "nodejs"), Version: "20.0"},
4150
Dependencies: map[string]map[string]string{},
4251
DependencyManagers: []models.DepManager{models.Npm},
4352
Environment: map[string]string{},
@@ -50,7 +59,7 @@ func TestBuildSteps_Ask(t *testing.T) {
5059
q: &BuildSteps{},
5160
args: args{models.Answers{
5261
Stack: models.GenericStack,
53-
Type: models.RuntimeType{Runtime: models.Ruby, Version: "3.3"},
62+
Type: models.RuntimeType{Runtime: runtimeByType(t, "ruby"), Version: "3.3"},
5463
Dependencies: map[string]map[string]string{},
5564
DependencyManagers: []models.DepManager{models.Bundler},
5665
Environment: map[string]string{},
@@ -63,7 +72,7 @@ func TestBuildSteps_Ask(t *testing.T) {
6372
q: &BuildSteps{},
6473
args: args{models.Answers{
6574
Stack: models.Rails,
66-
Type: models.RuntimeType{Runtime: models.Ruby, Version: "3.3"},
75+
Type: models.RuntimeType{Runtime: runtimeByType(t, "ruby"), Version: "3.3"},
6776
Dependencies: map[string]map[string]string{},
6877
DependencyManagers: []models.DepManager{models.Bundler},
6978
Environment: map[string]string{},

internal/question/locations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (q *Locations) Ask(ctx context.Context) error {
2424
"allow": true,
2525
}
2626
default:
27-
if answers.Type.Runtime == models.PHP {
27+
if answers.Type.Runtime.Type == "php" {
2828
locations := map[string]interface{}{
2929
"passthru": "/index.php",
3030
"root": "",

internal/question/models/answer.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,21 @@ type Service struct {
4141
}
4242

4343
type RuntimeType struct {
44-
Runtime Runtime
44+
Runtime *Runtime
4545
Version string
4646
}
4747

48-
func (t RuntimeType) String() string {
48+
func (t *RuntimeType) String() string {
49+
if t.Runtime == nil {
50+
return ""
51+
}
4952
if t.Version != "" {
5053
return t.Runtime.String() + ":" + t.Version
5154
}
5255
return t.Runtime.String()
5356
}
5457

55-
func (t RuntimeType) MarshalJSON() ([]byte, error) {
58+
func (t *RuntimeType) MarshalJSON() ([]byte, error) {
5659
return json.Marshal(t.String())
5760
}
5861

internal/question/models/generate_versions.go

Lines changed: 0 additions & 288 deletions
This file was deleted.

0 commit comments

Comments
 (0)