Skip to content

Commit

Permalink
Run Rails thruster on port 8080. (#3969)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys authored Sep 30, 2024
1 parent 925283c commit a8debdf
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions scanner/rails.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path"
"path/filepath"
"regexp"
"strconv"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -199,6 +200,23 @@ func configureRails(sourceDir string, config *ScannerConfig) (*SourceInfo, error
}
}

// extract port from Dockerfile (if present). This is primarily for thruster.
dockerfile, err := os.ReadFile("Dockerfile")
if err == nil {
re := regexp.MustCompile(`(?m)^EXPOSE\s+(?P<port>\d+)`)
m := re.FindStringSubmatch(string(dockerfile))
if len(m) > 0 {
port, err := strconv.Atoi(m[1])
if err == nil {
if port < 1024 {
port += 8000
}

s.Port = port
}
}
}

// master.key comes with Rails apps from v5.2 onwards, but may not be present
// if the app does not use Rails encrypted credentials. Rails v6 added
// support for multi-environment credentials. Use the Rails searching
Expand Down

0 comments on commit a8debdf

Please sign in to comment.