github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+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 ?= $(shell go env GOPATH)
    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)/bin/mockery -dir store -all -output store/storetest/mocks -note 'Regenerate this file using `make store-mocks`.'
   277  
   278  ldap-mocks: ## Creates mock files for ldap.
   279  	go get github.com/vektra/mockery/...
   280  	GOPATH=$(shell go env GOPATH) $(shell go env GOPATH)/bin/mockery -dir enterprise/ldap -all -output enterprise/ldap/mocks -note 'Regenerate this file using `make ldap-mocks`.'
   281  
   282  update-jira-plugin: ## Updates Jira plugin.
   283  	go get github.com/mattermost/go-bindata/...
   284  	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
   285  	$(shell go env GOPATH)/bin/go-bindata -pkg jira -o app/plugin/jira/plugin_darwin_amd64.go plugin.tar.gz
   286  	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
   287  	$(shell go env GOPATH)/bin/go-bindata -pkg jira -o app/plugin/jira/plugin_linux_amd64.go plugin.tar.gz
   288  	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
   289  	$(shell go env GOPATH)/bin/go-bindata -pkg jira -o app/plugin/jira/plugin_windows_amd64.go plugin.tar.gz
   290  	rm plugin.tar.gz
   291  	gofmt -s -w ./app/plugin/jira
   292  
   293  update-zoom-plugin: ## Updates Zoom plugin.
   294  	go get github.com/mattermost/go-bindata/...
   295  	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
   296  	$(shell go env GOPATH)/bin/go-bindata -pkg zoom -o app/plugin/zoom/plugin_darwin_amd64.go plugin.tar.gz
   297  	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
   298  	$(shell go env GOPATH)/bin/go-bindata -pkg zoom -o app/plugin/zoom/plugin_linux_amd64.go plugin.tar.gz
   299  	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
   300  	$(shell go env GOPATH)/bin/go-bindata -pkg zoom -o app/plugin/zoom/plugin_windows_amd64.go plugin.tar.gz
   301  	rm plugin.tar.gz
   302  	gofmt -s -w ./app/plugin/zoom
   303  
   304  check-licenses: ## Checks license status.
   305  	./scripts/license-check.sh $(TE_PACKAGES) $(EE_PACKAGES)
   306  
   307  check-prereqs: ## Checks prerequisite software status.
   308  	./scripts/prereq-check.sh
   309  	
   310  check-style: govet gofmt check-licenses ## Runs govet and gofmt against all packages.
   311  
   312  test-te-race: ## Checks for race conditions in the team edition.
   313  	@echo Testing TE race conditions
   314  
   315  	@echo "Packages to test: "$(TE_PACKAGES)
   316  
   317  	@for package in $(TE_PACKAGES); do \
   318  		echo "Testing "$$package; \
   319  		$(GO) test $(GOFLAGS) -race -run=$(TESTS) -test.timeout=4000s $$package || exit 1; \
   320  	done
   321  
   322  test-ee-race: ## Checks for race conditions in the enterprise edition.
   323  	@echo Testing EE race conditions
   324  
   325  ifeq ($(BUILD_ENTERPRISE_READY),true)
   326  	@echo "Packages to test: "$(EE_PACKAGES)
   327  
   328  	for package in $(EE_PACKAGES); do \
   329  		echo "Testing "$$package; \
   330  		$(GO) test $(GOFLAGS) -race -run=$(TESTS) -c $$package; \
   331  		if [ -f $$(basename $$package).test ]; then \
   332  			echo "Testing "$$package; \
   333  			./$$(basename $$package).test -test.timeout=2000s || exit 1; \
   334  			rm -r $$(basename $$package).test; \
   335  		fi; \
   336  	done
   337  
   338  	rm -f config/*.crt
   339  	rm -f config/*.key
   340  endif
   341  
   342  test-server-race: test-te-race test-ee-race ## Checks for race conditions.
   343  	find . -type d -name data -not -path './vendor/*' | xargs rm -rf
   344  
   345  do-cover-file: ## Creates the test coverage report file.
   346  	@echo "mode: count" > cover.out
   347  
   348  test-te: do-cover-file ## Runs tests in the team edition.
   349  	@echo Testing TE
   350  	@echo "Packages to test: "$(TE_PACKAGES)
   351  	find . -name 'cprofile*.out' -exec sh -c 'rm "{}"' \;
   352  	$(GO) test $(GOFLAGS) -run=$(TESTS) $(TESTFLAGS) -v -timeout=2000s -covermode=count -coverpkg=$(ALL_PACKAGES_COMMA) -exec $(ROOT)/scripts/test-xprog.sh $(TE_PACKAGES)
   353  	find . -name 'cprofile*.out' -exec sh -c 'tail -n +2 {} >> cover.out ; rm "{}"' \;
   354  
   355  test-ee: do-cover-file ## Runs tests in the enterprise edition.
   356  	@echo Testing EE
   357  
   358  ifeq ($(BUILD_ENTERPRISE_READY),true)
   359  	@echo "Packages to test: "$(EE_PACKAGES)
   360  	find . -name 'cprofile*.out' -exec sh -c 'rm "{}"' \;
   361  	$(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)
   362  	find . -name 'cprofile*.out' -exec sh -c 'tail -n +2 {} >> cover.out ; rm "{}"' \;
   363  	rm -f config/*.crt
   364  	rm -f config/*.key
   365  endif
   366  
   367  test-server: test-te test-ee ## Runs tests.
   368  	find . -type d -name data -not -path './vendor/*' | xargs rm -rf
   369  
   370  internal-test-web-client: ## Runs web client tests.
   371  	$(GO) run $(GOFLAGS) $(PLATFORM_FILES) test web_client_tests
   372  
   373  run-server-for-web-client-tests: ## Tests the server for web client.
   374  	$(GO) run $(GOFLAGS) $(PLATFORM_FILES) test web_client_tests_server
   375  
   376  test-client: ## Test client app.
   377  	@echo Running client tests
   378  
   379  	cd $(BUILD_WEBAPP_DIR) && $(MAKE) test
   380  
   381  test: test-server test-client ## Runs all checks and tests below (except race detection and postgres).
   382  
   383  cover: ## Runs the golang coverage tool. You must run the unit tests first.
   384  	@echo Opening coverage info in browser. If this failed run make test first
   385  
   386  	$(GO) tool cover -html=cover.out
   387  	$(GO) tool cover -html=ecover.out
   388  
   389  test-data: start-docker ## Add test data to the local instance.
   390  	$(GO) run $(GOFLAGS) $(GO_LINKER_FLAGS) $(PLATFORM_FILES) sampledata -w 1
   391  
   392  	@echo You may need to restart the Mattermost server before using the following
   393  	@echo ========================================================================
   394  	@echo Login with a system admin account username=sysadmin password=sysadmin
   395  	@echo Login with a regular account username=user-1 password=user-1
   396  	@echo ========================================================================
   397  
   398  run-server: start-docker ## Starts the server.
   399  	@echo Running mattermost for development
   400  
   401  	mkdir -p $(BUILD_WEBAPP_DIR)/dist/files
   402  	$(GO) run $(GOFLAGS) $(GO_LINKER_FLAGS) $(PLATFORM_FILES) --disableconfigwatch &
   403  
   404  run-cli: start-docker ## Runs CLI.
   405  	@echo Running mattermost for development
   406  	@echo Example should be like 'make ARGS="-version" run-cli'
   407  
   408  	$(GO) run $(GOFLAGS) $(GO_LINKER_FLAGS) $(PLATFORM_FILES) ${ARGS}
   409  
   410  run-client: ## Runs the webapp.
   411  	@echo Running mattermost client for development
   412  
   413  	ln -nfs $(BUILD_WEBAPP_DIR)/dist client
   414  	cd $(BUILD_WEBAPP_DIR) && $(MAKE) run
   415  
   416  run-client-fullmap: ## Runs the webapp with source code mapping (slower; better debugging).
   417  	@echo Running mattermost client for development with FULL SOURCE MAP
   418  
   419  	cd $(BUILD_WEBAPP_DIR) && $(MAKE) run-fullmap
   420  
   421  run: check-prereqs run-server run-client ## Runs the server and webapp.
   422  
   423  run-fullmap: run-server run-client-fullmap ## Same as run but with a full sourcemap for client.
   424  
   425  stop-server: ## Stops the server.
   426  	@echo Stopping mattermost
   427  
   428  ifeq ($(BUILDER_GOOS_GOARCH),"windows_amd64")
   429  	wmic process where "Caption='go.exe' and CommandLine like '%go.exe run%'" call terminate
   430  	wmic process where "Caption='mattermost.exe' and CommandLine like '%go-build%'" call terminate
   431  else
   432  	@for PID in $$(ps -ef | grep "[g]o run" | awk '{ print $$2 }'); do \
   433  		echo stopping go $$PID; \
   434  		kill $$PID; \
   435  	done
   436  	@for PID in $$(ps -ef | grep "[g]o-build" | awk '{ print $$2 }'); do \
   437  		echo stopping mattermost $$PID; \
   438  		kill $$PID; \
   439  	done
   440  endif
   441  
   442  stop-client: ## Stops the webapp.
   443  	@echo Stopping mattermost client
   444  
   445  	cd $(BUILD_WEBAPP_DIR) && $(MAKE) stop
   446  
   447  stop: stop-server stop-client ## Stops server and client.
   448  
   449  restart: restart-server restart-client ## Restarts the server and webapp.
   450  
   451  restart-server: | stop-server run-server ## Restarts the mattermost server to pick up development change.
   452  
   453  restart-client: | stop-client run-client ## Restarts the webapp.
   454  
   455  run-job-server: ## Runs the background job server.
   456  	@echo Running job server for development
   457  	$(GO) run $(GOFLAGS) $(GO_LINKER_FLAGS) $(PLATFORM_FILES) jobserver --disableconfigwatch &
   458  
   459  config-ldap: ## Configures LDAP.
   460  	@echo Setting up configuration for local LDAP
   461  
   462  	@sed -i'' -e 's|"LdapServer": ".*"|"LdapServer": "dockerhost"|g' config/config.json
   463  	@sed -i'' -e 's|"BaseDN": ".*"|"BaseDN": "ou=testusers,dc=mm,dc=test,dc=com"|g' config/config.json
   464  	@sed -i'' -e 's|"BindUsername": ".*"|"BindUsername": "cn=admin,dc=mm,dc=test,dc=com"|g' config/config.json
   465  	@sed -i'' -e 's|"BindPassword": ".*"|"BindPassword": "mostest"|g' config/config.json
   466  	@sed -i'' -e 's|"FirstNameAttribute": ".*"|"FirstNameAttribute": "cn"|g' config/config.json
   467  	@sed -i'' -e 's|"LastNameAttribute": ".*"|"LastNameAttribute": "sn"|g' config/config.json
   468  	@sed -i'' -e 's|"NicknameAttribute": ".*"|"NicknameAttribute": "cn"|g' config/config.json
   469  	@sed -i'' -e 's|"EmailAttribute": ".*"|"EmailAttribute": "mail"|g' config/config.json
   470  	@sed -i'' -e 's|"UsernameAttribute": ".*"|"UsernameAttribute": "uid"|g' config/config.json
   471  	@sed -i'' -e 's|"IdAttribute": ".*"|"IdAttribute": "uid"|g' config/config.json
   472  
   473  config-reset: ## Resets the config/config.json file to the default.
   474  	@echo Resetting configuration to default
   475  	rm -f config/config.json
   476  	cp config/default.json config/config.json
   477  
   478  clean: stop-docker ## Clean up everything except persistant server data.
   479  	@echo Cleaning
   480  
   481  	rm -Rf $(DIST_ROOT)
   482  	go clean $(GOFLAGS) -i ./...
   483  
   484  	cd $(BUILD_WEBAPP_DIR) && $(MAKE) clean
   485  
   486  	find . -type d -name data -not -path './vendor/*' | xargs rm -rf
   487  	rm -rf logs
   488  
   489  	rm -f mattermost.log
   490  	rm -f mattermost.log.jsonl
   491  	rm -f npm-debug.log
   492  	rm -f api/mattermost.log
   493  	rm -f api/mattermost.log.jsonl
   494  	rm -f .prepare-go
   495  	rm -f enterprise
   496  	rm -f cover.out
   497  	rm -f ecover.out
   498  	rm -f *.out
   499  	rm -f *.test
   500  	rm -f imports/imports.go
   501  	rm -f cmd/platform/cprofile*.out
   502  
   503  nuke: clean clean-docker ## Clean plus removes persistant server data.
   504  	@echo BOOM
   505  
   506  	rm -rf data
   507  
   508  setup-mac: ## Adds macOS hosts entries for Docker.
   509  	echo $$(boot2docker ip 2> /dev/null) dockerhost | sudo tee -a /etc/hosts
   510  
   511  
   512  todo: ## Display TODO and FIXME items in the source code.
   513  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime TODO
   514  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime XXX
   515  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime FIXME
   516  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime "FIX ME"
   517  ifeq ($(BUILD_ENTERPRISE_READY),true)
   518  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime TODO enterprise/
   519  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime XXX enterprise/
   520  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime FIXME enterprise/
   521  	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime "FIX ME" enterprise/
   522  endif
   523  
   524  ## Help documentatin à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
   525  help:
   526  	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' ./Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'