shared.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package buildpacks
  2. import (
  3. "github.com/google/go-github/github"
  4. )
  5. const (
  6. // NodeJS
  7. yarn = "yarn"
  8. npm = "npm"
  9. // Go
  10. mod = "mod"
  11. dep = "dep"
  12. // Python
  13. pipenv = "pipenv"
  14. pip = "pip"
  15. conda = "conda"
  16. // Ruby
  17. puma = "puma"
  18. thin = "thin"
  19. unicorn = "unicorn"
  20. passenger = "passenger"
  21. rackup = "rackup"
  22. rake = "rake"
  23. // Common
  24. standalone = "standalone"
  25. )
  26. type buildpackOrderGroupInfo struct {
  27. ID string `json:"id"`
  28. Optional bool `json:"optional"`
  29. Version string `json:"version"`
  30. }
  31. type BuildpackInfo struct {
  32. Packs []buildpackOrderGroupInfo `json:"packs"`
  33. // FIXME: env vars for https://github.com/paketo-buildpacks/environment-variables
  34. // and for https://github.com/paketo-buildpacks/image-labels
  35. EnvVars map[string]string `json:"env_vars"`
  36. }
  37. func newBuildpackInfo() *BuildpackInfo {
  38. return &BuildpackInfo{
  39. EnvVars: make(map[string]string),
  40. }
  41. }
  42. func (info *BuildpackInfo) addPack(pack buildpackOrderGroupInfo) {
  43. info.Packs = append(info.Packs, pack)
  44. }
  45. func (info *BuildpackInfo) addEnvVar(id string, val string) {
  46. info.EnvVars[id] = val
  47. }
  48. type RuntimeResponse struct {
  49. Name string `json:"name"`
  50. Buildpacks *BuildpackInfo `json:"buildpacks"`
  51. Runtime string `json:"runtime"`
  52. Config map[string]interface{} `json:"config"`
  53. }
  54. type Runtime interface {
  55. Detect(
  56. *github.Client, // github client to pull contents of files
  57. []*github.RepositoryContent, // the root folder structure of the git repo
  58. string, // owner
  59. string, // name
  60. string, // path
  61. github.RepositoryContentGetOptions, // SHA, branch or tag
  62. ) *RuntimeResponse
  63. }
  64. // Runtimes is a list of all API runtimes
  65. var Runtimes = []Runtime{
  66. NewGoRuntime(),
  67. NewNodeRuntime(),
  68. NewPythonRuntime(),
  69. NewRubyRuntime(),
  70. }