Skip to content

Commit 2ddf43f

Browse files
authored
Merge pull request #212 from spk/rails-stack
Rails stack
2 parents 1aa87e2 + 206e47c commit 2ddf43f

File tree

15 files changed

+119
-7
lines changed

15 files changed

+119
-7
lines changed

internal/question/build_steps.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ func (q *BuildSteps) Ask(ctx context.Context) error {
8989
answers.BuildSteps,
9090
"composer --no-ansi --no-interaction install --no-progress --prefer-dist --optimize-autoloader --no-dev",
9191
)
92+
case models.Bundler:
93+
answers.BuildSteps = append(
94+
answers.BuildSteps,
95+
"bundle install",
96+
)
9297
}
9398
}
9499

@@ -125,6 +130,13 @@ func (q *BuildSteps) Ask(ctx context.Context) error {
125130
}
126131
answers.BuildSteps = append(answers.BuildSteps, cmd)
127132
}
133+
case models.Rails:
134+
answers.Environment["RAILS_ENV"] = "production"
135+
answers.Environment["PIDFILE"] = "tmp/server.pid"
136+
answers.BuildSteps = append(
137+
answers.BuildSteps,
138+
"bundle exec rails assets:precompile",
139+
)
128140
}
129141

130142
return nil

internal/question/build_steps_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,32 @@ func TestBuildSteps_Ask(t *testing.T) {
4545
buildSteps: []string{"npm i", "npm exec next build"},
4646
wantErr: false,
4747
},
48+
{
49+
name: "Bundler",
50+
q: &BuildSteps{},
51+
args: args{models.Answers{
52+
Stack: models.GenericStack,
53+
Type: models.RuntimeType{Runtime: models.Ruby, Version: "3.3"},
54+
Dependencies: map[string]map[string]string{},
55+
DependencyManagers: []models.DepManager{models.Bundler},
56+
Environment: map[string]string{},
57+
}},
58+
buildSteps: []string{"bundle install"},
59+
wantErr: false,
60+
},
61+
{
62+
name: "Bundler with Rails",
63+
q: &BuildSteps{},
64+
args: args{models.Answers{
65+
Stack: models.Rails,
66+
Type: models.RuntimeType{Runtime: models.Ruby, Version: "3.3"},
67+
Dependencies: map[string]map[string]string{},
68+
DependencyManagers: []models.DepManager{models.Bundler},
69+
Environment: map[string]string{},
70+
}},
71+
buildSteps: []string{"bundle install", "bundle exec rails assets:precompile"},
72+
wantErr: false,
73+
},
4874
}
4975
for _, tt := range tests {
5076
t.Run(tt.name, func(t *testing.T) {

internal/question/dependency_manager.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const (
1616
pipenvLockFile = "Pipfile.lock"
1717
pipLockFile = "requirements.txt"
1818
composerLockFile = "composer.lock"
19+
bundlerLockFile = "Gemfile.lock"
1920
)
2021

2122
type DependencyManager struct{}
@@ -77,5 +78,9 @@ func (q *DependencyManager) Ask(ctx context.Context) error {
7778
answers.DependencyManagers = append(answers.DependencyManagers, models.Npm)
7879
}
7980

81+
if exists := utils.FileExists(answers.WorkingDirectory, bundlerLockFile); exists {
82+
answers.DependencyManagers = append(answers.DependencyManagers, models.Bundler)
83+
}
84+
8085
return nil
8186
}

internal/question/deploy_command.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ func (q *DeployCommand) Ask(ctx context.Context) error {
4242
"php artisan migrate --force",
4343
"php artisan optimize:clear",
4444
)
45+
case models.Rails:
46+
answers.DeployCommand = append(answers.DeployCommand,
47+
"bundle exec rake db:migrate",
48+
)
4549
}
4650

4751
return nil

internal/question/models/answer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ func getStack(answersStack Stack) platformifier.Stack {
141141
return platformifier.Django
142142
case Laravel:
143143
return platformifier.Laravel
144+
case Rails:
145+
return platformifier.Rails
144146
case NextJS:
145147
return platformifier.NextJS
146148
case Strapi:

internal/question/models/dependency_manager.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const (
88
Composer DepManager = "composer"
99
Yarn DepManager = "yarn"
1010
Npm DepManager = "npm"
11+
Bundler DepManager = "bundler"
1112
)
1213

1314
type DepManager string
@@ -32,6 +33,8 @@ func (m DepManager) Title() string {
3233
return "Yarn"
3334
case Npm:
3435
return "Npm"
36+
case Bundler:
37+
return "Bundler"
3538
default:
3639
return ""
3740
}

internal/question/models/stack.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const (
1414
Strapi
1515
Flask
1616
Express
17+
Rails
1718
)
1819

1920
var (
@@ -25,6 +26,7 @@ var (
2526
Strapi,
2627
Flask,
2728
Express,
29+
Rails,
2830
}
2931
)
3032

@@ -36,6 +38,8 @@ func (s Stack) Title() string {
3638
return "Other"
3739
case Django:
3840
return "Django"
41+
case Rails:
42+
return "Rails"
3943
case Laravel:
4044
return "Laravel"
4145
case NextJS:
@@ -88,6 +92,8 @@ func RuntimeForStack(stack Stack) Runtime {
8892
switch stack {
8993
case Django, Flask:
9094
return Python
95+
case Rails:
96+
return Ruby
9197
case Laravel:
9298
return PHP
9399
case NextJS, Strapi, Express:

internal/question/mounts.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ func (q *Mounts) Ask(ctx context.Context) error {
1515
}
1616

1717
switch answers.Stack {
18+
case models.Rails:
19+
answers.Disk = "2048" // in MB
20+
answers.Mounts = map[string]map[string]string{
21+
"storage": {
22+
"source": "local",
23+
"source_path": "storage",
24+
},
25+
"tmp": {
26+
"source": "tmp",
27+
"source_path": "tmp",
28+
},
29+
"log": {
30+
"source": "tmp",
31+
"source_path": "tmp",
32+
},
33+
}
1834
case models.Laravel:
1935
answers.Disk = "2048" // in MB
2036
answers.Mounts = map[string]map[string]string{

internal/question/stack.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
composerJSONFile = "composer.json"
2323
packageJSONFile = "package.json"
2424
symfonyLockFile = "symfony.lock"
25+
rackFile = "config.ru"
2526
)
2627

2728
type Stack struct{}
@@ -59,6 +60,18 @@ func (q *Stack) Ask(ctx context.Context) error {
5960
return nil
6061
}
6162

63+
rackPath := utils.FindFile(answers.WorkingDirectory, rackFile)
64+
if rackPath != "" {
65+
f, err := os.Open(rackPath)
66+
if err == nil {
67+
defer f.Close()
68+
if ok, _ := utils.ContainsStringInFile(f, "Rails.application.load_server", true); ok {
69+
answers.Stack = models.Rails
70+
return nil
71+
}
72+
}
73+
}
74+
6275
requirementsPath := utils.FindFile(answers.WorkingDirectory, "requirements.txt")
6376
if requirementsPath != "" {
6477
f, err := os.Open(requirementsPath)

internal/question/web_command.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ func (q *WebCommand) Ask(ctx context.Context) error {
8181

8282
answers.WebCommand = fmt.Sprintf("%sgunicorn %s -b unix:$SOCKET %s --log-file -", prefix, pythonPath, wsgi)
8383
return nil
84+
case models.Rails:
85+
if answers.SocketFamily == models.TCP {
86+
answers.WebCommand = "bundle exec rails server"
87+
return nil
88+
}
89+
90+
answers.WebCommand = "bundle exec puma -b unix://$SOCKET"
91+
return nil
8492
case models.NextJS:
8593
answers.WebCommand = "npx next start -p $PORT"
8694
return nil

0 commit comments

Comments
 (0)