Makefile 3.6 KB

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