Makefile 23 KB

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