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