github.com/haalcala/mattermost-server-change-repo/v5@v5.33.2/Makefile (about)

     1  .PHONY: build package run stop run-client run-server run-haserver stop-client stop-server restart restart-server restart-client restart-haserver start-docker clean-dist clean nuke check-style check-client-style check-server-style check-unit-tests test dist prepare-enteprise run-client-tests setup-run-client-tests cleanup-run-client-tests test-client build-linux build-osx build-windows internal-test-web-client vet run-server-for-web-client-tests diff-config prepackaged-plugins prepackaged-binaries test-server test-server-ee test-server-quick test-server-race start-docker-check
     2  
     3  ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
     4  
     5  ifeq ($(OS),Windows_NT)
     6  	PLATFORM := Windows
     7  else
     8  	PLATFORM := $(shell uname)
     9  endif
    10  
    11  # Set an environment variable on Linux used to resolve `docker.host.internal` inconsistencies with
    12  # docker. This can be reworked once https://github.com/docker/for-linux/issues/264 is resolved
    13  # satisfactorily.
    14  ifeq ($(PLATFORM),Linux)
    15  	export IS_LINUX = -linux
    16  else
    17  	export IS_LINUX =
    18  endif
    19  
    20  IS_CI ?= false
    21  # Build Flags
    22  BUILD_NUMBER ?= $(BUILD_NUMBER:)
    23  BUILD_DATE = $(shell date -u)
    24  BUILD_HASH = $(shell git rev-parse HEAD)
    25  # If we don't set the build number it defaults to dev
    26  ifeq ($(BUILD_NUMBER),)
    27  	BUILD_NUMBER := dev
    28  endif
    29  BUILD_ENTERPRISE_DIR ?= ../enterprise
    30  BUILD_ENTERPRISE ?= true
    31  BUILD_ENTERPRISE_READY = false
    32  BUILD_TYPE_NAME = team
    33  BUILD_HASH_ENTERPRISE = none
    34  ifneq ($(wildcard $(BUILD_ENTERPRISE_DIR)/.),)
    35  	ifeq ($(BUILD_ENTERPRISE),true)
    36  		BUILD_ENTERPRISE_READY = true
    37  		BUILD_TYPE_NAME = enterprise
    38  		BUILD_HASH_ENTERPRISE = $(shell cd $(BUILD_ENTERPRISE_DIR) && git rev-parse HEAD)
    39  	else
    40  		BUILD_ENTERPRISE_READY = false
    41  		BUILD_TYPE_NAME = team
    42  	endif
    43  else
    44  	BUILD_ENTERPRISE_READY = false
    45  	BUILD_TYPE_NAME = team
    46  endif
    47  BUILD_WEBAPP_DIR ?= ../mattermost-webapp
    48  BUILD_CLIENT = false
    49  BUILD_HASH_CLIENT = independant
    50  ifneq ($(wildcard $(BUILD_WEBAPP_DIR)/.),)
    51  	ifeq ($(BUILD_CLIENT),true)
    52  		BUILD_CLIENT = true
    53  		BUILD_HASH_CLIENT = $(shell cd $(BUILD_WEBAPP_DIR) && git rev-parse HEAD)
    54  	else
    55  		BUILD_CLIENT = false
    56  	endif
    57  else
    58  	BUILD_CLIENT = false
    59  endif
    60  
    61  # Go Flags
    62  GOFLAGS ?= $(GOFLAGS:)
    63  # We need to export GOBIN to allow it to be set
    64  # for processes spawned from the Makefile
    65  export GOBIN ?= $(PWD)/bin
    66  GO=go
    67  DELVE=dlv
    68  LDFLAGS += -X "github.com/mattermost/mattermost-server/v5/model.BuildNumber=$(BUILD_NUMBER)"
    69  LDFLAGS += -X "github.com/mattermost/mattermost-server/v5/model.BuildDate=$(BUILD_DATE)"
    70  LDFLAGS += -X "github.com/mattermost/mattermost-server/v5/model.BuildHash=$(BUILD_HASH)"
    71  LDFLAGS += -X "github.com/mattermost/mattermost-server/v5/model.BuildHashEnterprise=$(BUILD_HASH_ENTERPRISE)"
    72  LDFLAGS += -X "github.com/mattermost/mattermost-server/v5/model.BuildEnterpriseReady=$(BUILD_ENTERPRISE_READY)"
    73  
    74  GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
    75  GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
    76  MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
    77  MINIMUM_SUPPORTED_GO_MINOR_VERSION = 15
    78  GO_VERSION_VALIDATION_ERR_MSG = Golang version is not supported, please update to at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION)
    79  
    80  # GOOS/GOARCH of the build host, used to determine whether we're cross-compiling or not
    81  BUILDER_GOOS_GOARCH="$(shell $(GO) env GOOS)_$(shell $(GO) env GOARCH)"
    82  
    83  PLATFORM_FILES="./cmd/mattermost/main.go"
    84  
    85  # Output paths
    86  DIST_ROOT=dist
    87  DIST_PATH=$(DIST_ROOT)/mattermost
    88  
    89  # Tests
    90  TESTS=.
    91  
    92  # Packages lists
    93  TE_PACKAGES=$(shell $(GO) list ./... | grep -v ./data)
    94  
    95  # Plugins Packages
    96  PLUGIN_PACKAGES ?= mattermost-plugin-antivirus-v0.1.2
    97  PLUGIN_PACKAGES += mattermost-plugin-autolink-v1.2.1
    98  PLUGIN_PACKAGES += mattermost-plugin-aws-SNS-v1.2.0
    99  PLUGIN_PACKAGES += mattermost-plugin-channel-export-v0.2.2
   100  PLUGIN_PACKAGES += mattermost-plugin-custom-attributes-v1.3.0
   101  PLUGIN_PACKAGES += mattermost-plugin-github-v2.0.0
   102  PLUGIN_PACKAGES += mattermost-plugin-gitlab-v1.3.0
   103  PLUGIN_PACKAGES += mattermost-plugin-incident-collaboration-v1.4.0
   104  PLUGIN_PACKAGES += mattermost-plugin-jenkins-v1.1.0
   105  PLUGIN_PACKAGES += mattermost-plugin-jira-v2.4.0
   106  PLUGIN_PACKAGES += mattermost-plugin-nps-v1.1.0
   107  PLUGIN_PACKAGES += mattermost-plugin-welcomebot-v1.2.0
   108  PLUGIN_PACKAGES += mattermost-plugin-zoom-v1.5.0
   109  
   110  # Prepares the enterprise build if exists. The IGNORE stuff is a hack to get the Makefile to execute the commands outside a target
   111  ifeq ($(BUILD_ENTERPRISE_READY),true)
   112  	IGNORE:=$(shell echo Enterprise build selected, preparing)
   113  	IGNORE:=$(shell rm -f imports/imports.go)
   114  	IGNORE:=$(shell cp $(BUILD_ENTERPRISE_DIR)/imports/imports.go imports/)
   115  	IGNORE:=$(shell rm -f enterprise)
   116  	IGNORE:=$(shell ln -s $(BUILD_ENTERPRISE_DIR) enterprise)
   117  else
   118  	IGNORE:=$(shell rm -f imports/imports.go)
   119  endif
   120  
   121  EE_PACKAGES=$(shell $(GO) list ./enterprise/...)
   122  
   123  ifeq ($(BUILD_ENTERPRISE_READY),true)
   124  ALL_PACKAGES=$(TE_PACKAGES) $(EE_PACKAGES)
   125  else
   126  ALL_PACKAGES=$(TE_PACKAGES)
   127  endif
   128  
   129  all: run ## Alias for 'run'.
   130  
   131  -include config.override.mk
   132  include config.mk
   133  include build/*.mk
   134  
   135  RUN_IN_BACKGROUND ?=
   136  ifeq ($(RUN_SERVER_IN_BACKGROUND),true)
   137  	RUN_IN_BACKGROUND := &
   138  endif
   139  
   140  start-docker-check:
   141  ifeq (,$(findstring minio,$(ENABLED_DOCKER_SERVICES)))
   142    TEMP_DOCKER_SERVICES:=$(TEMP_DOCKER_SERVICES) minio
   143  endif
   144  ifeq ($(BUILD_ENTERPRISE_READY),true)
   145    ifeq (,$(findstring openldap,$(ENABLED_DOCKER_SERVICES)))
   146      TEMP_DOCKER_SERVICES:=$(TEMP_DOCKER_SERVICES) openldap
   147    endif
   148    ifeq (,$(findstring elasticsearch,$(ENABLED_DOCKER_SERVICES)))
   149      TEMP_DOCKER_SERVICES:=$(TEMP_DOCKER_SERVICES) elasticsearch
   150    endif
   151  endif
   152  ENABLED_DOCKER_SERVICES:=$(ENABLED_DOCKER_SERVICES) $(TEMP_DOCKER_SERVICES)
   153  
   154  start-docker: ## Starts the docker containers for local development.
   155  ifneq ($(IS_CI),false)
   156  	@echo CI Build: skipping docker start
   157  else ifeq ($(MM_NO_DOCKER),true)
   158  	@echo No Docker Enabled: skipping docker start
   159  else
   160  	@echo Starting docker containers
   161  
   162  	$(GO) run ./build/docker-compose-generator/main.go $(ENABLED_DOCKER_SERVICES) | docker-compose -f docker-compose.makefile.yml -f /dev/stdin run --rm start_dependencies
   163  ifneq (,$(findstring openldap,$(ENABLED_DOCKER_SERVICES)))
   164  	cat tests/${LDAP_DATA}-data.ldif | docker-compose -f docker-compose.makefile.yml exec -T openldap bash -c 'ldapadd -x -D "cn=admin,dc=mm,dc=test,dc=com" -w mostest || true';
   165  endif
   166  endif
   167  
   168  run-haserver: run-client
   169  ifeq ($(BUILD_ENTERPRISE_READY),true)
   170  	@echo Starting mattermost in an HA topology
   171  
   172  	docker-compose -f docker-compose.yaml up haproxy
   173  endif
   174  
   175  stop-docker: ## Stops the docker containers for local development.
   176  ifeq ($(MM_NO_DOCKER),true)
   177  	@echo No Docker Enabled: skipping docker stop
   178  else
   179  	@echo Stopping docker containers
   180  
   181  	docker-compose stop
   182  endif
   183  
   184  clean-docker: ## Deletes the docker containers for local development.
   185  ifeq ($(MM_NO_DOCKER),true)
   186  	@echo No Docker Enabled: skipping docker clean
   187  else
   188  	@echo Removing docker containers
   189  
   190  	docker-compose down -v
   191  	docker-compose rm -v
   192  endif
   193  
   194  
   195  plugin-checker:
   196  	$(GO) run $(GOFLAGS) ./plugin/checker
   197  
   198  prepackaged-plugins: ## Populate the prepackaged-plugins directory
   199  	@echo Downloading prepackaged plugins
   200  	mkdir -p prepackaged_plugins
   201  	@cd prepackaged_plugins && for plugin_package in $(PLUGIN_PACKAGES) ; do \
   202  		curl -f -O -L https://plugins-store.test.mattermost.com/release/$$plugin_package.tar.gz; \
   203  		curl -f -O -L https://plugins-store.test.mattermost.com/release/$$plugin_package.tar.gz.sig; \
   204  	done
   205  
   206  prepackaged-binaries: ## Populate the prepackaged-binaries to the bin directory
   207  ifeq ($(shell test -f bin/mmctl && printf "yes"),yes)
   208  	@echo "MMCTL already exists in bin/mmctl not downloading a new version."
   209  else
   210  	@scripts/download_mmctl_release.sh
   211  endif
   212  
   213  golangci-lint: ## Run golangci-lint on codebase
   214  # https://stackoverflow.com/a/677212/1027058 (check if a command exists or not)
   215  	@if ! [ -x "$$(command -v golangci-lint)" ]; then \
   216  		echo "golangci-lint is not installed. Please see https://github.com/golangci/golangci-lint#install for installation instructions."; \
   217  		exit 1; \
   218  	fi; \
   219  
   220  	@echo Running golangci-lint
   221  	golangci-lint run ./...
   222  ifeq ($(BUILD_ENTERPRISE_READY),true)
   223  ifneq ($(MM_NO_ENTERPRISE_LINT),true)
   224  	golangci-lint run ./enterprise/...
   225  endif
   226  endif
   227  
   228  app-layers: ## Extract interface from App struct
   229  	$(GO) get -modfile=go.tools.mod github.com/reflog/struct2interface
   230  	$(GOBIN)/struct2interface -f "app" -o "app/app_iface.go" -p "app" -s "App" -i "AppIface" -t ./app/layer_generators/app_iface.go.tmpl
   231  	$(GO) run ./app/layer_generators -in ./app/app_iface.go -out ./app/opentracing/opentracing_layer.go -template ./app/layer_generators/opentracing_layer.go.tmpl
   232  
   233  i18n-extract: ## Extract strings for translation from the source code
   234  	$(GO) get -modfile=go.tools.mod github.com/mattermost/mattermost-utilities/mmgotool
   235  	$(GOBIN)/mmgotool i18n extract --portal-dir=""
   236  
   237  i18n-check: ## Exit on empty translation strings and translation source strings
   238  	$(GO) get -modfile=go.tools.mod github.com/mattermost/mattermost-utilities/mmgotool
   239  	$(GOBIN)/mmgotool i18n clean-empty --portal-dir="" --check
   240  	$(GOBIN)/mmgotool i18n check-empty-src --portal-dir=""
   241  
   242  store-mocks: ## Creates mock files.
   243  	$(GO) get -modfile=go.tools.mod github.com/vektra/mockery/...
   244  	$(GOBIN)/mockery -dir store -all -output store/storetest/mocks -note 'Regenerate this file using `make store-mocks`.'
   245  
   246  telemetry-mocks: ## Creates mock files.
   247  	$(GO) get -modfile=go.tools.mod github.com/vektra/mockery/...
   248  	$(GOBIN)/mockery -dir services/telemetry -all -output services/telemetry/mocks -note 'Regenerate this file using `make telemetry-mocks`.'
   249  
   250  store-layers: ## Generate layers for the store
   251  	$(GO) generate $(GOFLAGS) ./store
   252  
   253  filesstore-mocks: ## Creates mock files.
   254  	$(GO) get -modfile=go.tools.mod github.com/vektra/mockery/...
   255  	$(GOBIN)/mockery -dir services/filesstore -all -output services/filesstore/mocks -note 'Regenerate this file using `make filesstore-mocks`.'
   256  
   257  ldap-mocks: ## Creates mock files for ldap.
   258  	$(GO) get -modfile=go.tools.mod github.com/vektra/mockery/...
   259  	$(GOBIN)/mockery -dir enterprise/ldap -all -output enterprise/ldap/mocks -note 'Regenerate this file using `make ldap-mocks`.'
   260  
   261  plugin-mocks: ## Creates mock files for plugins.
   262  	$(GO) get -modfile=go.tools.mod github.com/vektra/mockery/...
   263  	$(GOBIN)/mockery -dir plugin -name API -output plugin/plugintest -outpkg plugintest -case underscore -note 'Regenerate this file using `make plugin-mocks`.'
   264  	$(GOBIN)/mockery -dir plugin -name Hooks -output plugin/plugintest -outpkg plugintest -case underscore -note 'Regenerate this file using `make plugin-mocks`.'
   265  	$(GOBIN)/mockery -dir plugin -name Helpers -output plugin/plugintest -outpkg plugintest -case underscore -note 'Regenerate this file using `make plugin-mocks`.'
   266  
   267  einterfaces-mocks: ## Creates mock files for einterfaces.
   268  	$(GO) get -modfile=go.tools.mod github.com/vektra/mockery/...
   269  	$(GOBIN)/mockery -dir einterfaces -all -output einterfaces/mocks -note 'Regenerate this file using `make einterfaces-mocks`.'
   270  
   271  searchengine-mocks: ## Creates mock files for searchengines.
   272  	$(GO) get -modfile=go.tools.mod github.com/vektra/mockery/...
   273  	$(GOBIN)/mockery -dir services/searchengine -all -output services/searchengine/mocks -note 'Regenerate this file using `make searchengine-mocks`.'
   274  
   275  pluginapi: ## Generates api and hooks glue code for plugins
   276  	$(GO) generate $(GOFLAGS) ./plugin
   277  
   278  check-prereqs: ## Checks prerequisite software status.
   279  	./scripts/prereq-check.sh
   280  
   281  check-prereqs-enterprise: ## Checks prerequisite software status for enterprise.
   282  ifeq ($(BUILD_ENTERPRISE_READY),true)
   283  	./scripts/prereq-check-enterprise.sh
   284  endif
   285  
   286  check-style: golangci-lint plugin-checker vet ## Runs golangci against all packages
   287  
   288  test-te-race: ## Checks for race conditions in the team edition.
   289  	@echo Testing TE race conditions
   290  
   291  	@echo "Packages to test: "$(TE_PACKAGES)
   292  
   293  	@for package in $(TE_PACKAGES); do \
   294  		echo "Testing "$$package; \
   295  		$(GO) test $(GOFLAGS) -race -run=$(TESTS) -test.timeout=4000s $$package || exit 1; \
   296  	done
   297  
   298  test-ee-race: check-prereqs-enterprise ## Checks for race conditions in the enterprise edition.
   299  	@echo Testing EE race conditions
   300  
   301  ifeq ($(BUILD_ENTERPRISE_READY),true)
   302  	@echo "Packages to test: "$(EE_PACKAGES)
   303  
   304  	for package in $(EE_PACKAGES); do \
   305  		echo "Testing "$$package; \
   306  		$(GO) test $(GOFLAGS) -race -run=$(TESTS) -c $$package; \
   307  		if [ -f $$(basename $$package).test ]; then \
   308  			echo "Testing "$$package; \
   309  			./$$(basename $$package).test -test.timeout=2000s || exit 1; \
   310  			rm -r $$(basename $$package).test; \
   311  		fi; \
   312  	done
   313  
   314  	rm -f config/*.crt
   315  	rm -f config/*.key
   316  endif
   317  
   318  test-server-race: test-te-race test-ee-race ## Checks for race conditions.
   319  	find . -type d -name data -not -path './vendor/*' | xargs rm -rf
   320  
   321  do-cover-file: ## Creates the test coverage report file.
   322  	@echo "mode: count" > cover.out
   323  
   324  go-junit-report:
   325  	$(GO) get -modfile=go.tools.mod github.com/jstemmer/go-junit-report
   326  
   327  test-compile: ## Compile tests.
   328  	@echo COMPILE TESTS
   329  
   330  	for package in $(TE_PACKAGES) $(EE_PACKAGES); do \
   331  		$(GO) test $(GOFLAGS) -c $$package; \
   332  	done
   333  
   334  test-db-migration: start-docker ## Gets diff of upgrade vs new instance schemas.
   335  	./scripts/mysql-migration-test.sh
   336  	./scripts/psql-migration-test.sh
   337  
   338  gomodtidy:
   339  	@cp go.mod go.mod.orig
   340  	@cp go.sum go.sum.orig
   341  	$(GO) mod tidy
   342  	@if [ "$$(diff go.mod go.mod.orig)" != "" -o "$$(diff go.sum go.sum.orig)" != "" ]; then \
   343  		echo "go.mod/go.sum was modified. \ndiff- $$(diff go.mod go.mod.orig) \n$$(diff go.sum go.sum.orig) \nRun \"go mod tidy\"."; \
   344  		rm go.*.orig; \
   345  		exit 1; \
   346  	fi;
   347  	@rm go.*.orig;
   348  
   349  test-server: check-prereqs-enterprise start-docker-check start-docker go-junit-report do-cover-file ## Runs tests.
   350  ifeq ($(BUILD_ENTERPRISE_READY),true)
   351  	@echo Running all tests
   352  else
   353  	@echo Running only TE tests
   354  endif
   355  	./scripts/test.sh "$(GO)" "$(GOFLAGS)" "$(ALL_PACKAGES)" "$(TESTS)" "$(TESTFLAGS)" "$(GOBIN)"
   356    ifneq ($(IS_CI),true)
   357      ifneq ($(MM_NO_DOCKER),true)
   358        ifneq ($(TEMP_DOCKER_SERVICES),)
   359  	      @echo Stopping temporary docker services
   360  	      docker-compose stop $(TEMP_DOCKER_SERVICES)
   361        endif
   362      endif
   363    endif
   364  
   365  test-server-ee: check-prereqs-enterprise start-docker-check start-docker go-junit-report do-cover-file ## Runs EE tests.
   366  	@echo Running only EE tests
   367  	./scripts/test.sh "$(GO)" "$(GOFLAGS)" "$(EE_PACKAGES)" "$(TESTS)" "$(TESTFLAGS)" "$(GOBIN)"
   368  
   369  test-server-quick: check-prereqs-enterprise ## Runs only quick tests.
   370  ifeq ($(BUILD_ENTERPRISE_READY),true)
   371  	@echo Running all tests
   372  	$(GO) test $(GOFLAGS) -short $(ALL_PACKAGES)
   373  else
   374  	@echo Running only TE tests
   375  	$(GO) test $(GOFLAGS) -short $(TE_PACKAGES)
   376  endif
   377  
   378  internal-test-web-client: ## Runs web client tests.
   379  	$(GO) run $(GOFLAGS) $(PLATFORM_FILES) test web_client_tests
   380  
   381  run-server-for-web-client-tests: ## Tests the server for web client.
   382  	$(GO) run $(GOFLAGS) $(PLATFORM_FILES) test web_client_tests_server
   383  
   384  test-client: ## Test client app.
   385  	@echo Running client tests
   386  
   387  	cd $(BUILD_WEBAPP_DIR) && $(MAKE) test
   388  
   389  test: test-server test-client ## Runs all checks and tests below (except race detection and postgres).
   390  
   391  cover: ## Runs the golang coverage tool. You must run the unit tests first.
   392  	@echo Opening coverage info in browser. If this failed run make test first
   393  
   394  	$(GO) tool cover -html=cover.out
   395  	$(GO) tool cover -html=ecover.out
   396  
   397  test-data: start-docker ## Add test data to the local instance.
   398  	$(GO) run $(GOFLAGS) -ldflags '$(LDFLAGS)' $(PLATFORM_FILES) config set TeamSettings.MaxUsersPerTeam 100
   399  	$(GO) run $(GOFLAGS) -ldflags '$(LDFLAGS)' $(PLATFORM_FILES) sampledata -w 4 -u 60
   400  
   401  	@echo You may need to restart the Mattermost server before using the following
   402  	@echo ========================================================================
   403  	@echo Login with a system admin account username=sysadmin password=Sys@dmin-sample1
   404  	@echo Login with a regular account username=user-1 password=SampleUs@r-1
   405  	@echo ========================================================================
   406  
   407  validate-go-version: ## Validates the installed version of go against Mattermost's minimum requirement.
   408  	@if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
   409  		exit 0 ;\
   410  	elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
   411  		echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
   412  		exit 1; \
   413  	elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \
   414  		echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
   415  		exit 1; \
   416  	fi
   417  
   418  run-server: prepackaged-binaries validate-go-version start-docker ## Starts the server.
   419  	@echo Running mattermost for development
   420  
   421  	mkdir -p $(BUILD_WEBAPP_DIR)/dist/files
   422  	$(GO) run $(GOFLAGS) -ldflags '$(LDFLAGS)' $(PLATFORM_FILES) --disableconfigwatch 2>&1 | \
   423  	    $(GO) run $(GOFLAGS) -ldflags '$(LDFLAGS)' $(PLATFORM_FILES) logs --logrus $(RUN_IN_BACKGROUND)
   424  
   425  debug-server: start-docker ## Compile and start server using delve.
   426  	mkdir -p $(BUILD_WEBAPP_DIR)/dist/files
   427  	$(DELVE) debug $(PLATFORM_FILES) --build-flags="-ldflags '\
   428  		-X github.com/mattermost/mattermost-server/v5/model.BuildNumber=$(BUILD_NUMBER)\
   429  		-X \"github.com/mattermost/mattermost-server/v5/model.BuildDate=$(BUILD_DATE)\"\
   430  		-X github.com/mattermost/mattermost-server/v5/model.BuildHash=$(BUILD_HASH)\
   431  		-X github.com/mattermost/mattermost-server/v5/model.BuildHashEnterprise=$(BUILD_HASH_ENTERPRISE)\
   432  		-X github.com/mattermost/mattermost-server/v5/model.BuildEnterpriseReady=$(BUILD_ENTERPRISE_READY)'"
   433  
   434  debug-server-headless: start-docker ## Debug server from within an IDE like VSCode or IntelliJ.
   435  	mkdir -p $(BUILD_WEBAPP_DIR)/dist/files
   436  	$(DELVE) debug --headless --listen=:2345 --api-version=2 --accept-multiclient $(PLATFORM_FILES) --build-flags="-ldflags '\
   437  		-X github.com/mattermost/mattermost-server/v5/model.BuildNumber=$(BUILD_NUMBER)\
   438  		-X \"github.com/mattermost/mattermost-server/v5/model.BuildDate=$(BUILD_DATE)\"\
   439  		-X github.com/mattermost/mattermost-server/v5/model.BuildHash=$(BUILD_HASH)\
   440  		-X github.com/mattermost/mattermost-server/v5/model.BuildHashEnterprise=$(BUILD_HASH_ENTERPRISE)\
   441  		-X github.com/mattermost/mattermost-server/v5/model.BuildEnterpriseReady=$(BUILD_ENTERPRISE_READY)'"
   442  
   443  run-cli: start-docker ## Runs CLI.
   444  	@echo Running mattermost for development
   445  	@echo Example should be like 'make ARGS="-version" run-cli'
   446  
   447  	$(GO) run $(GOFLAGS) -ldflags '$(LDFLAGS)' $(PLATFORM_FILES) ${ARGS}
   448  
   449  run-client: ## Runs the webapp.
   450  	@echo Running mattermost client for development
   451  
   452  	ln -nfs $(BUILD_WEBAPP_DIR)/dist client
   453  	cd $(BUILD_WEBAPP_DIR) && $(MAKE) run
   454  
   455  run-client-fullmap: ## Legacy alias to run-client
   456  	@echo Running mattermost client for development
   457  
   458  	cd $(BUILD_WEBAPP_DIR) && $(MAKE) run
   459  
   460  run: check-prereqs run-server run-client ## Runs the server and webapp.
   461  
   462  run-fullmap: run-server run-client ## Legacy alias to run
   463  
   464  stop-server: ## Stops the server.
   465  	@echo Stopping mattermost
   466  
   467  ifeq ($(BUILDER_GOOS_GOARCH),"windows_amd64")
   468  	wmic process where "Caption='go.exe' and CommandLine like '%go.exe run%'" call terminate
   469  	wmic process where "Caption='mattermost.exe' and CommandLine like '%go-build%'" call terminate
   470  else
   471  	@for PID in $$(ps -ef | grep "[g]o run" | grep "disableconfigwatch" | awk '{ print $$2 }'); do \
   472  		echo stopping go $$PID; \
   473  		kill $$PID; \
   474  	done
   475  	@for PID in $$(ps -ef | grep "[g]o-build" | grep "disableconfigwatch" | awk '{ print $$2 }'); do \
   476  		echo stopping mattermost $$PID; \
   477  		kill $$PID; \
   478  	done
   479  endif
   480  
   481  stop-client: ## Stops the webapp.
   482  	@echo Stopping mattermost client
   483  
   484  	cd $(BUILD_WEBAPP_DIR) && $(MAKE) stop
   485  
   486  stop: stop-server stop-client stop-docker ## Stops server, client and the docker compose.
   487  
   488  restart: restart-server restart-client ## Restarts the server and webapp.
   489  
   490  restart-server: | stop-server run-server ## Restarts the mattermost server to pick up development change.
   491  
   492  restart-haserver:
   493  	@echo Restarting mattermost in an HA topology
   494  
   495  	docker-compose restart follower
   496  	docker-compose restart leader
   497  	docker-compose restart haproxy
   498  
   499  restart-client: | stop-client run-client ## Restarts the webapp.
   500  
   501  run-job-server: ## Runs the background job server.
   502  	@echo Running job server for development
   503  	$(GO) run $(GOFLAGS) -ldflags '$(LDFLAGS)' $(PLATFORM_FILES) jobserver --disableconfigwatch &
   504  
   505  config-ldap: ## Configures LDAP.
   506  	@echo Setting up configuration for local LDAP
   507  
   508  	@sed -i'' -e 's|"LdapServer": ".*"|"LdapServer": "localhost"|g' config/config.json
   509  	@sed -i'' -e 's|"BaseDN": ".*"|"BaseDN": "dc=mm,dc=test,dc=com"|g' config/config.json
   510  	@sed -i'' -e 's|"BindUsername": ".*"|"BindUsername": "cn=admin,dc=mm,dc=test,dc=com"|g' config/config.json
   511  	@sed -i'' -e 's|"BindPassword": ".*"|"BindPassword": "mostest"|g' config/config.json
   512  	@sed -i'' -e 's|"FirstNameAttribute": ".*"|"FirstNameAttribute": "cn"|g' config/config.json
   513  	@sed -i'' -e 's|"LastNameAttribute": ".*"|"LastNameAttribute": "sn"|g' config/config.json
   514  	@sed -i'' -e 's|"NicknameAttribute": ".*"|"NicknameAttribute": "cn"|g' config/config.json
   515  	@sed -i'' -e 's|"EmailAttribute": ".*"|"EmailAttribute": "mail"|g' config/config.json
   516  	@sed -i'' -e 's|"UsernameAttribute": ".*"|"UsernameAttribute": "uid"|g' config/config.json
   517  	@sed -i'' -e 's|"IdAttribute": ".*"|"IdAttribute": "uid"|g' config/config.json
   518  	@sed -i'' -e 's|"LoginIdAttribute": ".*"|"LoginIdAttribute": "uid"|g' config/config.json
   519  	@sed -i'' -e 's|"GroupDisplayNameAttribute": ".*"|"GroupDisplayNameAttribute": "cn"|g' config/config.json
   520  	@sed -i'' -e 's|"GroupIdAttribute": ".*"|"GroupIdAttribute": "entryUUID"|g' config/config.json
   521  
   522  config-reset: ## Resets the config/config.json file to the default.
   523  	@echo Resetting configuration to default
   524  	rm -f config/config.json
   525  	OUTPUT_CONFIG=$(PWD)/config/config.json $(GO) generate $(GOFLAGS) ./config
   526  
   527  diff-config: ## Compares default configuration between two mattermost versions
   528  	@./scripts/diff-config.sh
   529  
   530  clean: stop-docker ## Clean up everything except persistant server data.
   531  	@echo Cleaning
   532  
   533  	rm -Rf $(DIST_ROOT)
   534  	$(GO) clean $(GOFLAGS) -i ./...
   535  
   536  	cd $(BUILD_WEBAPP_DIR) && $(MAKE) clean
   537  
   538  	find . -type d -name data -not -path './vendor/*' | xargs rm -rf
   539  	rm -rf logs
   540  
   541  	rm -f mattermost.log
   542  	rm -f mattermost.log.jsonl
   543  	rm -f npm-debug.log
   544  	rm -f .prepare-go
   545  	rm -f enterprise
   546  	rm -f cover.out
   547  	rm -f ecover.out
   548  	rm -f *.out
   549  	rm -f *.test
   550  	rm -f imports/imports.go
   551  	rm -f cmd/platform/cprofile*.out
   552  	rm -f cmd/mattermost/cprofile*.out
   553  
   554  nuke: clean clean-docker ## Clean plus removes persistent server data.
   555  	@echo BOOM
   556  
   557  	rm -rf data
   558  
   559  setup-mac: ## Adds macOS hosts entries for Docker.
   560  	echo $$(boot2docker ip 2> /dev/null) dockerhost | sudo tee -a /etc/hosts
   561  
   562  update-dependencies: ## Uses go get -u to update all the dependencies while holding back any that require it.
   563  	@echo Updating Dependencies
   564  
   565  	# Update all dependencies (does not update across major versions)
   566  	$(GO) get -u ./...
   567  
   568  	# Copy everything to vendor directory
   569  	$(GO) mod vendor
   570  
   571  	# Tidy up
   572  	$(GO) mod tidy
   573  
   574  vet: ## Run mattermost go vet specific checks
   575  	@if ! [ -x "$$(command -v $(GOBIN)/mattermost-govet)" ]; then \
   576  		echo "mattermost-govet is not installed. Please install it executing \"GO111MODULE=off GOBIN=$(PWD)/bin go get -u github.com/mattermost/mattermost-govet\""; \
   577  		exit 1; \
   578  	fi;
   579  	@VET_CMD="-license -structuredLogging -inconsistentReceiverName -inconsistentReceiverName.ignore=session_serial_gen.go,team_member_serial_gen.go,user_serial_gen.go -emptyStrCmp -tFatal -configtelemetry"; \
   580  	if ! [ -z "${MM_VET_OPENSPEC_PATH}" ] && [ -f "${MM_VET_OPENSPEC_PATH}" ]; then \
   581  		VET_CMD="$$VET_CMD -openApiSync -openApiSync.spec=$$MM_VET_OPENSPEC_PATH"; \
   582  	else \
   583  		echo "MM_VET_OPENSPEC_PATH not set or spec yaml path in it is incorrect. Skipping API check"; \
   584  	fi; \
   585  	$(GO) vet -vettool=$(GOBIN)/mattermost-govet $$VET_CMD ./...
   586  ifeq ($(BUILD_ENTERPRISE_READY),true)
   587  ifneq ($(MM_NO_ENTERPRISE_LINT),true)
   588  	$(GO) vet -vettool=$(GOBIN)/mattermost-govet -enterpriseLicense -structuredLogging -tFatal ./enterprise/...
   589  endif
   590  endif
   591  
   592  gen-serialized: ## Generates serialization methods for hot structs
   593  	# This tool only works at a file level, not at a package level.
   594  	# There will be some warnings about "unresolved identifiers",
   595  	# but that is because of the above problem. Since we are generating
   596  	# methods for all the relevant files at a package level, all
   597  	# identifiers will be resolved. An alternative to remove the warnings
   598  	# would be to temporarily move all the structs to the same file,
   599  	# but that involves a lot of manual work.
   600  	$(GO) get -modfile=go.tools.mod github.com/tinylib/msgp
   601  	$(GOBIN)/msgp -file=./model/session.go -tests=false -o=./model/session_serial_gen.go
   602  	$(GOBIN)/msgp -file=./model/user.go -tests=false -o=./model/user_serial_gen.go
   603  	$(GOBIN)/msgp -file=./model/team_member.go -tests=false -o=./model/team_member_serial_gen.go
   604  
   605  todo: ## Display TODO and FIXME items in the source code.
   606  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime TODO
   607  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime XXX
   608  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime FIXME
   609  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime "FIX ME"
   610  ifeq ($(BUILD_ENTERPRISE_READY),true)
   611  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime TODO enterprise/
   612  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime XXX enterprise/
   613  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime FIXME enterprise/
   614  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime "FIX ME" enterprise/
   615  endif
   616  
   617  ## Help documentatin à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
   618  help:
   619  	@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' ./Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
   620  	@echo
   621  	@echo You can modify the default settings for this Makefile creating a file config.mk based on the default-config.mk
   622  	@echo