Makefile 21.7 KB
Newer Older
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 package-common package-linux package-osx package-windows internal-test-web-client vet run-server-for-web-client-tests
=Corey Hulen's avatar
=Corey Hulen committed
2

3 4
ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

5
# Build Flags
=Corey Hulen's avatar
=Corey Hulen committed
6
BUILD_NUMBER ?= $(BUILD_NUMBER:)
=Corey Hulen's avatar
=Corey Hulen committed
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
=Corey Hulen's avatar
=Corey Hulen committed
10 11 12
ifeq ($(BUILD_NUMBER),)
	BUILD_NUMBER := dev
endif
13 14 15
BUILD_ENTERPRISE_DIR ?= ../enterprise
BUILD_ENTERPRISE ?= true
BUILD_ENTERPRISE_READY = false
16
BUILD_TYPE_NAME = team
17
BUILD_HASH_ENTERPRISE = none
18 19 20
ifneq ($(wildcard $(BUILD_ENTERPRISE_DIR)/.),)
	ifeq ($(BUILD_ENTERPRISE),true)
		BUILD_ENTERPRISE_READY = true
21
		BUILD_TYPE_NAME = enterprise
22
		BUILD_HASH_ENTERPRISE = $(shell cd $(BUILD_ENTERPRISE_DIR) && git rev-parse HEAD)
23 24
	else
		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
Christopher Speller's avatar
Christopher Speller committed
31
BUILD_WEBAPP_DIR ?= ../mattermost-webapp
32 33 34 35 36 37 38 39 40 41 42 43
BUILD_CLIENT = false
BUILD_HASH_CLIENT = independant
ifneq ($(wildcard $(BUILD_WEBAPP_DIR)/.),)
	ifeq ($(BUILD_CLIENT),true)
		BUILD_CLIENT = true
		BUILD_HASH_CLIENT = $(shell cd $(BUILD_WEBAPP_DIR) && git rev-parse HEAD)
	else
		BUILD_CLIENT = false
	endif
else
	BUILD_CLIENT = false
endif
44

45
# Golang Flags
Christopher Speller's avatar
Christopher Speller committed
46
GOPATH ?= $(GOPATH:):./vendor
47
GOFLAGS ?= $(GOFLAGS:)
Christopher Speller's avatar
Christopher Speller committed
48
GO=go
49
GO_LINKER_FLAGS ?= -ldflags \
50 51 52 53 54
				   "-X github.com/mattermost/mattermost-server/model.BuildNumber=$(BUILD_NUMBER)\
				    -X 'github.com/mattermost/mattermost-server/model.BuildDate=$(BUILD_DATE)'\
				    -X github.com/mattermost/mattermost-server/model.BuildHash=$(BUILD_HASH)\
				    -X github.com/mattermost/mattermost-server/model.BuildHashEnterprise=$(BUILD_HASH_ENTERPRISE)\
				    -X github.com/mattermost/mattermost-server/model.BuildEnterpriseReady=$(BUILD_ENTERPRISE_READY)"
55

56 57 58
# GOOS/GOARCH of the build host, used to determine whether we're cross-compiling or not
BUILDER_GOOS_GOARCH="$(shell $(GO) env GOOS)_$(shell $(GO) env GOARCH)"

59 60
PLATFORM_FILES=$(shell ls -1 ./cmd/platform/*.go | grep -v _test.go)

61
# Output paths
=Corey Hulen's avatar
=Corey Hulen committed
62 63 64
DIST_ROOT=dist
DIST_PATH=$(DIST_ROOT)/mattermost

65
# Tests
=Corey Hulen's avatar
=Corey Hulen committed
66 67
TESTS=.

68
TESTFLAGS ?= -short
69
TESTFLAGSEE ?= -short
70

71
# Packages lists
Chris's avatar
Chris committed
72
TE_PACKAGES=$(shell go list ./...)
73 74
TE_PACKAGES_COMMA=$(shell echo $(TE_PACKAGES) | tr ' ' ',')

75 76 77
# Prepares the enterprise build if exists. The IGNORE stuff is a hack to get the Makefile to execute the commands outside a target
ifeq ($(BUILD_ENTERPRISE_READY),true)
	IGNORE:=$(shell echo Enterprise build selected, preparing)
78
	IGNORE:=$(shell rm -f imports/imports.go)
79 80 81 82 83
	IGNORE:=$(shell cp $(BUILD_ENTERPRISE_DIR)/imports/imports.go imports/)
	IGNORE:=$(shell rm -f enterprise)
	IGNORE:=$(shell ln -s $(BUILD_ENTERPRISE_DIR) enterprise)
endif

Chris's avatar
Chris committed
84 85 86 87 88 89 90 91 92
EE_PACKAGES=$(shell go list ./enterprise/...)
EE_PACKAGES_COMMA=$(shell echo $(EE_PACKAGES) | tr ' ' ',')

ifeq ($(BUILD_ENTERPRISE_READY),true)
ALL_PACKAGES_COMMA=$(TE_PACKAGES_COMMA),$(EE_PACKAGES_COMMA)
else
ALL_PACKAGES_COMMA=$(TE_PACKAGES_COMMA)
endif

93

94
all: run ## Alias for 'run'.
95

96
include build/*.mk
97

98
start-docker: ## Starts the docker containers for local development.
99 100 101 102 103 104 105 106 107
	@echo Starting docker containers

	@if [ $(shell docker ps -a | grep -ci mattermost-mysql) -eq 0 ]; then \
		echo starting mattermost-mysql; \
		docker run --name mattermost-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=mostest \
		-e MYSQL_USER=mmuser -e MYSQL_PASSWORD=mostest -e MYSQL_DATABASE=mattermost_test -d mysql:5.7 > /dev/null; \
	elif [ $(shell docker ps | grep -ci mattermost-mysql) -eq 0 ]; then \
		echo restarting mattermost-mysql; \
		docker start mattermost-mysql > /dev/null; \
108 109
	fi

110 111
	@if [ $(shell docker ps -a | grep -ci mattermost-postgres) -eq 0 ]; then \
		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 114 115 116
		-d postgres:9.4 > /dev/null; \
	elif [ $(shell docker ps | grep -ci mattermost-postgres) -eq 0 ]; then \
		echo restarting mattermost-postgres; \
		docker start mattermost-postgres > /dev/null; \
117 118
	fi

119 120 121 122 123 124 125 126
	@if [ $(shell docker ps -a | grep -ci mattermost-inbucket) -eq 0 ]; then \
		echo starting mattermost-inbucket; \
		docker run --name mattermost-inbucket -p 9000:10080 -p 2500:10025 -d jhillyerd/inbucket:latest > /dev/null; \
	elif [ $(shell docker ps | grep -ci mattermost-inbucket) -eq 0 ]; then \
		echo restarting mattermost-inbucket; \
		docker start mattermost-inbucket > /dev/null; \
	fi

127 128 129 130
	@if [ $(shell docker ps -a | grep -ci mattermost-minio) -eq 0 ]; then \
		echo starting mattermost-minio; \
		docker run --name mattermost-minio -p 9001:9000 -e "MINIO_ACCESS_KEY=minioaccesskey" \
		-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 133 134 135 136
	elif [ $(shell docker ps | grep -ci mattermost-minio) -eq 0 ]; then \
		echo restarting mattermost-minio; \
		docker start mattermost-minio > /dev/null; \
	fi

137
ifeq ($(BUILD_ENTERPRISE_READY),true)
138 139 140 141 142 143 144 145
	@echo Ldap test user test.one
	@if [ $(shell docker ps -a | grep -ci mattermost-openldap) -eq 0 ]; then \
		echo starting mattermost-openldap; \
		docker run --name mattermost-openldap -p 389:389 -p 636:636 \
			-e LDAP_TLS_VERIFY_CLIENT="never" \
			-e LDAP_ORGANISATION="Mattermost Test" \
			-e LDAP_DOMAIN="mm.test.com" \
			-e LDAP_ADMIN_PASSWORD="mostest" \
146
			-d osixia/openldap:1.1.6 > /dev/null;\
147 148 149 150 151 152 153 154 155 156
		sleep 10; \
		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';\
		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';\
		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';\
		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';\
		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';\
		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';\
	elif [ $(shell docker ps | grep -ci mattermost-openldap) -eq 0 ]; then \
		echo restarting mattermost-openldap; \
		docker start mattermost-openldap > /dev/null; \
157
		sleep 10; \
158
	fi
159 160 161 162 163 164 165 166

	@if [ $(shell docker ps -a | grep -ci mattermost-elasticsearch) -eq 0 ]; then \
		echo starting mattermost-elasticsearch; \
		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; \
	elif [ $(shell docker ps | grep -ci mattermost-elasticsearch) -eq 0 ]; then \
		echo restarting mattermost-elasticsearch; \
		docker start mattermost-elasticsearch> /dev/null; \
	fi
167 168 169 170 171 172 173 174

	@if [ $(shell docker ps -a | grep -ci mattermost-redis) -eq 0 ]; then \
		echo starting mattermost-redis; \
		docker run --name mattermost-redis -p 6379:6379 -d redis > /dev/null; \
	elif [ $(shell docker ps | grep -ci mattermost-redis) -eq 0 ]; then \
		echo restarting mattermost-redis; \
		docker start mattermost-redis > /dev/null; \
	fi
175
endif
176

177
stop-docker: ## Stops the docker containers for local development.
178
	@echo Stopping docker containers
=Corey Hulen's avatar
=Corey Hulen committed
179

180 181 182 183
	@if [ $(shell docker ps -a | grep -ci mattermost-mysql) -eq 1 ]; then \
		echo stopping mattermost-mysql; \
		docker stop mattermost-mysql > /dev/null; \
	fi
=Corey Hulen's avatar
=Corey Hulen committed
184

185 186 187 188
	@if [ $(shell docker ps -a | grep -ci mattermost-postgres) -eq 1 ]; then \
		echo stopping mattermost-postgres; \
		docker stop mattermost-postgres > /dev/null; \
	fi
189

190 191 192 193
	@if [ $(shell docker ps -a | grep -ci mattermost-openldap) -eq 1 ]; then \
		echo stopping mattermost-openldap; \
		docker stop mattermost-openldap > /dev/null; \
	fi
=Corey Hulen's avatar
=Corey Hulen committed
194

195 196 197 198 199
	@if [ $(shell docker ps -a | grep -ci mattermost-inbucket) -eq 1 ]; then \
		echo stopping mattermost-inbucket; \
		docker stop mattermost-inbucket > /dev/null; \
	fi

200 201 202 203 204
		@if [ $(shell docker ps -a | grep -ci mattermost-minio) -eq 1 ]; then \
    		echo stopping mattermost-minio; \
    		docker stop mattermost-minio > /dev/null; \
    	fi

205 206 207 208 209
	@if [ $(shell docker ps -a | grep -ci mattermost-elasticsearch) -eq 1 ]; then \
		echo stopping mattermost-elasticsearch; \
		docker stop mattermost-elasticsearch > /dev/null; \
	fi

210
clean-docker: ## Deletes the docker containers for local development.
211
	@echo Removing docker containers
=Corey Hulen's avatar
=Corey Hulen committed
212 213

	@if [ $(shell docker ps -a | grep -ci mattermost-mysql) -eq 1 ]; then \
214
		echo removing mattermost-mysql; \
=Corey Hulen's avatar
=Corey Hulen committed
215 216 217 218
		docker stop mattermost-mysql > /dev/null; \
		docker rm -v mattermost-mysql > /dev/null; \
	fi

219
	@if [ $(shell docker ps -a | grep -ci mattermost-postgres) -eq 1 ]; then \
220
		echo removing mattermost-postgres; \
221 222 223 224
		docker stop mattermost-postgres > /dev/null; \
		docker rm -v mattermost-postgres > /dev/null; \
	fi

225 226 227 228 229 230
	@if [ $(shell docker ps -a | grep -ci mattermost-openldap) -eq 1 ]; then \
		echo removing mattermost-openldap; \
		docker stop mattermost-openldap > /dev/null; \
		docker rm -v mattermost-openldap > /dev/null; \
	fi

231 232 233 234 235 236
	@if [ $(shell docker ps -a | grep -ci mattermost-inbucket) -eq 1 ]; then \
		echo removing mattermost-inbucket; \
		docker stop mattermost-inbucket > /dev/null; \
		docker rm -v mattermost-inbucket > /dev/null; \
	fi

237 238 239 240 241 242
	@if [ $(shell docker ps -a | grep -ci mattermost-minio) -eq 1 ]; then \
		echo removing mattermost-minio; \
		docker stop mattermost-minio > /dev/null; \
		docker rm -v mattermost-minio > /dev/null; \
	fi

243 244 245 246 247 248
	@if [ $(shell docker ps -a | grep -ci mattermost-elasticsearch) -eq 1 ]; then \
		echo removing mattermost-elasticsearch; \
		docker stop mattermost-elasticsearch > /dev/null; \
		docker rm -v mattermost-elasticsearch > /dev/null; \
	fi

249
govet: ## Runs govet against all packages.
250 251
	@echo Running GOVET
	$(GO) vet $(GOFLAGS) $(TE_PACKAGES) || exit 1
252

253 254 255
ifeq ($(BUILD_ENTERPRISE_READY),true)
	$(GO) vet $(GOFLAGS) $(EE_PACKAGES) || exit 1
endif
256

257
gofmt: ## Runs gofmt against all packages.
258
	@echo Running GOFMT
Chris's avatar
Chris committed
259 260 261 262 263 264 265 266 267 268 269 270 271 272

	@for package in $(TE_PACKAGES) $(EE_PACKAGES); do \
		echo "Checking "$$package; \
		files=$$(go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}} {{end}}' $$package); \
		if [ "$$files" ]; then \
			gofmt_output=$$(gofmt -d -s $$files 2>&1); \
			if [ "$$gofmt_output" ]; then \
				echo "$$gofmt_output"; \
				echo "gofmt failure"; \
				exit 1; \
			fi; \
		fi; \
	done
	@echo "gofmt success"; \
273

274
store-mocks: ## Creates mock files.
Chris's avatar
Chris committed
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`.'
Chris's avatar
Chris committed
277

278
update-jira-plugin: ## Updates Jira plugin.
279
	go get github.com/mattermost/go-bindata/...
280 281 282 283 284 285 286 287 288
	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
	$(shell go env GOPATH)/bin/go-bindata -pkg jira -o app/plugin/jira/plugin_darwin_amd64.go plugin.tar.gz
	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
	$(shell go env GOPATH)/bin/go-bindata -pkg jira -o app/plugin/jira/plugin_linux_amd64.go plugin.tar.gz
	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
	$(shell go env GOPATH)/bin/go-bindata -pkg jira -o app/plugin/jira/plugin_windows_amd64.go plugin.tar.gz
	rm plugin.tar.gz
	gofmt -s -w ./app/plugin/jira

289
update-zoom-plugin: ## Updates Zoom plugin.
290
	go get github.com/mattermost/go-bindata/...
291 292 293 294 295 296 297 298 299
	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
	$(shell go env GOPATH)/bin/go-bindata -pkg zoom -o app/plugin/zoom/plugin_darwin_amd64.go plugin.tar.gz
	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
	$(shell go env GOPATH)/bin/go-bindata -pkg zoom -o app/plugin/zoom/plugin_linux_amd64.go plugin.tar.gz
	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
	$(shell go env GOPATH)/bin/go-bindata -pkg zoom -o app/plugin/zoom/plugin_windows_amd64.go plugin.tar.gz
	rm plugin.tar.gz
	gofmt -s -w ./app/plugin/zoom

300
check-licenses: ## Checks license status.
301 302
	./scripts/license-check.sh $(TE_PACKAGES) $(EE_PACKAGES)

Derrick Anderson's avatar
Derrick Anderson committed
303 304 305
check-prereqs: ## Checks prerequisite software status.
	./scripts/prereq-check.sh
	
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 310 311 312 313 314
	@echo Testing TE race conditions

	@echo "Packages to test: "$(TE_PACKAGES)

	@for package in $(TE_PACKAGES); do \
		echo "Testing "$$package; \
315
		$(GO) test $(GOFLAGS) -race -run=$(TESTS) -test.timeout=4000s $$package || exit 1; \
316 317
	done

318
test-ee-race: ## Checks for race conditions in the enterprise edition.
319 320 321 322 323 324 325 326 327 328
	@echo Testing EE race conditions

ifeq ($(BUILD_ENTERPRISE_READY),true)
	@echo "Packages to test: "$(EE_PACKAGES)

	for package in $(EE_PACKAGES); do \
		echo "Testing "$$package; \
		$(GO) test $(GOFLAGS) -race -run=$(TESTS) -c $$package; \
		if [ -f $$(basename $$package).test ]; then \
			echo "Testing "$$package; \
329
			./$$(basename $$package).test -test.timeout=2000s || exit 1; \
330 331 332 333 334 335 336 337
			rm -r $$(basename $$package).test; \
		fi; \
	done

	rm -f config/*.crt
	rm -f config/*.key
endif

338
test-server-race: test-te-race test-ee-race ## Checks for race conditions.
339

340
do-cover-file: ## Creates the test coverage report file.
341 342
	@echo "mode: count" > cover.out

343
test-te: do-cover-file ## Runs tests in the team edition.
344 345
	@echo Testing TE
	@echo "Packages to test: "$(TE_PACKAGES)
346
	find . -name 'cprofile*.out' -exec sh -c 'rm "{}"' \;
Chris's avatar
Chris committed
347
	$(GO) test $(GOFLAGS) -run=$(TESTS) $(TESTFLAGS) -v -timeout=2000s -covermode=count -coverpkg=$(ALL_PACKAGES_COMMA) -exec $(ROOT)/scripts/test-xprog.sh $(TE_PACKAGES)
348
	find . -name 'cprofile*.out' -exec sh -c 'tail -n +2 {} >> cover.out ; rm "{}"' \;
349

350
test-ee: do-cover-file ## Runs tests in the enterprise edition.
351
	@echo Testing EE
352

353
ifeq ($(BUILD_ENTERPRISE_READY),true)
354
	@echo "Packages to test: "$(EE_PACKAGES)
355
	find . -name 'cprofile*.out' -exec sh -c 'rm "{}"' \;
356
	$(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)
357
	find . -name 'cprofile*.out' -exec sh -c 'tail -n +2 {} >> cover.out ; rm "{}"' \;
358 359
	rm -f config/*.crt
	rm -f config/*.key
360 361
endif

362
test-server: test-te test-ee ## Runs tests.
363

364
internal-test-web-client: ## Runs web client tests.
365
	$(GO) run $(GOFLAGS) $(PLATFORM_FILES) test web_client_tests
366

367
run-server-for-web-client-tests: ## Tests the server for web client.
368
	$(GO) run $(GOFLAGS) $(PLATFORM_FILES) test web_client_tests_server
369

370
test-client: ## Test client app.
371
	@echo Running client tests
372 373 374

	cd $(BUILD_WEBAPP_DIR) && $(MAKE) test

375
test: test-server test-client ## Runs all checks and tests below (except race detection and postgres).
=Corey Hulen's avatar
=Corey Hulen committed
376

377
cover: ## Runs the golang coverage tool. You must run the unit tests first.
378 379 380 381 382
	@echo Opening coverage info in browser. If this failed run make test first

	$(GO) tool cover -html=cover.out
	$(GO) tool cover -html=ecover.out

383 384 385 386 387 388 389 390 391
test-data: start-docker ## Add test data to the local instance.
	$(GO) run $(GOFLAGS) $(GO_LINKER_FLAGS) $(PLATFORM_FILES) sampledata -w 1

	@echo You may need to restart the Mattermost server before using the following
	@echo ====================================================================================
	@echo Login with a system admin account email=user-0@sample.mattermost.com password=user-0
	@echo Login with a regular account email=user-1@sample.mattermost.com password=user-1
	@echo ====================================================================================

392
run-server: start-docker ## Starts the server.
393 394 395
	@echo Running mattermost for development

	mkdir -p $(BUILD_WEBAPP_DIR)/dist/files
396
	$(GO) run $(GOFLAGS) $(GO_LINKER_FLAGS) $(PLATFORM_FILES) --disableconfigwatch &
397

398
run-cli: start-docker ## Runs CLI.
399
	@echo Running mattermost for development
400
	@echo Example should be like 'make ARGS="-version" run-cli'
401

402
	$(GO) run $(GOFLAGS) $(GO_LINKER_FLAGS) $(PLATFORM_FILES) ${ARGS}
403

404
run-client: ## Runs the webapp.
405 406
	@echo Running mattermost client for development

407
	ln -nfs $(BUILD_WEBAPP_DIR)/dist client
408
	cd $(BUILD_WEBAPP_DIR) && $(MAKE) run
409

410
run-client-fullmap: ## Runs the webapp with source code mapping (slower; better debugging).
411 412 413 414
	@echo Running mattermost client for development with FULL SOURCE MAP

	cd $(BUILD_WEBAPP_DIR) && $(MAKE) run-fullmap

Derrick Anderson's avatar
Derrick Anderson committed
415
run: check-prereqs run-server run-client ## Runs the server and webapp.
416

417
run-fullmap: run-server run-client-fullmap ## Same as run but with a full sourcemap for client.
418

419
stop-server: ## Stops the server.
420 421
	@echo Stopping mattermost

422 423 424 425
ifeq ($(BUILDER_GOOS_GOARCH),"windows_amd64")
	wmic process where "Caption='go.exe' and CommandLine like '%go.exe run%'" call terminate
	wmic process where "Caption='mattermost.exe' and CommandLine like '%go-build%'" call terminate
else
426
	@for PID in $$(ps -ef | grep "[g]o run" | awk '{ print $$2 }'); do \
427
		echo stopping go $$PID; \
=Corey Hulen's avatar
=Corey Hulen committed
428 429
		kill $$PID; \
	done
430
	@for PID in $$(ps -ef | grep "[g]o-build" | awk '{ print $$2 }'); do \
431 432 433
		echo stopping mattermost $$PID; \
		kill $$PID; \
	done
434
endif
435

436
stop-client: ## Stops the webapp.
437
	@echo Stopping mattermost client
438

439
	cd $(BUILD_WEBAPP_DIR) && $(MAKE) stop
Christopher Speller's avatar
Christopher Speller committed
440

441
stop: stop-server stop-client ## Stops server and client.
442

443
restart: restart-server restart-client ## Restarts the server and webapp.
444

445
restart-server: | stop-server run-server ## Restarts the mattermost server to pick up development change.
446

447
restart-client: | stop-client run-client ## Restarts the webapp.
448

449
run-job-server: ## Runs the background job server.
450
	@echo Running job server for development
451
	$(GO) run $(GOFLAGS) $(GO_LINKER_FLAGS) $(PLATFORM_FILES) jobserver --disableconfigwatch &
452

453
config-ldap: ## Configures LDAP.
454 455 456 457 458 459 460 461 462 463 464 465 466
	@echo Setting up configuration for local LDAP

	@sed -i'' -e 's|"LdapServer": ".*"|"LdapServer": "dockerhost"|g' config/config.json
	@sed -i'' -e 's|"BaseDN": ".*"|"BaseDN": "ou=testusers,dc=mm,dc=test,dc=com"|g' config/config.json
	@sed -i'' -e 's|"BindUsername": ".*"|"BindUsername": "cn=admin,dc=mm,dc=test,dc=com"|g' config/config.json
	@sed -i'' -e 's|"BindPassword": ".*"|"BindPassword": "mostest"|g' config/config.json
	@sed -i'' -e 's|"FirstNameAttribute": ".*"|"FirstNameAttribute": "cn"|g' config/config.json
	@sed -i'' -e 's|"LastNameAttribute": ".*"|"LastNameAttribute": "sn"|g' config/config.json
	@sed -i'' -e 's|"NicknameAttribute": ".*"|"NicknameAttribute": "cn"|g' config/config.json
	@sed -i'' -e 's|"EmailAttribute": ".*"|"EmailAttribute": "mail"|g' config/config.json
	@sed -i'' -e 's|"UsernameAttribute": ".*"|"UsernameAttribute": "uid"|g' config/config.json
	@sed -i'' -e 's|"IdAttribute": ".*"|"IdAttribute": "uid"|g' config/config.json

467
config-reset: ## Resets the config/config.json file to the default.
468 469 470 471
	@echo Resetting configuration to default
	rm -f config/config.json
	cp config/default.json config/config.json

472
clean: stop-docker ## Clean up everything except persistant server data.
473 474 475 476 477
	@echo Cleaning

	rm -Rf $(DIST_ROOT)
	go clean $(GOFLAGS) -i ./...

478
	cd $(BUILD_WEBAPP_DIR) && $(MAKE) clean
479

480
	find . -type d -name data -not -path './vendor/*' | xargs rm -r
481 482 483
	rm -rf logs

	rm -f mattermost.log
484
	rm -f mattermost.log.jsonl
485 486
	rm -f npm-debug.log
	rm -f api/mattermost.log
487
	rm -f api/mattermost.log.jsonl
488
	rm -f .prepare-go
Christopher Speller's avatar
Christopher Speller committed
489
	rm -f enterprise
490 491 492 493
	rm -f cover.out
	rm -f ecover.out
	rm -f *.out
	rm -f *.test
494
	rm -f imports/imports.go
495
	rm -f cmd/platform/cprofile*.out
496

497
nuke: clean clean-docker ## Clean plus removes persistant server data.
498
	@echo BOOM
499

500
	rm -rf data
501

502
setup-mac: ## Adds macOS hosts entries for Docker.
503
	echo $$(boot2docker ip 2> /dev/null) dockerhost | sudo tee -a /etc/hosts
504

505

506
todo: ## Display TODO and FIXME items in the source code.
Christopher Speller's avatar
Christopher Speller committed
507 508 509 510
	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime TODO
	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime XXX
	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime FIXME
	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime "FIX ME"
511
ifeq ($(BUILD_ENTERPRISE_READY),true)
Christopher Speller's avatar
Christopher Speller committed
512 513 514 515
	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime TODO enterprise/
	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime XXX enterprise/
	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime FIXME enterprise/
	@! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime "FIX ME" enterprise/
516
endif
517 518 519 520

## Help documentatin à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' ./Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'