Skip to content
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

Automatically configure http_checks when rails_health_check_path detected #1678

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,37 @@ func (c *Config) SetInternalPort(port int) bool {
return false
}

func (c *Config) SetHttpCheck(path string) bool {
services, ok := c.Definition["services"].([]interface{})
if !ok {
return false
}

if len(services) == 0 {
return false
}

if service, ok := services[0].(map[string]interface{}); ok {
check := map[string]interface{}{
"interval": 10000,
"grace_period": "5s",
"method": "get",
"protocol": "http",
"restart_limit": 0,
"timeout": 2000,
"tls_skip_verify": false,
}

check["path"] = path

service["http_checks"] = []map[string]interface{}{check}

return true
}

return false
}

func (c *Config) SetConcurrency(soft int, hard int) bool {
services, ok := c.Definition["services"].([]interface{})
if !ok {
Expand Down
4 changes: 4 additions & 0 deletions internal/command/launch/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@ func run(ctx context.Context) (err error) {
appConfig.SetInternalPort(srcInfo.Port)
}

if srcInfo.HttpCheckPath != "" {
appConfig.SetHttpCheck(srcInfo.HttpCheckPath)
}

if srcInfo.Concurrency != nil {
appConfig.SetConcurrency(srcInfo.Concurrency["soft_limit"], srcInfo.Concurrency["hard_limit"])
}
Expand Down
16 changes: 16 additions & 0 deletions scanner/rails.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/pkg/errors"
)

var healthcheck_channel = make(chan string)

func configureRails(sourceDir string, config *ScannerConfig) (*SourceInfo, error) {
if !checksPass(sourceDir, dirContains("Gemfile", "rails")) {
return nil, nil
Expand Down Expand Up @@ -64,6 +66,18 @@ https://fly.io/docs/rails/getting-started/dockerfiles/.
Once ready: run 'fly deploy' to deploy your Rails app.
`

// fetch healthcheck route in a separate thread
go func() {
out, err := exec.Command("ruby", "./bin/rails", "runner",
"puts Rails.application.routes.url_helpers.rails_health_check_path").Output()

if err == nil {
healthcheck_channel <- strings.TrimSpace(string(out))
} else {
healthcheck_channel <- ""
}
}()

return s, nil
}

Expand Down Expand Up @@ -156,5 +170,7 @@ func RailsCallback(srcInfo *SourceInfo, options map[string]bool) error {
},
}

srcInfo.HttpCheckPath = <-healthcheck_channel

return nil
}
1 change: 1 addition & 0 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type SourceInfo struct {
PostgresInitCommandCondition bool
Concurrency map[string]int
Callback func(srcInfo *SourceInfo, options map[string]bool) error
HttpCheckPath string
}

type SourceFile struct {
Expand Down