Makefile 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. -include local/Makefile
  2. .PHONY: all deps-go deps-js deps build-go build-server build-cli build-js build build-docker-dev build-docker-full lint-go test-go test-js test run clean gosec revive devenv devenv-down revive-alerting
  3. GO := GO111MODULE=on go
  4. GO_FILES := ./pkg/...
  5. all: deps build
  6. deps-go:
  7. go run build.go setup
  8. deps-js: node_modules
  9. deps: deps-js
  10. build-go:
  11. @echo "build go files"
  12. GO111MODULE=on go run build.go build
  13. build-server:
  14. @echo "build server"
  15. GO111MODULE=on go run build.go build-server
  16. build-cli:
  17. @echo "build in CI environment"
  18. GO111MODULE=on go run build.go build-cli
  19. build-js:
  20. @echo "build frontend"
  21. yarn run build
  22. build: build-go build-js
  23. build-docker-dev:
  24. @echo "build development container"
  25. @echo "\033[92mInfo:\033[0m the frontend code is expected to be built already."
  26. GO111MODULE=on go run build.go -goos linux -pkg-arch amd64 ${OPT} build pkg-archive latest
  27. cp dist/grafana-latest.linux-x64.tar.gz packaging/docker
  28. cd packaging/docker && docker build --tag grafana/grafana:dev .
  29. build-docker-full:
  30. @echo "build docker container"
  31. docker build --tag grafana/grafana:dev .
  32. lint-go:
  33. @echo "lint go source"
  34. scripts/backend-lint.sh
  35. test-go:
  36. @echo "test backend"
  37. GO111MODULE=on go test -v ./pkg/...
  38. test-js:
  39. @echo "test frontend"
  40. yarn test
  41. test: test-go test-js
  42. clean:
  43. @echo "cleaning"
  44. rm -rf node_modules
  45. rm -rf public/build
  46. node_modules: package.json yarn.lock
  47. @echo "install frontend dependencies"
  48. yarn install --pure-lockfile --no-progress
  49. scripts/go/bin/revive: scripts/go/go.mod
  50. @cd scripts/go; \
  51. $(GO) build -o ./bin/revive github.com/mgechev/revive
  52. scripts/go/bin/gosec: scripts/go/go.mod
  53. @cd scripts/go; \
  54. $(GO) build -o ./bin/gosec github.com/securego/gosec/cmd/gosec
  55. scripts/go/bin/bra: scripts/go/go.mod
  56. @cd scripts/go; \
  57. $(GO) build -o ./bin/bra github.com/Unknwon/bra
  58. revive: scripts/go/bin/revive
  59. @scripts/go/bin/revive \
  60. -formatter stylish \
  61. -config ./scripts/go/configs/revive.toml \
  62. $(GO_FILES)
  63. revive-alerting: scripts/go/bin/revive
  64. @scripts/go/bin/revive \
  65. -formatter stylish \
  66. ./pkg/services/alerting/...
  67. run: scripts/go/bin/bra
  68. @scripts/go/bin/bra run
  69. # TODO recheck the rules and leave only necessary exclusions
  70. gosec: scripts/go/bin/gosec
  71. @scripts/go/bin/gosec -quiet \
  72. -exclude=G104,G107,G201,G202,G204,G301,G304,G401,G402,G501 \
  73. -conf=./scripts/go/configs/gosec.json \
  74. $(GO_FILES)
  75. # create docker-compose file with provided sources and start them
  76. # example: make devenv sources=postgres,openldap
  77. ifeq ($(sources),)
  78. devenv:
  79. @printf 'You have to define sources for this command \nexample: make devenv sources=postgres,openldap\n'
  80. else
  81. devenv: devenv-down
  82. $(eval targets := $(shell echo '$(sources)' | tr "," " "))
  83. @cd devenv; \
  84. ./create_docker_compose.sh $(targets) || \
  85. (rm -rf docker-compose.yaml; exit 1)
  86. @cd devenv; \
  87. docker-compose up -d --build
  88. endif
  89. # drop down the envs
  90. devenv-down:
  91. @cd devenv; \
  92. test -f docker-compose.yaml && \
  93. docker-compose down || exit 0;