mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Makefile: refactoring .PHONY (#85440)
This commit is contained in:
46
Makefile
46
Makefile
@@ -7,7 +7,6 @@ WIRE_TAGS = "oss"
|
|||||||
-include local/Makefile
|
-include local/Makefile
|
||||||
include .bingo/Variables.mk
|
include .bingo/Variables.mk
|
||||||
|
|
||||||
.PHONY: all deps-go deps-js deps build-go build-backend build-server build-cli build-js build build-docker-full build-docker-full-ubuntu lint-go golangci-lint test-go test-js gen-ts test run run-frontend clean devenv devenv-down protobuf drone help gen-go gen-cue fix-cue gen-feature-toggles
|
|
||||||
|
|
||||||
GO = go
|
GO = go
|
||||||
GO_FILES ?= ./pkg/... ./pkg/apiserver/... ./pkg/apimachinery/... ./pkg/promlib/...
|
GO_FILES ?= ./pkg/... ./pkg/apiserver/... ./pkg/apimachinery/... ./pkg/promlib/...
|
||||||
@@ -19,17 +18,22 @@ targets := $(shell echo '$(sources)' | tr "," " ")
|
|||||||
|
|
||||||
GO_INTEGRATION_TESTS := $(shell find ./pkg -type f -name '*_test.go' -exec grep -l '^func TestIntegration' '{}' '+' | grep -o '\(.*\)/' | sort -u)
|
GO_INTEGRATION_TESTS := $(shell find ./pkg -type f -name '*_test.go' -exec grep -l '^func TestIntegration' '{}' '+' | grep -o '\(.*\)/' | sort -u)
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
all: deps build
|
all: deps build
|
||||||
|
|
||||||
##@ Dependencies
|
##@ Dependencies
|
||||||
|
|
||||||
|
.PHONY: deps-go
|
||||||
deps-go: ## Install backend dependencies.
|
deps-go: ## Install backend dependencies.
|
||||||
$(GO) run build.go setup
|
$(GO) run build.go setup
|
||||||
|
|
||||||
|
.PHONY: deps-js
|
||||||
deps-js: node_modules ## Install frontend dependencies.
|
deps-js: node_modules ## Install frontend dependencies.
|
||||||
|
|
||||||
|
.PHONY: deps
|
||||||
deps: deps-js ## Install all dependencies.
|
deps: deps-js ## Install all dependencies.
|
||||||
|
|
||||||
|
.PHONY: node_modules
|
||||||
node_modules: package.json yarn.lock ## Install node modules.
|
node_modules: package.json yarn.lock ## Install node modules.
|
||||||
@echo "install frontend dependencies"
|
@echo "install frontend dependencies"
|
||||||
YARN_ENABLE_PROGRESS_BARS=false yarn install --immutable
|
YARN_ENABLE_PROGRESS_BARS=false yarn install --immutable
|
||||||
@@ -47,6 +51,7 @@ $(MERGED_SPEC_TARGET): swagger-oss-gen swagger-enterprise-gen $(NGALERT_SPEC_TAR
|
|||||||
# known conflicts DsPermissionType, AddApiKeyCommand, Json, Duration (identical models referenced by both specs)
|
# known conflicts DsPermissionType, AddApiKeyCommand, Json, Duration (identical models referenced by both specs)
|
||||||
$(SWAGGER) mixin -q $(SPEC_TARGET) $(ENTERPRISE_SPEC_TARGET) $(NGALERT_SPEC_TARGET) --ignore-conflicts -o $(MERGED_SPEC_TARGET)
|
$(SWAGGER) mixin -q $(SPEC_TARGET) $(ENTERPRISE_SPEC_TARGET) $(NGALERT_SPEC_TARGET) --ignore-conflicts -o $(MERGED_SPEC_TARGET)
|
||||||
|
|
||||||
|
.PHONY: swagger-oss-gen
|
||||||
swagger-oss-gen: $(SWAGGER) ## Generate API Swagger specification
|
swagger-oss-gen: $(SWAGGER) ## Generate API Swagger specification
|
||||||
@echo "re-generating swagger for OSS"
|
@echo "re-generating swagger for OSS"
|
||||||
rm -f $(SPEC_TARGET)
|
rm -f $(SPEC_TARGET)
|
||||||
@@ -58,6 +63,7 @@ swagger-oss-gen: $(SWAGGER) ## Generate API Swagger specification
|
|||||||
--exclude-tag=enterprise
|
--exclude-tag=enterprise
|
||||||
|
|
||||||
# this file only exists if enterprise is enabled
|
# this file only exists if enterprise is enabled
|
||||||
|
.PHONY: swagger-enterprise-gen
|
||||||
ENTERPRISE_EXT_FILE = pkg/extensions/ext.go
|
ENTERPRISE_EXT_FILE = pkg/extensions/ext.go
|
||||||
ifeq ("$(wildcard $(ENTERPRISE_EXT_FILE))","") ## if enterprise is not enabled
|
ifeq ("$(wildcard $(ENTERPRISE_EXT_FILE))","") ## if enterprise is not enabled
|
||||||
swagger-enterprise-gen:
|
swagger-enterprise-gen:
|
||||||
@@ -74,11 +80,14 @@ swagger-enterprise-gen: $(SWAGGER) ## Generate API Swagger specification
|
|||||||
--include-tag=enterprise
|
--include-tag=enterprise
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
.PHONY: swagger-gen
|
||||||
swagger-gen: gen-go $(MERGED_SPEC_TARGET) swagger-validate
|
swagger-gen: gen-go $(MERGED_SPEC_TARGET) swagger-validate
|
||||||
|
|
||||||
|
.PHONY: swagger-validate
|
||||||
swagger-validate: $(MERGED_SPEC_TARGET) $(SWAGGER) ## Validate API spec
|
swagger-validate: $(MERGED_SPEC_TARGET) $(SWAGGER) ## Validate API spec
|
||||||
$(SWAGGER) validate --skip-warnings $(<)
|
$(SWAGGER) validate --skip-warnings $(<)
|
||||||
|
|
||||||
|
.PHONY: swagger-clean
|
||||||
swagger-clean:
|
swagger-clean:
|
||||||
rm -f $(SPEC_TARGET) $(MERGED_SPEC_TARGET) $(OAPI_SPEC_TARGET)
|
rm -f $(SPEC_TARGET) $(MERGED_SPEC_TARGET) $(OAPI_SPEC_TARGET)
|
||||||
|
|
||||||
@@ -97,15 +106,18 @@ lefthook-uninstall: $(LEFTHOOK)
|
|||||||
##@ OpenAPI 3
|
##@ OpenAPI 3
|
||||||
OAPI_SPEC_TARGET = public/openapi3.json
|
OAPI_SPEC_TARGET = public/openapi3.json
|
||||||
|
|
||||||
|
.PHONY: openapi3-gen
|
||||||
openapi3-gen: swagger-gen ## Generates OpenApi 3 specs from the Swagger 2 already generated
|
openapi3-gen: swagger-gen ## Generates OpenApi 3 specs from the Swagger 2 already generated
|
||||||
$(GO) run scripts/openapi3/openapi3conv.go $(MERGED_SPEC_TARGET) $(OAPI_SPEC_TARGET)
|
$(GO) run scripts/openapi3/openapi3conv.go $(MERGED_SPEC_TARGET) $(OAPI_SPEC_TARGET)
|
||||||
|
|
||||||
##@ Building
|
##@ Building
|
||||||
|
.PHONY: gen-cue
|
||||||
gen-cue: ## Do all CUE/Thema code generation
|
gen-cue: ## Do all CUE/Thema code generation
|
||||||
@echo "generate code from .cue files"
|
@echo "generate code from .cue files"
|
||||||
go generate ./kinds/gen.go
|
go generate ./kinds/gen.go
|
||||||
go generate ./public/app/plugins/gen.go
|
go generate ./public/app/plugins/gen.go
|
||||||
|
|
||||||
|
.PHONY: gen-feature-toggles
|
||||||
gen-feature-toggles:
|
gen-feature-toggles:
|
||||||
## First go test run fails because it will re-generate the feature toggles.
|
## First go test run fails because it will re-generate the feature toggles.
|
||||||
## Second go test run will compare the generated files and pass.
|
## Second go test run will compare the generated files and pass.
|
||||||
@@ -117,34 +129,42 @@ gen-feature-toggles:
|
|||||||
go test -v ./pkg/services/featuremgmt/...; \
|
go test -v ./pkg/services/featuremgmt/...; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
.PHONY: gen-go
|
||||||
gen-go:
|
gen-go:
|
||||||
@echo "generate go files"
|
@echo "generate go files"
|
||||||
$(GO) run ./pkg/build/wire/cmd/wire/main.go gen -tags $(WIRE_TAGS) ./pkg/server
|
$(GO) run ./pkg/build/wire/cmd/wire/main.go gen -tags $(WIRE_TAGS) ./pkg/server
|
||||||
|
|
||||||
|
.PHONY: fix-cue
|
||||||
fix-cue: $(CUE)
|
fix-cue: $(CUE)
|
||||||
@echo "formatting cue files"
|
@echo "formatting cue files"
|
||||||
$(CUE) fix kinds/**/*.cue
|
$(CUE) fix kinds/**/*.cue
|
||||||
$(CUE) fix public/app/plugins/**/**/*.cue
|
$(CUE) fix public/app/plugins/**/**/*.cue
|
||||||
|
|
||||||
|
.PHONY: gen-jsonnet
|
||||||
gen-jsonnet:
|
gen-jsonnet:
|
||||||
go generate ./devenv/jsonnet
|
go generate ./devenv/jsonnet
|
||||||
|
|
||||||
|
.PHONY: build-go
|
||||||
build-go: gen-go ## Build all Go binaries.
|
build-go: gen-go ## Build all Go binaries.
|
||||||
@echo "build go files"
|
@echo "build go files"
|
||||||
$(GO) run build.go $(GO_BUILD_FLAGS) build
|
$(GO) run build.go $(GO_BUILD_FLAGS) build
|
||||||
|
|
||||||
|
.PHONY: build-backend
|
||||||
build-backend: ## Build Grafana backend.
|
build-backend: ## Build Grafana backend.
|
||||||
@echo "build backend"
|
@echo "build backend"
|
||||||
$(GO) run build.go $(GO_BUILD_FLAGS) build-backend
|
$(GO) run build.go $(GO_BUILD_FLAGS) build-backend
|
||||||
|
|
||||||
|
.PHONY: build-server
|
||||||
build-server: ## Build Grafana server.
|
build-server: ## Build Grafana server.
|
||||||
@echo "build server"
|
@echo "build server"
|
||||||
$(GO) run build.go $(GO_BUILD_FLAGS) build-server
|
$(GO) run build.go $(GO_BUILD_FLAGS) build-server
|
||||||
|
|
||||||
|
.PHONY: build-cli
|
||||||
build-cli: ## Build Grafana CLI application.
|
build-cli: ## Build Grafana CLI application.
|
||||||
@echo "build grafana-cli"
|
@echo "build grafana-cli"
|
||||||
$(GO) run build.go $(GO_BUILD_FLAGS) build-cli
|
$(GO) run build.go $(GO_BUILD_FLAGS) build-cli
|
||||||
|
|
||||||
|
.PHONY: build-js
|
||||||
build-js: ## Build frontend assets.
|
build-js: ## Build frontend assets.
|
||||||
@echo "build frontend"
|
@echo "build frontend"
|
||||||
yarn run build
|
yarn run build
|
||||||
@@ -152,6 +172,7 @@ build-js: ## Build frontend assets.
|
|||||||
|
|
||||||
PLUGIN_ID ?=
|
PLUGIN_ID ?=
|
||||||
|
|
||||||
|
.PHONY: build-plugin-go
|
||||||
build-plugin-go: ## Build decoupled plugins
|
build-plugin-go: ## Build decoupled plugins
|
||||||
@echo "build plugin $(PLUGIN_ID)"
|
@echo "build plugin $(PLUGIN_ID)"
|
||||||
@cd pkg/tsdb; \
|
@cd pkg/tsdb; \
|
||||||
@@ -161,11 +182,14 @@ build-plugin-go: ## Build decoupled plugins
|
|||||||
fi; \
|
fi; \
|
||||||
mage -v buildplugin $(PLUGIN_ID)
|
mage -v buildplugin $(PLUGIN_ID)
|
||||||
|
|
||||||
|
.PHONY: build
|
||||||
build: build-go build-js ## Build backend and frontend.
|
build: build-go build-js ## Build backend and frontend.
|
||||||
|
|
||||||
|
.PHONY: run
|
||||||
run: $(BRA) ## Build and run web server on filesystem changes.
|
run: $(BRA) ## Build and run web server on filesystem changes.
|
||||||
$(BRA) run
|
$(BRA) run
|
||||||
|
|
||||||
|
.PHONY: run-frontend
|
||||||
run-frontend: deps-js ## Fetch js dependencies and watch frontend for rebuild
|
run-frontend: deps-js ## Fetch js dependencies and watch frontend for rebuild
|
||||||
yarn start
|
yarn start
|
||||||
|
|
||||||
@@ -217,22 +241,27 @@ test-go-integration-memcached: ## Run integration tests for memcached cache.
|
|||||||
$(GO) clean -testcache
|
$(GO) clean -testcache
|
||||||
MEMCACHED_HOSTS=localhost:11211 $(GO) test -run IntegrationMemcached -covermode=atomic -timeout=2m $(GO_INTEGRATION_TESTS)
|
MEMCACHED_HOSTS=localhost:11211 $(GO) test -run IntegrationMemcached -covermode=atomic -timeout=2m $(GO_INTEGRATION_TESTS)
|
||||||
|
|
||||||
|
.PHONY: test-js
|
||||||
test-js: ## Run tests for frontend.
|
test-js: ## Run tests for frontend.
|
||||||
@echo "test frontend"
|
@echo "test frontend"
|
||||||
yarn test
|
yarn test
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
test: test-go test-js ## Run all tests.
|
test: test-go test-js ## Run all tests.
|
||||||
|
|
||||||
##@ Linting
|
##@ Linting
|
||||||
|
.PHONY: golangci-lint
|
||||||
golangci-lint: $(GOLANGCI_LINT)
|
golangci-lint: $(GOLANGCI_LINT)
|
||||||
@echo "lint via golangci-lint"
|
@echo "lint via golangci-lint"
|
||||||
$(GOLANGCI_LINT) run \
|
$(GOLANGCI_LINT) run \
|
||||||
--config .golangci.toml \
|
--config .golangci.toml \
|
||||||
$(GO_FILES)
|
$(GO_FILES)
|
||||||
|
|
||||||
|
.PHONY: lint-go
|
||||||
lint-go: golangci-lint ## Run all code checks for backend. You can use GO_FILES to specify exact files to check
|
lint-go: golangci-lint ## Run all code checks for backend. You can use GO_FILES to specify exact files to check
|
||||||
|
|
||||||
# with disabled SC1071 we are ignored some TCL,Expect `/usr/bin/env expect` scripts
|
# with disabled SC1071 we are ignored some TCL,Expect `/usr/bin/env expect` scripts
|
||||||
|
.PHONY: shellcheck
|
||||||
shellcheck: $(SH_FILES) ## Run checks for shell scripts.
|
shellcheck: $(SH_FILES) ## Run checks for shell scripts.
|
||||||
@docker run --rm -v "$$PWD:/mnt" koalaman/shellcheck:stable \
|
@docker run --rm -v "$$PWD:/mnt" koalaman/shellcheck:stable \
|
||||||
$(SH_FILES) -e SC1071 -e SC2162
|
$(SH_FILES) -e SC1071 -e SC2162
|
||||||
@@ -242,6 +271,7 @@ shellcheck: $(SH_FILES) ## Run checks for shell scripts.
|
|||||||
TAG_SUFFIX=$(if $(WIRE_TAGS)!=oss,-$(WIRE_TAGS))
|
TAG_SUFFIX=$(if $(WIRE_TAGS)!=oss,-$(WIRE_TAGS))
|
||||||
PLATFORM=linux/amd64
|
PLATFORM=linux/amd64
|
||||||
|
|
||||||
|
.PHONY: build-docker-full
|
||||||
build-docker-full: ## Build Docker image for development.
|
build-docker-full: ## Build Docker image for development.
|
||||||
@echo "build docker container"
|
@echo "build docker container"
|
||||||
tar -ch . | \
|
tar -ch . | \
|
||||||
@@ -255,6 +285,7 @@ build-docker-full: ## Build Docker image for development.
|
|||||||
--tag grafana/grafana$(TAG_SUFFIX):dev \
|
--tag grafana/grafana$(TAG_SUFFIX):dev \
|
||||||
$(DOCKER_BUILD_ARGS)
|
$(DOCKER_BUILD_ARGS)
|
||||||
|
|
||||||
|
.PHONY: build-docker-full-ubuntu
|
||||||
build-docker-full-ubuntu: ## Build Docker image based on Ubuntu for development.
|
build-docker-full-ubuntu: ## Build Docker image based on Ubuntu for development.
|
||||||
@echo "build docker container"
|
@echo "build docker container"
|
||||||
tar -ch . | \
|
tar -ch . | \
|
||||||
@@ -274,6 +305,7 @@ build-docker-full-ubuntu: ## Build Docker image based on Ubuntu for development.
|
|||||||
|
|
||||||
# create docker-compose file with provided sources and start them
|
# create docker-compose file with provided sources and start them
|
||||||
# example: make devenv sources=postgres,auth/openldap
|
# example: make devenv sources=postgres,auth/openldap
|
||||||
|
.PHONY: devenv
|
||||||
ifeq ($(sources),)
|
ifeq ($(sources),)
|
||||||
devenv:
|
devenv:
|
||||||
@printf 'You have to define sources for this command \nexample: make devenv sources=postgres,openldap\n'
|
@printf 'You have to define sources for this command \nexample: make devenv sources=postgres,openldap\n'
|
||||||
@@ -287,15 +319,18 @@ devenv: devenv-down ## Start optional services, e.g. postgres, prometheus, and e
|
|||||||
docker-compose up -d --build
|
docker-compose up -d --build
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
.PHONY: devenv-down
|
||||||
devenv-down: ## Stop optional services.
|
devenv-down: ## Stop optional services.
|
||||||
@cd devenv; \
|
@cd devenv; \
|
||||||
test -f docker-compose.yaml && \
|
test -f docker-compose.yaml && \
|
||||||
docker-compose down || exit 0;
|
docker-compose down || exit 0;
|
||||||
|
|
||||||
|
.PHONY: devenv-postgres
|
||||||
devenv-postgres:
|
devenv-postgres:
|
||||||
@cd devenv; \
|
@cd devenv; \
|
||||||
sources=postgres_tests
|
sources=postgres_tests
|
||||||
|
|
||||||
|
.PHONY: devenv-mysql
|
||||||
devenv-mysql:
|
devenv-mysql:
|
||||||
@cd devenv; \
|
@cd devenv; \
|
||||||
sources=mysql_tests
|
sources=mysql_tests
|
||||||
@@ -307,18 +342,21 @@ devenv-mysql:
|
|||||||
# go-gettable dependency and so getting it installed can be inconvenient.
|
# go-gettable dependency and so getting it installed can be inconvenient.
|
||||||
#
|
#
|
||||||
# If you are working on changes to protobuf interfaces you may either use
|
# If you are working on changes to protobuf interfaces you may either use
|
||||||
# this target or run the individual scripts below directly.
|
# this target or run the individual scripts below directly
|
||||||
|
.PHONY: protobuf
|
||||||
protobuf: ## Compile protobuf definitions
|
protobuf: ## Compile protobuf definitions
|
||||||
bash scripts/protobuf-check.sh
|
bash scripts/protobuf-check.sh
|
||||||
bash pkg/plugins/backendplugin/pluginextensionv2/generate.sh
|
bash pkg/plugins/backendplugin/pluginextensionv2/generate.sh
|
||||||
bash pkg/plugins/backendplugin/secretsmanagerplugin/generate.sh
|
bash pkg/plugins/backendplugin/secretsmanagerplugin/generate.sh
|
||||||
bash pkg/services/store/entity/generate.sh
|
bash pkg/services/store/entity/generate.sh
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
clean: ## Clean up intermediate build artifacts.
|
clean: ## Clean up intermediate build artifacts.
|
||||||
@echo "cleaning"
|
@echo "cleaning"
|
||||||
rm -rf node_modules
|
rm -rf node_modules
|
||||||
rm -rf public/build
|
rm -rf public/build
|
||||||
|
|
||||||
|
.PHONY: gen-ts
|
||||||
gen-ts:
|
gen-ts:
|
||||||
@echo "generating TypeScript definitions"
|
@echo "generating TypeScript definitions"
|
||||||
go get github.com/tkrajina/typescriptify-golang-structs/typescriptify@v0.1.7
|
go get github.com/tkrajina/typescriptify-golang-structs/typescriptify@v0.1.7
|
||||||
@@ -328,6 +366,7 @@ gen-ts:
|
|||||||
# This repository's configuration is protected (https://readme.drone.io/signature/).
|
# This repository's configuration is protected (https://readme.drone.io/signature/).
|
||||||
# Use this make target to regenerate the configuration YAML files when
|
# Use this make target to regenerate the configuration YAML files when
|
||||||
# you modify starlark files.
|
# you modify starlark files.
|
||||||
|
.PHONY: drone
|
||||||
drone: $(DRONE)
|
drone: $(DRONE)
|
||||||
bash scripts/drone/env-var-check.sh
|
bash scripts/drone/env-var-check.sh
|
||||||
$(DRONE) starlark --format
|
$(DRONE) starlark --format
|
||||||
@@ -335,11 +374,14 @@ drone: $(DRONE)
|
|||||||
$(DRONE) --server https://drone.grafana.net sign --save grafana/grafana
|
$(DRONE) --server https://drone.grafana.net sign --save grafana/grafana
|
||||||
|
|
||||||
# Generate an Emacs tags table (https://www.gnu.org/software/emacs/manual/html_node/emacs/Tags-Tables.html) for Starlark files.
|
# Generate an Emacs tags table (https://www.gnu.org/software/emacs/manual/html_node/emacs/Tags-Tables.html) for Starlark files.
|
||||||
|
.PHONY: scripts/drone/TAGS
|
||||||
scripts/drone/TAGS: $(shell find scripts/drone -name '*.star')
|
scripts/drone/TAGS: $(shell find scripts/drone -name '*.star')
|
||||||
etags --lang none --regex="/def \(\w+\)[^:]+:/\1/" --regex="/\s*\(\w+\) =/\1/" $^ -o $@
|
etags --lang none --regex="/def \(\w+\)[^:]+:/\1/" --regex="/\s*\(\w+\) =/\1/" $^ -o $@
|
||||||
|
|
||||||
|
.PHONY: format-drone
|
||||||
format-drone:
|
format-drone:
|
||||||
buildifier --lint=fix -r scripts/drone
|
buildifier --lint=fix -r scripts/drone
|
||||||
|
|
||||||
|
.PHONY: help
|
||||||
help: ## Display this help.
|
help: ## Display this help.
|
||||||
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
|
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
|
||||||
|
|||||||
Reference in New Issue
Block a user