main.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "os"
  6. "path/filepath"
  7. condaenvupdate "github.com/paketo-buildpacks/conda-env-update"
  8. gomodvendor "github.com/paketo-buildpacks/go-mod-vendor"
  9. "github.com/paketo-buildpacks/packit"
  10. pipenvinstall "github.com/paketo-buildpacks/pipenv-install"
  11. pythonstart "github.com/paketo-buildpacks/python-start"
  12. "github.com/paketo-buildpacks/rackup"
  13. railsassets "github.com/paketo-buildpacks/rails-assets"
  14. "github.com/paketo-buildpacks/rake"
  15. "github.com/porter-dev/porter/cmd/test-runtime/runtimes"
  16. )
  17. const GoModLocation = "go.mod"
  18. var workingDir string
  19. func detectGo() {
  20. /* First check if it is a go.mod project */
  21. goModParser := gomodvendor.NewGoModParser()
  22. detect := gomodvendor.Detect(goModParser)
  23. _, err := detect(packit.DetectContext{
  24. WorkingDir: workingDir,
  25. })
  26. if err == nil {
  27. log.Println("go.mod project detected")
  28. return
  29. }
  30. /* Next, check if it is a Gopkg.toml */
  31. _, err = os.Stat(filepath.Join(workingDir, "Gopkg.toml"))
  32. if err == nil {
  33. log.Println("Gopkg.toml project detected")
  34. return
  35. }
  36. /* Finally, check if it is a Go vendor */
  37. _, err = os.Stat(filepath.Join(workingDir, "vendor"))
  38. if err == nil {
  39. log.Println("Go vendor project detected")
  40. return
  41. }
  42. // FIXME: what about Go projects that do not use any of the
  43. // above but contain a Makefile to call 'go build'
  44. /* Not a Go project */
  45. log.Println("Not a Go project")
  46. }
  47. func detectPython() {
  48. /* Check for Pipfile project */
  49. pipfileParser := pipenvinstall.NewPipfileParser()
  50. pipfileLockParser := pipenvinstall.NewPipfileLockParser()
  51. detect := pipenvinstall.Detect(pipfileParser, pipfileLockParser)
  52. _, err := detect(packit.DetectContext{
  53. WorkingDir: workingDir,
  54. })
  55. if err == nil {
  56. log.Println("Python Pipfile project detected")
  57. return
  58. }
  59. /* Check for pip project */
  60. _, err = os.Stat(filepath.Join(workingDir, "requirements.txt"))
  61. if err == nil {
  62. log.Println("Python pip project detected")
  63. return
  64. }
  65. /* Check for conda project */
  66. detect = condaenvupdate.Detect()
  67. _, err = detect(packit.DetectContext{
  68. WorkingDir: workingDir,
  69. })
  70. if err == nil {
  71. log.Println("Python conda project detected")
  72. return
  73. }
  74. /* Check for all other possibilities of a Python project */
  75. detect = pythonstart.Detect()
  76. _, err = detect(packit.DetectContext{
  77. WorkingDir: workingDir,
  78. })
  79. if err == nil {
  80. log.Println("Python project detected")
  81. return
  82. }
  83. /* Not a Python project */
  84. log.Println("Not a Python project")
  85. }
  86. func detectRuby() {
  87. /* Check for rackup project */
  88. gemParser := rackup.NewGemfileLockParser()
  89. detect := rackup.Detect(gemParser)
  90. _, err := detect(packit.DetectContext{
  91. WorkingDir: workingDir,
  92. })
  93. if err == nil {
  94. log.Println("Ruby rackup project detected")
  95. return
  96. }
  97. /* Check for Rails app with assets */
  98. railsGemfileParser := railsassets.NewGemfileParser()
  99. detect = railsassets.Detect(railsGemfileParser)
  100. _, err = detect(packit.DetectContext{
  101. WorkingDir: workingDir,
  102. })
  103. if err == nil {
  104. log.Println("Ruby rails project detected")
  105. return
  106. }
  107. /* Check for rakefile project */
  108. rakeGemfileParser := rake.NewGemfileParser()
  109. detect = rake.Detect(rakeGemfileParser)
  110. _, err = detect(packit.DetectContext{
  111. WorkingDir: workingDir,
  112. })
  113. if err == nil {
  114. log.Println("Ruby rakefile project detected")
  115. return
  116. }
  117. /* Not a Ruby project */
  118. log.Println("Not a Ruby project")
  119. }
  120. func main() {
  121. if len(os.Args) < 2 {
  122. log.Fatalln("Usage: ./test-runtime <project directory>")
  123. }
  124. workingDir = os.Args[1]
  125. nodeRuntime := runtimes.NewNodeRuntime()
  126. buildpackInfo, data := nodeRuntime.Detect(workingDir)
  127. if data != nil {
  128. fmt.Println(data)
  129. for i := 0; i < len(buildpackInfo.Packs); i++ {
  130. fmt.Println(buildpackInfo.Packs[i])
  131. }
  132. }
  133. }