Advertisement
Guest User

Untitled

a guest
Aug 15th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. Makefile for Revel apps for Elastic Beanstalk:
  2.  
  3. HASH := $(shell git rev-parse --short HEAD)
  4. BUILD_RAW := $(shell git rev-list --count HEAD) # Removed '--first-parent' because it means build numbers can go down after a merge.
  5. BUILD := $(strip $(BUILD_RAW))
  6.  
  7. help:
  8. cat Makefile
  9.  
  10. run:
  11. revel run
  12.  
  13. open:
  14. open http://localhost:9000
  15. revel run
  16.  
  17. zip:
  18. # Clean
  19. rm -rf build || true
  20. rm EBApp_*.zip || true
  21. # Build the app/tmp and app/routes autogen stuff.
  22. revel clean
  23. revel build
  24. rm -rf src || true
  25. rm run.bat || true
  26. rm run.sh || true
  27. rm myAppBinary || true
  28. # Override the main to pull params from envars not cmdline, for easier EB deployment.
  29. cp main/main.go app/tmp
  30. # Build it
  31. cd app/tmp && GOARCH=amd64 GOOS=linux go build -o ../../build/application
  32. # Copy in assets
  33. mkdir -p build/src/github.com/myCompany/myApp/app
  34. mkdir -p build/src/github.com/revel/revel
  35. cp -R ~/go/src/github.com/revel/revel/conf build/src/github.com/revel/revel
  36. cp -R ~/go/src/github.com/revel/revel/templates build/src/github.com/revel/revel
  37. cp -R .ebextensions build
  38. cp -R app/views build/src/github.com/myCompany/myProject/app
  39. cp -R conf build/src/github.com/myCompany/myProject
  40. cp -R public build/src/github.com/myCompany/myProject
  41. # Zip up
  42. cd build && zip -r "../EBApp_$(BUILD)_$(HASH).zip" * .ebextensions -x "**/.DS_Store"
  43. open .
  44. <<EOF>>
  45.  
  46. And in main/main.go:
  47. package main
  48.  
  49. import (
  50. "os"
  51. "strconv"
  52.  
  53. "github.com/aacapella/portal/app/tmp/run"
  54. "github.com/revel/revel"
  55. )
  56.  
  57. func getEnvWithDefault(key string, def string) string {
  58. e := os.Getenv(key)
  59. if e == "" {
  60. return def
  61. }
  62. return e
  63. }
  64.  
  65. func main() {
  66. runMode := getEnvWithDefault("RUNMODE", "prod")
  67. port, _ := strconv.Atoi(getEnvWithDefault("PORT", "5000"))
  68. importPath := getEnvWithDefault("IMPORTPATH", "github.com/aacapella/portal")
  69. srcPath := getEnvWithDefault("SRCPATH", "src")
  70.  
  71. revel.Init(runMode, importPath, srcPath)
  72. run.Run(port)
  73. }
  74. <<EOF>>
  75.  
  76. And in .ebextensions/go-settings.config:
  77. option_settings:
  78. aws:elasticbeanstalk:container:golang:staticfiles:
  79. /public: src/github.com/aacapella/portal/public
  80.  
  81. Seems to work!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement