github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/Makefile (about)

     1  #
     2  # Usage: `make help`
     3  #
     4  SHELL := /bin/bash
     5  DEPLOY_DIR = ./deploy/dev/local
     6  SCRIPTS_DIR = ./scripts
     7  BUILD_DIR = ./cmd
     8  BUILD_SRC = $(BUILD_DIR)/aisnode/main.go
     9  
    10  ifeq ($(shell go env GOOS),linux)
    11  ifeq ($(strip $(GORACE)),)
    12  	CGO_DISABLE = CGO_ENABLED=0
    13  endif
    14  endif
    15  
    16  AISTORE_PATH = $(shell git rev-parse --show-toplevel)
    17  
    18  CLI_VERSION := $(shell ais version 2>/dev/null)
    19  
    20  # Do not print enter/leave directory when doing 'make -C DIR <target>'
    21  MAKEFLAGS += --no-print-directory
    22  
    23  # Uncomment to cross-compile aisnode and cli, respectively:
    24  # CROSS_COMPILE = docker run --rm -v $(AISTORE_PATH):/go/src/n -w /go/src/n golang:1.22
    25  # CROSS_COMPILE_CLI = docker run -e $(CGO_DISABLE) --rm -v $(AISTORE_PATH)/cmd/cli:/go/src/n -w /go/src/n golang:1.22
    26  
    27  # Build version, flags, and tags
    28  VERSION = $(shell git rev-parse --short HEAD)
    29  BUILD = $(shell date +%FT%T%z)
    30  BUILD_FLAGS += $(if $(strip $(GORACE)),-race,)
    31  BUILD_DEST = $(GOPATH)/bin
    32  ifdef GOBIN
    33  	BUILD_DEST = $(GOBIN)
    34  endif
    35  ifdef TAGS
    36  	BUILD_TAGS = $(AIS_BACKEND_PROVIDERS) $(TAGS)
    37  else
    38  	BUILD_TAGS = $(AIS_BACKEND_PROVIDERS)
    39  endif
    40  
    41  # Race detection
    42  ifneq ($(strip $(GORACE)),)
    43  	WRD = GORACE=$(GORACE)
    44  ifneq ($(findstring log_path,$(GORACE)),log_path)
    45  	@echo
    46  	@echo "Expecting GORACE='log_path=...', run 'make help' for usage examples"
    47  	@exit 1
    48  endif
    49  endif
    50  
    51  # Profiling
    52  # Example usage: MEM_PROFILE=/tmp/mem make kill clean deploy <<< $'5\n5\n4\ny\ny\nn\n'
    53  # Note that MEM_PROFILE (memprofile) option requires graceful shutdown (see `kill:`)
    54  ifdef MEM_PROFILE
    55  	export AIS_NODE_FLAGS += -memprofile=$(MEM_PROFILE)
    56  	BUILD_SRC = $(BUILD_DIR)/aisnodeprofile/main.go
    57  endif
    58  ifdef CPU_PROFILE
    59  	export AIS_NODE_FLAGS += -cpuprofile=$(CPU_PROFILE)
    60  	BUILD_SRC = $(BUILD_DIR)/aisnodeprofile/main.go
    61  endif
    62  
    63  # Intra-cluster networking: two alternative ways to build AIS `transport` package:
    64  # 1) using Go net/http, or
    65  # 2) with a 3rd party github.com/valyala/fasthttp aka "fasthttp"
    66  #
    67  # The second option is the current default.
    68  # To build with net/http, use `nethttp` build tag, for instance:
    69  # TAGS=nethttp make deploy <<< $'5\n5\n4\ny\ny\nn\n'
    70  
    71  ifeq ($(MODE),debug)
    72  	# Debug mode
    73  	GCFLAGS = -gcflags="all=-N -l"
    74  	LDFLAGS = -ldflags "-X 'main.build=$(VERSION)' -X 'main.buildtime=$(BUILD)'"
    75  	BUILD_TAGS += debug
    76  else
    77  	# Production mode
    78  	GCFLAGS =
    79  	LDFLAGS = -ldflags "-w -s -X 'main.build=$(VERSION)' -X 'main.buildtime=$(BUILD)'"
    80  endif
    81  
    82  ifdef AIS_DEBUG
    83  	BUILD_TAGS += debug
    84  endif
    85  
    86  # mono:  utilize go:linkname for monotonic time source
    87  # !mono: use standard Go runtime
    88  BUILD_TAGS += mono
    89  
    90  # Colors
    91  cyan = $(shell { tput setaf 6 || tput AF 6; } 2>/dev/null)
    92  term-reset = $(shell { tput sgr0 || tput me; } 2>/dev/null)
    93  $(call make-lazy,cyan)
    94  $(call make-lazy,term-reset)
    95  
    96  .PHONY: all node cli cli-autocompletions authn aisloader xmeta
    97  
    98  all: node cli authn aisloader ## Build all main binaries
    99  
   100  node: ## Build 'aisnode' binary
   101  	@echo "Building aisnode $(VERSION) [build tags:$(BUILD_TAGS)]"
   102  ifdef WRD
   103  	@echo "Deploying with race detector, writing reports to $(subst log_path=,,$(GORACE)).<pid>"
   104  endif
   105  ifdef CROSS_COMPILE
   106  	@$(CROSS_COMPILE) go build -o ./aisnode $(BUILD_FLAGS) -tags="$(BUILD_TAGS)" $(GCFLAGS) $(LDFLAGS) $(BUILD_SRC)
   107  	@mv ./aisnode $(BUILD_DEST)/.
   108  else
   109  	@$(WRD) go build -o $(BUILD_DEST)/aisnode $(BUILD_FLAGS) -tags="$(BUILD_TAGS)" $(GCFLAGS) $(LDFLAGS) $(BUILD_SRC)
   110  endif
   111  	@echo "done."
   112  
   113  cli: ## Build CLI binary. NOTE: 1) a separate go.mod, 2) static linkage with cgo disabled
   114  	@echo "Building ais (CLI) => $(BUILD_DEST)/ais [build tags:$(BUILD_TAGS)]"
   115  ifdef CROSS_COMPILE_CLI
   116  	cd $(BUILD_DIR)/cli && \
   117  	$(CROSS_COMPILE_CLI) go build -o ./ais -tags="$(BUILD_TAGS)" $(BUILD_FLAGS) $(LDFLAGS) *.go && mv ./ais $(BUILD_DEST)/.
   118  else
   119  	@cd $(BUILD_DIR)/cli && $(CGO_DISABLE) go build -o $(BUILD_DEST)/ais -tags="$(BUILD_TAGS)" $(BUILD_FLAGS) $(LDFLAGS) *.go
   120  endif
   121  	@echo "*** To enable autocompletions in your current shell, run:"
   122  ifeq ($(AISTORE_PATH),$(PWD))
   123  	@echo "*** 'source cmd/cli/autocomplete/bash' or 'source cmd/cli/autocomplete/zsh'"
   124  else
   125  	@echo "*** source $(AISTORE_PATH)/cmd/cli/autocomplete/[bash|zsh]"
   126  endif
   127  
   128  cli-autocompletions: ## Add CLI autocompletions
   129  	@echo "Adding CLI autocomplete..."
   130  	@./$(BUILD_DIR)/cli/autocomplete/install.sh
   131  
   132  authn: build-authn         ## Build AuthN
   133  aisloader: build-aisloader ## Build aisloader
   134  xmeta: build-xmeta         ## Build xmeta
   135  
   136  build-%:
   137  	@echo -n "Building $*... "
   138  ifdef CROSS_COMPILE
   139  	@$(CROSS_COMPILE) go build -o ./$* $(BUILD_FLAGS) $(LDFLAGS) $(BUILD_DIR)/$*/*.go
   140  	@mv ./$* $(BUILD_DEST)/.
   141  else
   142  	@go build -o $(BUILD_DEST)/$* $(BUILD_FLAGS) $(LDFLAGS) $(BUILD_DIR)/$*/*.go
   143  endif
   144  	@echo "done."
   145  
   146  #
   147  # local deployment (intended for developers)
   148  #
   149  .PHONY: deploy run restart
   150  
   151  ## Build 'aisnode' and parse command-line to generate configurations
   152  ## and deploy the specified numbers of local AIS (proxy and target) daemons
   153  deploy:
   154  	@"$(DEPLOY_DIR)/deploy.sh" $(RUN_ARGS)
   155  
   156  ## Same as `deploy` except for (not) generating daemon configurations.
   157  ## Use `make run` to restart cluster and utilize existing daemon configs.
   158  run:
   159  	@"$(DEPLOY_DIR)/deploy.sh" $(RUN_ARGS) --dont-generate-configs
   160  
   161  restart: kill run
   162  
   163  #
   164  # cleanup local deployment (cached objects, logs, and executables)
   165  #
   166  .PHONY: kill clean
   167  
   168  kill: ## Kill all locally deployed clusters (all targets and all proxies)
   169  ifndef CLI_VERSION
   170  	@echo "Warning: missing CLI (ais) executable for proper graceful shutdown"
   171  else
   172  	@ais cluster shutdown -y 2>/dev/null || true
   173  endif
   174  	@"$(DEPLOY_DIR)/kill.sh"
   175  
   176  clean: ## Remove all AIS related files and binaries
   177  	@echo -n "Cleaning... "
   178  	@"$(DEPLOY_DIR)/clean.sh"
   179  	@echo "done."
   180  
   181  #
   182  # modules
   183  #
   184  .PHONY: mod-all mod-clean mod-tidy
   185  
   186  mod-all: mod-clean mod-tidy
   187  	@echo "CLI ..." && cd cmd/cli && $(MAKE) mod-tidy
   188  
   189  # cleanup go-mod cache
   190  mod-clean:
   191  	go clean --modcache
   192  
   193  # in particular, remove unused
   194  mod-tidy:
   195  	go mod tidy
   196  
   197  # for local docker deployment
   198  .PHONY: deploy-docker stop-docker
   199  
   200  deploy-docker: ## Deploy AIS cluster inside the dockers
   201  # pass -d=3 because need 3 mountpaths for some tests
   202  	@cd ./deploy/dev/docker && ./deploy_docker.sh -d=3
   203  
   204  stop-docker: ## Stop deployed AIS docker cluster
   205  ifeq ($(FLAGS),)
   206  	$(warning missing environment variable: FLAGS="stop docker flags")
   207  endif
   208  	@./deploy/dev/docker/stop_docker.sh $(FLAGS)
   209  
   210  #
   211  # tests
   212  #
   213  .PHONY: test-bench test-aisloader test-envcheck test-short test-long test-run test-docker test
   214  
   215  # Target for benchmark tests
   216  test-bench: ## Run benchmarking tests
   217  	@$(SHELL) "$(SCRIPTS_DIR)/bootstrap.sh" test-bench
   218  
   219  test-envcheck:
   220  	@$(SHELL) "$(SCRIPTS_DIR)/bootstrap.sh" test-env
   221  
   222  test-short: test-envcheck ## Run short tests
   223  	@RE="$(RE)" BUCKET="$(BUCKET)" TESTS_DIR="$(TESTS_DIR)" AIS_ENDPOINT="$(AIS_ENDPOINT)" $(SHELL) "$(SCRIPTS_DIR)/bootstrap.sh" test-short
   224  	@cd $(BUILD_DIR)/cli && go test -v -tags=debug ./...
   225  
   226  test-assorted: test-envcheck # Run specific tests
   227  	@RE="ETLBucket|ETLConnectionError|ETLInitCode" BUCKET="$(BUCKET)" TESTS_DIR="$(TESTS_DIR)" AIS_ENDPOINT="$(AIS_ENDPOINT)" $(SHELL) "$(SCRIPTS_DIR)/bootstrap.sh" test-long
   228  
   229  test-long: test-envcheck ## Run all integration tests
   230  	@RE="$(RE)" BUCKET="$(BUCKET)" TESTS_DIR="$(TESTS_DIR)" AIS_ENDPOINT="$(AIS_ENDPOINT)" $(SHELL) "$(SCRIPTS_DIR)/bootstrap.sh" test-long
   231  	@cd $(BUILD_DIR)/cli && go test -v -tags=debug ./...
   232  
   233  test-aisloader:
   234  	@./bench/tools/aisloader/test/ci-test.sh $(FLAGS)
   235  
   236  test-run: test-envcheck # runs tests matching a specific regex
   237  ifeq ($(RE),)
   238  	$(error missing environment variable: RE="testnameregex")
   239  endif
   240  	@RE="$(RE)" BUCKET="$(BUCKET)" TESTS_DIR="$(TESTS_DIR)" AIS_ENDPOINT="$(AIS_ENDPOINT)" $(SHELL) "$(SCRIPTS_DIR)/bootstrap.sh" test-run
   241  
   242  test-docker: ## Run tests inside docker
   243  	@$(SHELL) "$(SCRIPTS_DIR)/bootstrap.sh" test-docker
   244  
   245  ci: spell-check fmt-check lint test-short ## Run CI related checkers and linters (requires BUCKET variable to be set)
   246  
   247  
   248  # Target for linters
   249  .PHONY: lint-update lint install-python-deps fmt-check fmt-fix spell-check spell-fix cyclo msgp-update
   250  
   251  ## Removes the previous version of `golangci-lint` and installs the latest (compare with lint-update-ci below)
   252  lint-update:
   253  	@rm -f $(GOPATH)/bin/golangci-lint
   254  	@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin latest
   255  
   256  ## Install specific `golangci-lint` version (hardcoded)
   257  ## See also: .github/workflows/lint.yml
   258  lint-update-ci:
   259  	@rm -f $(GOPATH)/bin/golangci-lint
   260  	@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.58.1
   261  
   262  lint:
   263  	@([[ -x "$(command -v golangci-lint)" ]] && echo "Cannot find golangci-lint, run 'make lint-update' to install" && exit 1) || true
   264  	@$(SHELL) "$(SCRIPTS_DIR)/bootstrap.sh" lint
   265  	@$(MAKE) -C $(BUILD_DIR)/cli lint
   266  
   267  install-python-deps:
   268  	@pip3 install -r ./python/aistore/common_requirements
   269  
   270  fmt-check: install-python-deps ## Check code formatting
   271  	@ [[ $$(black --help) ]] || pip3 install black[jupyter]
   272  	@$(SHELL) "$(SCRIPTS_DIR)/bootstrap.sh" fmt
   273  
   274  fmt-fix: ## Fix code formatting
   275  	@ [[ $$(black --help) ]] || pip3 install black[jupyter]
   276  	@$(SHELL) "$(SCRIPTS_DIR)/bootstrap.sh" fmt --fix
   277  
   278  spell-check: ## Run spell checker on the project
   279  	@GOOS="" go install github.com/client9/misspell/cmd/misspell@latest
   280  	@$(SHELL) "$(SCRIPTS_DIR)/bootstrap.sh" spell
   281  
   282  spell-fix: ## Fix spell checking issues
   283  	@GOOS="" go install github.com/client9/misspell/cmd/misspell@latest
   284  	@$(SHELL) "$(SCRIPTS_DIR)/bootstrap.sh" spell --fix
   285  
   286  msgp-update: ## MessagePack generator
   287  	@GOOS="" go install github.com/tinylib/msgp@latest
   288  
   289  # Misc Targets
   290  .PHONY: cpuprof flamegraph dev-init
   291  
   292  # run benchmarks 10 times to generate cpu.prof
   293  cpuprof:
   294  	@go test -v -run=XXX -bench=. -count 10 -cpuprofile=/tmp/cpu.prof
   295  
   296  flamegraph: cpuprof
   297  	@go tool pprof -http ":6060" /tmp/cpu.prof
   298  
   299  # To help with working with a non-github remote
   300  # It replaces existing github.com AIStore remote with the one specified by REMOTE
   301  dev-init:
   302  	@$(SHELL) "$(SCRIPTS_DIR)/bootstrap.sh" dev-init
   303  
   304  .PHONY: help
   305  help:
   306  	@echo "Usage:"
   307  	@echo "  [VAR=foo VAR2=bar...] make [target...]"
   308  	@echo ""
   309  	@echo "Useful commands:"
   310  	@grep -Eh '^[a-zA-Z._-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "  $(cyan)%-30s$(term-reset) %s\n", $$1, $$2}'
   311  	@echo ""
   312  	@echo "Examples:"
   313  	@printf "  $(cyan)%s$(term-reset)\n    %s\n\n" \
   314  		"make deploy" "Deploy cluster locally" \
   315  		"make kill clean" "Stop locally deployed cluster and cleanup all cluster-related data and bucket metadata (but not cluster map)" \
   316  		"make kill deploy <<< $$'7\n2\n4\ny\ny\nn\n0\n'"  "Shutdown and then (non-interactively) generate local configs and deploy a cluster consisting of 7 targets (4 mountpaths each) and 2 proxies; build 'aisnode' executable with the support for GCP and AWS backends" \
   317  		"make restart <<< $$'7\n2\n4\ny\ny\nn\nn\n0\n'"  "Restart a cluster of 7 targets (4 mountpaths each) and 2 proxies; utilize previously generated (pre-shutdown) local configurations" \
   318  		"RUN_ARGS=-override_backends MODE=debug make kill deploy <<< $$'4\n1\n4\nn\nn\nn\nn\n0\n'"  "Redeploy (4 targets + 1 proxy) cluster; build executable for debug without any backend-supporting libraries; use RUN_ARGS to pass additional command-line option ('-override_backends=true') to each running node"\
   319  		"RUN_ARGS='-override_backends -standby' MODE=debug make kill deploy <<< $$'4\n1\n4\nn\nn\nn\nn\n0\n'"  "Same as above, but additionally run all 4 targets in a standby mode"\
   320  		"make kill clean cli deploy <<< $$'7\n2\n4\ny\ny\nn\n1G\n'"  "Shutdown, cleanup, build CLI, and redeploy from scratch; create 4 loopback devices (size = 1G, one loopback per mountpath)" \
   321  		"GORACE='log_path=/tmp/race' make deploy" "Deploy cluster with race detector, write reports to /tmp/race.<PID>" \
   322  		"MODE=debug make deploy" "Deploy cluster with 'aisnode' (AIS target and proxy) executable built with debug symbols and debug asserts enabled" \
   323  		"BUCKET=tmp make test-short" "Run all short tests" \
   324  		"BUCKET=<existing-cloud-bucket> make test-long" "Run all tests" \
   325  		"BUCKET=tmp make ci" "Run style, lint, and spell checks, as well as all short tests" \
   326  		"MEM_PROFILE=/tmp/mem make deploy" "Deploy cluster with memory profiling enabled, write reports to /tmp/mem.<PID> (and make sure to stop gracefully)" \
   327  		"CPU_PROFILE=/tmp/cpu make deploy" "Build and deploy cluster instrumented for CPU profiling, write reports to /tmp/cpu.<PID>" \
   328  		"TAGS=nethttp make deploy" "Build 'transport' package with net/http (see transport/README.md) and deploy cluster locally" \