superfly / flyctl

Command line tools for fly.io services
https://fly.io
Apache License 2.0
1.43k stars 240 forks source link

`fly launch` creates failing health checks for Rails 7.1 apps #2475

Closed nreilly closed 1 year ago

nreilly commented 1 year ago

The bug Fly launch creates health checks for the new Rails 7.1 discoverable health checks as shown here. However, the checks generated will fail as the default Rails configuration forces https.

I've tested with both the homebrew flavour of flyctl, and a fresh build.

By adding X-Forwarded-Proto = "https" to the generated check in the fly.toml, we can get it to pass.

Generated fly.toml

app = "hc"
primary_region = "syd"
console_command = "/rails/bin/rails console"

[http_service]
  internal_port = 3000
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0
  processes = ["app"]

[checks]  
  [checks.status]
    port = 3000
    type = "http"
    interval = "10s"
    timeout = "2s"
    grace_period = "5s"
    method = "GET"
    path = "/up"
    protocol = "http"

[[statics]]
  guest_path = "/rails/public"
  url_prefix = "/"

Status Check:

  NAME   | STATUS   | MACHINE        | LAST UPDATED | OUTPUT                 
---------*----------*----------------*--------------*------------------------
  status | critical | 3d8d9902f0e268 | 48s ago      | 301 Moved Permanently  
---------*----------*----------------*--------------*------------------------

Adjusted fly.toml

app = "hc"
primary_region = "syd"
console_command = "/rails/bin/rails console"

[http_service]
  internal_port = 3000
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0
  processes = ["app"]

[checks]  
  [checks.status]
    port = 3000
    type = "http"
    interval = "10s"
    timeout = "2s"
    grace_period = "5s"
    method = "GET"
    path = "/up"
    protocol = "http"
    [checks.status.headers]
      X-Forwarded-Proto = "https"

[[statics]]
  guest_path = "/rails/public"
  url_prefix = "/"

Resulting Status Check:

  NAME   | STATUS  | MACHINE        | LAST UPDATED | OUTPUT                                                      
---------*---------*----------------*--------------*-------------------------------------------------------------
  status | passing | 3d8d9902f0e268 | 3s ago       | <html><body style="background-color: green"></body></html>  
---------*---------*----------------*--------------*-------------------------------------------------------------
nreilly commented 1 year ago

The linked pull request resolves the issue

  NAME   | STATUS  | MACHINE        | LAST UPDATED | OUTPUT                                                      
---------*---------*----------------*--------------*-------------------------------------------------------------
  status | passing | 3287314b032685 | just now     | <html><body style="background-color: green"></body></html>  
---------*---------*----------------*--------------*-------------------------------------------------------------

Using flyctl v0.0.0-1687908539+dev darwin/amd64 Commit: 313f950616cdab01d9ba4adf46d363a4d4137613 BuildDate: 2023-06-27T23:28:59Z BranchName: rails-health-https

Extract from fly.toml:

[checks]
  [checks.status]
    port = 3000
    type = "http"
    interval = "10s"
    timeout = "2s"
    grace_period = "5s"
    method = "GET"
    path = "/up"
    protocol = "http"
    [checks.status.headers]
      X-Forwarded-Proto = "https"