github.com/keys-pub/mattermost-server@v4.10.10+incompatible/Makefile (about)

     1  .PHONY: build package run stop run-client run-server stop-client stop-server restart restart-server restart-client start-docker clean-dist clean nuke check-style check-client-style check-server-style check-unit-tests test dist setup-mac 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
     2  
     3  ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
     4  
     5  # Build Flags
     6  BUILD_NUMBER ?= $(BUILD_NUMBER:)
     7  BUILD_DATE = $(shell date -u)
     8  BUILD_HASH = $(shell git rev-parse HEAD)
     9  # If we don't set the build number it defaults to dev
    10  ifeq ($(BUILD_NUMBER),)
    11  	BUILD_NUMBER := dev
    12  endif
    13  BUILD_ENTERPRISE_DIR ?= ../enterprise
    14  BUILD_ENTERPRISE ?= true
    15  BUILD_ENTERPRISE_READY = false
    16  BUILD_TYPE_NAME = team
    17  BUILD_HASH_ENTERPRISE = none
    18  ifneq ($(wildcard $(BUILD_ENTERPRISE_DIR)/.),)
    19  	ifeq ($(BUILD_ENTERPRISE),true)
    20  		BUILD_ENTERPRISE_READY = true
    21  		BUILD_TYPE_NAME = enterprise
    22  		BUILD_HASH_ENTERPRISE = $(shell cd $(BUILD_ENTERPRISE_DIR) && git rev-parse HEAD)
    23  	else
    24  		BUILD_ENTERPRISE_READY = false
    25  		BUILD_TYPE_NAME = team
    26  	endif
    27  else
    28  	BUILD_ENTERPRISE_READY = false
    29  	BUILD_TYPE_NAME = team
    30  endif
    31  BUILD_WEBAPP_DIR ?= ../mattermost-webapp
    32  BUILD_CLIENT = false
    33  BUILD_HASH_CLIENT = independant
    34  ifneq ($(wildcard $(BUILD_WEBAPP_DIR)/.),)
    35  	ifeq ($(BUILD_CLIENT),true)
    36  		BUILD_CLIENT = true
    37  		BUILD_HASH_CLIENT = $(shell cd $(BUILD_WEBAPP_DIR) && git rev-parse HEAD)
    38  	else
    39  		BUILD_CLIENT = false
    40  	endif
    41  else
    42  	BUILD_CLIENT = false
    43  endif
    44  
    45  # Golang Flags
    46  GOPATH ?= $(GOPATH:):./vendor
    47  GOFLAGS ?= $(GOFLAGS:)
    48  GO=go
    49  GO_LINKER_FLAGS ?= -ldflags \
    50  				   "-X github.com/mattermost/mattermost-server/model.BuildNumber=$(BUILD_NUMBER)\
    51  				    -X 'github.com/mattermost/mattermost-server/model.BuildDate=$(BUILD_DATE)'\
    52  				    -X github.com/mattermost/mattermost-server/model.BuildHash=$(BUILD_HASH)\
    53  				    -X github.com/mattermost/mattermost-server/model.BuildHashEnterprise=$(BUILD_HASH_ENTERPRISE)\
    54  				    -X github.com/mattermost/mattermost-server/model.BuildEnterpriseReady=$(BUILD_ENTERPRISE_READY)"
    55  
    56  # GOOS/GOARCH of the build host, used to determine whether we're cross-compiling or not
    57  BUILDER_GOOS_GOARCH="$(shell $(GO) env GOOS)_$(shell $(GO) env GOARCH)"
    58  
    59  PLATFORM_FILES="./main.go"
    60  
    61  # Output paths
    62  DIST_ROOT=dist
    63  DIST_PATH=$(DIST_ROOT)/mattermost
    64  
    65  # Tests
    66  TESTS=.
    67  
    68  TESTFLAGS ?= -short
    69  TESTFLAGSEE ?= -short
    70  
    71  # Packages lists
    72  TE_PACKAGES=$(shell go list ./...)
    73  TE_PACKAGES_COMMA=$(shell echo $(TE_PACKAGES) | tr ' ' ',')
    74  
    75  # Prepares the enterprise build if exists. The IGNORE stuff is a hack to get the Makefile to execute the commands outside a target
    76  ifeq ($(BUILD_ENTERPRISE_READY),true)
    77  	IGNORE:=$(shell echo Enterprise build selected, preparing)
    78  	IGNORE:=$(shell rm -f imports/imports.go)
    79  	IGNORE:=$(shell cp $(BUILD_ENTERPRISE_DIR)/imports/imports.go imports/)
    80  	IGNORE:=$(shell rm -f enterprise)
    81  	IGNORE:=$(shell ln -s $(BUILD_ENTERPRISE_DIR) enterprise)
    82  endif
    83  
    84  EE_PACKAGES=$(shell go list ./enterprise/...)
    85  EE_PACKAGES_COMMA=$(shell echo $(EE_PACKAGES) | tr ' ' ',')
    86  
    87  ifeq ($(BUILD_ENTERPRISE_READY),true)
    88  ALL_PACKAGES_COMMA=$(TE_PACKAGES_COMMA),$(EE_PACKAGES_COMMA)
    89  else
    90  ALL_PACKAGES_COMMA=$(TE_PACKAGES_COMMA)
    91  endif
    92  
    93  
    94  all: run ## Alias for 'run'.
    95  
    96  include build/*.mk
    97  
    98  start-docker: ## Starts the docker containers for local development.
    99  	@echo Starting docker containers
   100  
   101  	@if [ $(shell docker ps -a | grep -ci mattermost-mysql) -eq 0 ]; then \
   102  		echo starting mattermost-mysql; \
   103  		docker run --name mattermost-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=mostest \
   104  		-e MYSQL_USER=mmuser -e MYSQL_PASSWORD=mostest -e MYSQL_DATABASE=mattermost_test -d mysql:5.7 > /dev/null; \
   105  	elif [ $(shell docker ps | grep -ci mattermost-mysql) -eq 0 ]; then \
   106  		echo restarting mattermost-mysql; \
   107  		docker start mattermost-mysql > /dev/null; \
   108  	fi
   109  
   110  	@if [ $(shell docker ps -a | grep -ci mattermost-postgres) -eq 0 ]; then \
   111  		echo starting mattermost-postgres; \
   112  		docker run --name mattermost-postgres -p 5432:5432 -e POSTGRES_USER=mmuser -e POSTGRES_PASSWORD=mostest -e POSTGRES_DB=mattermost_test \
   113  		-d postgres:9.4 > /dev/null; \
   114  	elif [ $(shell docker ps | grep -ci mattermost-postgres) -eq 0 ]; then \
   115  		echo restarting mattermost-postgres; \
   116  		docker start mattermost-postgres > /dev/null; \
   117  	fi
   118  
   119  	@if [ $(shell docker ps -a | grep -ci mattermost-inbucket) -eq 0 ]; then \
   120  		echo starting mattermost-inbucket; \
   121  		docker run --name mattermost-inbucket -p 9000:10080 -p 2500:10025 -d jhillyerd/inbucket:release-1.2.0 > /dev/null; \
   122  	elif [ $(shell docker ps | grep -ci mattermost-inbucket) -eq 0 ]; then \
   123  		echo restarting mattermost-inbucket; \
   124  		docker start mattermost-inbucket > /dev/null; \
   125  	fi
   126  
   127  	@if [ $(shell docker ps -a | grep -ci mattermost-minio) -eq 0 ]; then \
   128  		echo starting mattermost-minio; \
   129  		docker run --name mattermost-minio -p 9001:9000 -e "MINIO_ACCESS_KEY=minioaccesskey" \
   130  		-e "MINIO_SECRET_KEY=miniosecretkey" -d minio/minio:latest server /data > /dev/null; \
   131  		docker exec -it mattermost-minio /bin/sh -c "mkdir -p /data/mattermost-test" > /dev/null; \
   132  	elif [ $(shell docker ps | grep -ci mattermost-minio) -eq 0 ]; then \
   133  		echo restarting mattermost-minio; \
   134  		docker start mattermost-minio > /dev/null; \
   135  	fi
   136  
   137  ifeq ($(BUILD_ENTERPRISE_READY),true)
   138  	@echo Ldap test user test.one
   139  	@if [ $(shell docker ps -a | grep -ci mattermost-openldap) -eq 0 ]; then \
   140  		echo starting mattermost-openldap; \
   141  		docker run --name mattermost-openldap -p 389:389 -p 636:636 \
   142  			-e LDAP_TLS_VERIFY_CLIENT="never" \
   143  			-e LDAP_ORGANISATION="Mattermost Test" \
   144  			-e LDAP_DOMAIN="mm.test.com" \
   145  			-e LDAP_ADMIN_PASSWORD="mostest" \
   146  			-d osixia/openldap:1.1.6 > /dev/null;\
   147  		sleep 10; \
   148  		docker exec -ti mattermost-openldap bash -c 'echo -e "dn: ou=testusers,dc=mm,dc=test,dc=com\nobjectclass: organizationalunit" | ldapadd -x -D "cn=admin,dc=mm,dc=test,dc=com" -w mostest';\
   149  		docker exec -ti mattermost-openldap bash -c 'echo -e "dn: uid=test.one,ou=testusers,dc=mm,dc=test,dc=com\nobjectclass: iNetOrgPerson\nsn: User\ncn: Test1\nmail: success+testone@simulator.amazonses.com" | ldapadd -x -D "cn=admin,dc=mm,dc=test,dc=com" -w mostest';\
   150  		docker exec -ti mattermost-openldap bash -c 'ldappasswd -s Password1 -D "cn=admin,dc=mm,dc=test,dc=com" -x "uid=test.one,ou=testusers,dc=mm,dc=test,dc=com" -w mostest';\
   151  		docker exec -ti mattermost-openldap bash -c 'echo -e "dn: uid=test.two,ou=testusers,dc=mm,dc=test,dc=com\nobjectclass: iNetOrgPerson\nsn: User\ncn: Test2\nmail: success+testtwo@simulator.amazonses.com" | ldapadd -x -D "cn=admin,dc=mm,dc=test,dc=com" -w mostest';\
   152  		docker exec -ti mattermost-openldap bash -c 'ldappasswd -s Password1 -D "cn=admin,dc=mm,dc=test,dc=com" -x "uid=test.two,ou=testusers,dc=mm,dc=test,dc=com" -w mostest';\
   153  		docker exec -ti mattermost-openldap bash -c 'echo -e "dn: cn=tgroup,ou=testusers,dc=mm,dc=test,dc=com\nobjectclass: groupOfUniqueNames\nuniqueMember: uid=test.one,ou=testusers,dc=mm,dc=test,dc=com" | ldapadd -x -D "cn=admin,dc=mm,dc=test,dc=com" -w mostest';\
   154  	elif [ $(shell docker ps | grep -ci mattermost-openldap) -eq 0 ]; then \
   155  		echo restarting mattermost-openldap; \
   156  		docker start mattermost-openldap > /dev/null; \
   157  		sleep 10; \
   158  	fi
   159  
   160  	@if [ $(shell docker ps -a | grep -ci mattermost-elasticsearch) -eq 0 ]; then \
   161  		echo starting mattermost-elasticsearch; \
   162  		docker run --name mattermost-elasticsearch -p 9200:9200 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" -e "ES_JAVA_OPTS=-Xms250m -Xmx250m" -d grundleborg/elasticsearch:latest > /dev/null; \
   163  	elif [ $(shell docker ps | grep -ci mattermost-elasticsearch) -eq 0 ]; then \
   164  		echo restarting mattermost-elasticsearch; \
   165  		docker start mattermost-elasticsearch> /dev/null; \
   166  	fi
   167  
   168  	@if [ $(shell docker ps -a | grep -ci mattermost-redis) -eq 0 ]; then \
   169  		echo starting mattermost-redis; \
   170  		docker run --name mattermost-redis -p 6379:6379 -d redis > /dev/null; \
   171  	elif [ $(shell docker ps | grep -ci mattermost-redis) -eq 0 ]; then \
   172  		echo restarting mattermost-redis; \
   173  		docker start mattermost-redis > /dev/null; \
   174  	fi
   175  endif
   176  
   177  stop-docker: ## Stops the docker containers for local development.
   178  	@echo Stopping docker containers
   179  
   180  	@if [ $(shell docker ps -a | grep -ci mattermost-mysql) -eq 1 ]; then \
   181  		echo stopping mattermost-mysql; \
   182  		docker stop mattermost-mysql > /dev/null; \
   183  	fi
   184  
   185  	@if [ $(shell docker ps -a | grep -ci mattermost-postgres) -eq 1 ]; then \
   186  		echo stopping mattermost-postgres; \
   187  		docker stop mattermost-postgres > /dev/null; \
   188  	fi
   189  
   190  	@if [ $(shell docker ps -a | grep -ci mattermost-openldap) -eq 1 ]; then \
   191  		echo stopping mattermost-openldap; \
   192  		docker stop mattermost-openldap > /dev/null; \
   193  	fi
   194  
   195  	@if [ $(shell docker ps -a | grep -ci mattermost-inbucket) -eq 1 ]; then \
   196  		echo stopping mattermost-inbucket; \
   197  		docker stop mattermost-inbucket > /dev/null; \
   198  	fi
   199  
   200  		@if [ $(shell docker ps -a | grep -ci mattermost-minio) -eq 1 ]; then \
   201      		echo stopping mattermost-minio; \
   202      		docker stop mattermost-minio > /dev/null; \
   203      	fi
   204  
   205  	@if [ $(shell docker ps -a | grep -ci mattermost-elasticsearch) -eq 1 ]; then \
   206  		echo stopping mattermost-elasticsearch; \
   207  		docker stop mattermost-elasticsearch > /dev/null; \
   208  	fi
   209  
   210  clean-docker: ## Deletes the docker containers for local development.
   211  	@echo Removing docker containers
   212  
   213  	@if [ $(shell docker ps -a | grep -ci mattermost-mysql) -eq 1 ]; then \
   214  		echo removing mattermost-mysql; \
   215  		docker stop mattermost-mysql > /dev/null; \
   216  		docker rm -v mattermost-mysql > /dev/null; \
   217  	fi
   218  
   219  	@if [ $(shell docker ps -a | grep -ci mattermost-postgres) -eq 1 ]; then \
   220  		echo removing mattermost-postgres; \
   221  		docker stop mattermost-postgres > /dev/null; \
   222  		docker rm -v mattermost-postgres > /dev/null; \
   223  	fi
   224  
   225  	@if [ $(shell docker ps -a | grep -ci mattermost-openldap) -eq 1 ]; then \
   226  		echo removing mattermost-openldap; \
   227  		docker stop mattermost-openldap > /dev/null; \
   228  		docker rm -v mattermost-openldap > /dev/null; \
   229  	fi
   230  
   231  	@if [ $(shell docker ps -a | grep -ci mattermost-inbucket) -eq 1 ]; then \
   232  		echo removing mattermost-inbucket; \
   233  		docker stop mattermost-inbucket > /dev/null; \
   234  		docker rm -v mattermost-inbucket > /dev/null; \
   235  	fi
   236  
   237  	@if [ $(shell docker ps -a | grep -ci mattermost-minio) -eq 1 ]; then \
   238  		echo removing mattermost-minio; \
   239  		docker stop mattermost-minio > /dev/null; \
   240  		docker rm -v mattermost-minio > /dev/null; \
   241  	fi
   242  
   243  	@if [ $(shell docker ps -a | grep -ci mattermost-elasticsearch) -eq 1 ]; then \
   244  		echo removing mattermost-elasticsearch; \
   245  		docker stop mattermost-elasticsearch > /dev/null; \
   246  		docker rm -v mattermost-elasticsearch > /dev/null; \
   247  	fi
   248  
   249  govet: ## Runs govet against all packages.
   250  	@echo Running GOVET
   251  	$(GO) vet $(GOFLAGS) $(TE_PACKAGES) || exit 1
   252  
   253  ifeq ($(BUILD_ENTERPRISE_READY),true)
   254  	$(GO) vet $(GOFLAGS) $(EE_PACKAGES) || exit 1
   255  endif
   256  
   257  gofmt: ## Runs gofmt against all packages.
   258  	@echo Running GOFMT
   259  
   260  	@for package in $(TE_PACKAGES) $(EE_PACKAGES); do \
   261  		echo "Checking "$$package; \
   262  		files=$$(go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}} {{end}}' $$package); \
   263  		if [ "$$files" ]; then \
   264  			gofmt_output=$$(gofmt -d -s $$files 2>&1); \
   265  			if [ "$$gofmt_output" ]; then \
   266  				echo "$$gofmt_output"; \
   267  				echo "gofmt failure"; \
   268  				exit 1; \
   269  			fi; \
   270  		fi; \
   271  	done
   272  	@echo "gofmt success"; \
   273  
   274  store-mocks: ## Creates mock files.
   275  	go get github.com/vektra/mockery/...
   276  	GOPATH=$(shell go env GOPATH) $(shell go env GOPATH)/bin/mockery -dir store -all -output store/storetest/mocks -note 'Regenerate this file using `make store-mocks`.'
   277  
   278  update-jira-plugin: ## Updates Jira plugin.
   279  	go get github.com/mattermost/go-bindata/...
   280  	curl -s https://api.github.com/repos/mattermost/mattermost-plugin-jira/releases/latest | grep browser_download_url | grep darwin-amd64 | cut -d '"' -f 4 | wget -qi - -O plugin.tar.gz
   281  	$(shell go env GOPATH)/bin/go-bindata -pkg jira -o app/plugin/jira/plugin_darwin_amd64.go plugin.tar.gz
   282  	curl -s https://api.github.com/repos/mattermost/mattermost-plugin-jira/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi - -O plugin.tar.gz
   283  	$(shell go env GOPATH)/bin/go-bindata -pkg jira -o app/plugin/jira/plugin_linux_amd64.go plugin.tar.gz
   284  	curl -s https://api.github.com/repos/mattermost/mattermost-plugin-jira/releases/latest | grep browser_download_url | grep windows-amd64 | cut -d '"' -f 4 | wget -qi - -O plugin.tar.gz
   285  	$(shell go env GOPATH)/bin/go-bindata -pkg jira -o app/plugin/jira/plugin_windows_amd64.go plugin.tar.gz
   286  	rm plugin.tar.gz
   287  	gofmt -s -w ./app/plugin/jira
   288  
   289  update-zoom-plugin: ## Updates Zoom plugin.
   290  	go get github.com/mattermost/go-bindata/...
   291  	curl -s https://api.github.com/repos/mattermost/mattermost-plugin-zoom/releases/latest | grep browser_download_url | grep darwin-amd64 | cut -d '"' -f 4 | wget -qi - -O plugin.tar.gz
   292  	$(shell go env GOPATH)/bin/go-bindata -pkg zoom -o app/plugin/zoom/plugin_darwin_amd64.go plugin.tar.gz
   293  	curl -s https://api.github.com/repos/mattermost/mattermost-plugin-zoom/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi - -O plugin.tar.gz
   294  	$(shell go env GOPATH)/bin/go-bindata -pkg zoom -o app/plugin/zoom/plugin_linux_amd64.go plugin.tar.gz
   295  	curl -s https://api.github.com/repos/mattermost/mattermost-plugin-zoom/releases/latest | grep browser_download_url | grep windows-amd64 | cut -d '"' -f 4 | wget -qi - -O plugin.tar.gz
   296  	$(shell go env GOPATH)/bin/go-bindata -pkg zoom -o app/plugin/zoom/plugin_windows_amd64.go plugin.tar.gz
   297  	rm plugin.tar.gz
   298  	gofmt -s -w ./app/plugin/zoom
   299  
   300  check-licenses: ## Checks license status.
   301  	./scripts/license-check.sh $(TE_PACKAGES) $(EE_PACKAGES)
   302  
   303  check-prereqs: ## Checks prerequisite software status.
   304  	./scripts/prereq-check.sh
   305  	
   306  check-style: govet gofmt check-licenses ## Runs govet and gofmt against all packages.
   307  
   308  test-te-race: ## Checks for race conditions in the team edition.
   309  	@echo Testing TE race conditions
   310  
   311  	@echo "Packages to test: "$(TE_PACKAGES)
   312  
   313  	@for package in $(TE_PACKAGES); do \
   314  		echo "Testing "$$package; \
   315  		$(GO) test $(GOFLAGS) -race -run=$(TESTS) -test.timeout=4000s $$package || exit 1; \
   316  	done
   317  
   318  test-ee-race: ## Checks for race conditions in the enterprise edition.
   319  	@echo Testing EE race conditions
   320  
   321  ifeq ($(BUILD_ENTERPRISE_READY),true)
   322  	@echo "Packages to test: "$(EE_PACKAGES)
   323  
   324  	for package in $(EE_PACKAGES); do \
   325  		echo "Testing "$$package; \
   326  		$(GO) test $(GOFLAGS) -race -run=$(TESTS) -c $$package; \
   327  		if [ -f $$(basename $$package).test ]; then \
   328  			echo "Testing "$$package; \
   329  			./$$(basename $$package).test -test.timeout=2000s || exit 1; \
   330  			rm -r $$(basename $$package).test; \
   331  		fi; \
   332  	done
   333  
   334  	rm -f config/*.crt
   335  	rm -f config/*.key
   336  endif
   337  
   338  test-server-race: test-te-race test-ee-race ## Checks for race conditions.
   339  	find . -type d -name data -not -path './vendor/*' | xargs rm -rf
   340  
   341  do-cover-file: ## Creates the test coverage report file.
   342  	@echo "mode: count" > cover.out
   343  
   344  test-te: do-cover-file ## Runs tests in the team edition.
   345  	@echo Testing TE
   346  	@echo "Packages to test: "$(TE_PACKAGES)
   347  	find . -name 'cprofile*.out' -exec sh -c 'rm "{}"' \;
   348  	$(GO) test $(GOFLAGS) -run=$(TESTS) $(TESTFLAGS) -v -timeout=2000s -covermode=count -coverpkg=$(ALL_PACKAGES_COMMA) -exec $(ROOT)/scripts/test-xprog.sh $(TE_PACKAGES)
   349  	find . -name 'cprofile*.out' -exec sh -c 'tail -n +2 {} >> cover.out ; rm "{}"' \;
   350  
   351  test-ee: do-cover-file ## Runs tests in the enterprise edition.
   352  	@echo Testing EE
   353  
   354  ifeq ($(BUILD_ENTERPRISE_READY),true)
   355  	@echo "Packages to test: "$(EE_PACKAGES)
   356  	find . -name 'cprofile*.out' -exec sh -c 'rm "{}"' \;
   357  	$(GO) test $(GOFLAGS) -run=$(TESTS) $(TESTFLAGSEE) -p 1 -v -timeout=2000s -covermode=count -coverpkg=$(ALL_PACKAGES_COMMA) -exec $(ROOT)/scripts/test-xprog.sh $(EE_PACKAGES)
   358  	find . -name 'cprofile*.out' -exec sh -c 'tail -n +2 {} >> cover.out ; rm "{}"' \;
   359  	rm -f config/*.crt
   360  	rm -f config/*.key
   361  endif
   362  
   363  test-server: test-te test-ee ## Runs tests.
   364  	find . -type d -name data -not -path './vendor/*' | xargs rm -rf
   365  
   366  internal-test-web-client: ## Runs web client tests.
   367  	$(GO) run $(GOFLAGS) $(PLATFORM_FILES) test web_client_tests
   368  
   369  run-server-for-web-client-tests: ## Tests the server for web client.
   370  	$(GO) run $(GOFLAGS) $(PLATFORM_FILES) test web_client_tests_server
   371  
   372  test-client: ## Test client app.
   373  	@echo Running client tests
   374  
   375  	cd $(BUILD_WEBAPP_DIR) && $(MAKE) test
   376  
   377  test: test-server test-client ## Runs all checks and tests below (except race detection and postgres).
   378  
   379  cover: ## Runs the golang coverage tool. You must run the unit tests first.
   380  	@echo Opening coverage info in browser. If this failed run make test first
   381  
   382  	$(GO) tool cover -html=cover.out
   383  	$(GO) tool cover -html=ecover.out
   384  
   385  test-data: start-docker ## Add test data to the local instance.
   386  	$(GO) run $(GOFLAGS) $(GO_LINKER_FLAGS) $(PLATFORM_FILES) sampledata -w 1
   387  
   388  	@echo You may need to restart the Mattermost server before using the following
   389  	@echo ========================================================================
   390  	@echo Login with a system admin account username=sysadmin password=sysadmin
   391  	@echo Login with a regular account username=user-1 password=user-1
   392  	@echo ========================================================================
   393  
   394  run-server: start-docker ## Starts the server.
   395  	@echo Running mattermost for development
   396  
   397  	mkdir -p $(BUILD_WEBAPP_DIR)/dist/files
   398  	$(GO) run $(GOFLAGS) $(GO_LINKER_FLAGS) $(PLATFORM_FILES) --disableconfigwatch &
   399  
   400  run-cli: start-docker ## Runs CLI.
   401  	@echo Running mattermost for development
   402  	@echo Example should be like 'make ARGS="-version" run-cli'
   403  
   404  	$(GO) run $(GOFLAGS) $(GO_LINKER_FLAGS) $(PLATFORM_FILES) ${ARGS}
   405  
   406  run-client: ## Runs the webapp.
   407  	@echo Running mattermost client for development
   408  
   409  	ln -nfs $(BUILD_WEBAPP_DIR)/dist client
   410  	cd $(BUILD_WEBAPP_DIR) && $(MAKE) run
   411  
   412  run-client-fullmap: ## Runs the webapp with source code mapping (slower; better debugging).
   413  	@echo Running mattermost client for development with FULL SOURCE MAP
   414  
   415  	cd $(BUILD_WEBAPP_DIR) && $(MAKE) run-fullmap
   416  
   417  run: check-prereqs run-server run-client ## Runs the server and webapp.
   418  
   419  run-fullmap: run-server run-client-fullmap ## Same as run but with a full sourcemap for client.
   420  
   421  stop-server: ## Stops the server.
   422  	@echo Stopping mattermost
   423  
   424  ifeq ($(BUILDER_GOOS_GOARCH),"windows_amd64")
   425  	wmic process where "Caption='go.exe' and CommandLine like '%go.exe run%'" call terminate
   426  	wmic process where "Caption='mattermost.exe' and CommandLine like '%go-build%'" call terminate
   427  else
   428  	@for PID in $$(ps -ef | grep "[g]o run" | awk '{ print $$2 }'); do \
   429  		echo stopping go $$PID; \
   430  		kill $$PID; \
   431  	done
   432  	@for PID in $$(ps -ef | grep "[g]o-build" | awk '{ print $$2 }'); do \
   433  		echo stopping mattermost $$PID; \
   434  		kill $$PID; \
   435  	done
   436  endif
   437  
   438  stop-client: ## Stops the webapp.
   439  	@echo Stopping mattermost client
   440  
   441  	cd $(BUILD_WEBAPP_DIR) && $(MAKE) stop
   442  
   443  stop: stop-server stop-client ## Stops server and client.
   444  
   445  restart: restart-server restart-client ## Restarts the server and webapp.
   446  
   447  restart-server: | stop-server run-server ## Restarts the mattermost server to pick up development change.
   448  
   449  restart-client: | stop-client run-client ## Restarts the webapp.
   450  
   451  run-job-server: ## Runs the background job server.
   452  	@echo Running job server for development
   453  	$(GO) run $(GOFLAGS) $(GO_LINKER_FLAGS) $(PLATFORM_FILES) jobserver --disableconfigwatch &
   454  
   455  config-ldap: ## Configures LDAP.
   456  	@echo Setting up configuration for local LDAP
   457  
   458  	@sed -i'' -e 's|"LdapServer": ".*"|"LdapServer": "dockerhost"|g' config/config.json
   459  	@sed -i'' -e 's|"BaseDN": ".*"|"BaseDN": "ou=testusers,dc=mm,dc=test,dc=com"|g' config/config.json
   460  	@sed -i'' -e 's|"BindUsername": ".*"|"BindUsername": "cn=admin,dc=mm,dc=test,dc=com"|g' config/config.json
   461  	@sed -i'' -e 's|"BindPassword": ".*"|"BindPassword": "mostest"|g' config/config.json
   462  	@sed -i'' -e 's|"FirstNameAttribute": ".*"|"FirstNameAttribute": "cn"|g' config/config.json
   463  	@sed -i'' -e 's|"LastNameAttribute": ".*"|"LastNameAttribute": "sn"|g' config/config.json
   464  	@sed -i'' -e 's|"NicknameAttribute": ".*"|"NicknameAttribute": "cn"|g' config/config.json
   465  	@sed -i'' -e 's|"EmailAttribute": ".*"|"EmailAttribute": "mail"|g' config/config.json
   466  	@sed -i'' -e 's|"UsernameAttribute": ".*"|"UsernameAttribute": "uid"|g' config/config.json
   467  	@sed -i'' -e 's|"IdAttribute": ".*"|"IdAttribute": "uid"|g' config/config.json
   468  
   469  config-reset: ## Resets the config/config.json file to the default.
   470  	@echo Resetting configuration to default
   471  	rm -f config/config.json
   472  	cp config/default.json config/config.json
   473  
   474  clean: stop-docker ## Clean up everything except persistant server data.
   475  	@echo Cleaning
   476  
   477  	rm -Rf $(DIST_ROOT)
   478  	go clean $(GOFLAGS) -i ./...
   479  
   480  	cd $(BUILD_WEBAPP_DIR) && $(MAKE) clean
   481  
   482  	find . -type d -name data -not -path './vendor/*' | xargs rm -rf
   483  	rm -rf logs
   484  
   485  	rm -f mattermost.log
   486  	rm -f mattermost.log.jsonl
   487  	rm -f npm-debug.log
   488  	rm -f api/mattermost.log
   489  	rm -f api/mattermost.log.jsonl
   490  	rm -f .prepare-go
   491  	rm -f enterprise
   492  	rm -f cover.out
   493  	rm -f ecover.out
   494  	rm -f *.out
   495  	rm -f *.test
   496  	rm -f imports/imports.go
   497  	rm -f cmd/platform/cprofile*.out
   498  
   499  nuke: clean clean-docker ## Clean plus removes persistant server data.
   500  	@echo BOOM
   501  
   502  	rm -rf data
   503  
   504  setup-mac: ## Adds macOS hosts entries for Docker.
   505  	echo $$(boot2docker ip 2> /dev/null) dockerhost | sudo tee -a /etc/hosts
   506  
   507  
   508  todo: ## Display TODO and FIXME items in the source code.
   509  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime TODO
   510  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime XXX
   511  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime FIXME
   512  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime "FIX ME"
   513  ifeq ($(BUILD_ENTERPRISE_READY),true)
   514  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime TODO enterprise/
   515  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime XXX enterprise/
   516  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime FIXME enterprise/
   517  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime "FIX ME" enterprise/
   518  endif
   519  
   520  ## Help documentatin à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
   521  help:
   522  	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' ./Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'