github.com/mattermost/mattermost-server/v5@v5.39.3/Makefile (about) 1 .PHONY: build package run stop run-client run-server run-haserver stop-haserver stop-client stop-server restart restart-server restart-client restart-haserver 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 start-docker-check migrations-bindata new-migration migration-prereqs 2 3 ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) 4 5 ifeq ($(OS),Windows_NT) 6 PLATFORM := Windows 7 else 8 PLATFORM := $(shell uname) 9 endif 10 11 # Set an environment variable on Linux used to resolve `docker.host.internal` inconsistencies with 12 # docker. This can be reworked once https://github.com/docker/for-linux/issues/264 is resolved 13 # satisfactorily. 14 ifeq ($(PLATFORM),Linux) 15 export IS_LINUX = -linux 16 else 17 export IS_LINUX = 18 endif 19 20 IS_CI ?= false 21 # Build Flags 22 BUILD_NUMBER ?= $(BUILD_NUMBER:) 23 BUILD_DATE = $(shell date -u) 24 BUILD_HASH = $(shell git rev-parse HEAD) 25 # If we don't set the build number it defaults to dev 26 ifeq ($(BUILD_NUMBER),) 27 BUILD_NUMBER := dev 28 endif 29 BUILD_ENTERPRISE_DIR ?= ../enterprise 30 BUILD_ENTERPRISE ?= true 31 BUILD_ENTERPRISE_READY = false 32 BUILD_TYPE_NAME = team 33 BUILD_HASH_ENTERPRISE = none 34 ifneq ($(wildcard $(BUILD_ENTERPRISE_DIR)/.),) 35 ifeq ($(BUILD_ENTERPRISE),true) 36 BUILD_ENTERPRISE_READY = true 37 BUILD_TYPE_NAME = enterprise 38 BUILD_HASH_ENTERPRISE = $(shell cd $(BUILD_ENTERPRISE_DIR) && git rev-parse HEAD) 39 else 40 BUILD_ENTERPRISE_READY = false 41 BUILD_TYPE_NAME = team 42 endif 43 else 44 BUILD_ENTERPRISE_READY = false 45 BUILD_TYPE_NAME = team 46 endif 47 BUILD_WEBAPP_DIR ?= ../mattermost-webapp 48 BUILD_CLIENT = false 49 BUILD_HASH_CLIENT = independant 50 ifneq ($(wildcard $(BUILD_WEBAPP_DIR)/.),) 51 ifeq ($(BUILD_CLIENT),true) 52 BUILD_CLIENT = true 53 BUILD_HASH_CLIENT = $(shell cd $(BUILD_WEBAPP_DIR) && git rev-parse HEAD) 54 else 55 BUILD_CLIENT = false 56 endif 57 else 58 BUILD_CLIENT = false 59 endif 60 61 # We need current user's UID for `run-haserver` so docker compose does not run server 62 # as root and mess up file permissions for devs. When running like this HOME will be blank 63 # and docker will add '/', so we need to set the go-build cache location or we'll get 64 # permission errors on build as it tries to create a cache in filesystem root. 65 export CURRENT_UID = $(shell id -u):$(shell id -g) 66 ifeq ($(HOME),/) 67 export XDG_CACHE_HOME = /tmp/go-cache/ 68 endif 69 70 # Go Flags 71 GOFLAGS ?= $(GOFLAGS:) 72 # We need to export GOBIN to allow it to be set 73 # for processes spawned from the Makefile 74 export GOBIN ?= $(PWD)/bin 75 GO=go 76 DELVE=dlv 77 LDFLAGS += -X "github.com/mattermost/mattermost-server/v5/model.BuildNumber=$(BUILD_NUMBER)" 78 LDFLAGS += -X "github.com/mattermost/mattermost-server/v5/model.BuildDate=$(BUILD_DATE)" 79 LDFLAGS += -X "github.com/mattermost/mattermost-server/v5/model.BuildHash=$(BUILD_HASH)" 80 LDFLAGS += -X "github.com/mattermost/mattermost-server/v5/model.BuildHashEnterprise=$(BUILD_HASH_ENTERPRISE)" 81 LDFLAGS += -X "github.com/mattermost/mattermost-server/v5/model.BuildEnterpriseReady=$(BUILD_ENTERPRISE_READY)" 82 83 GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1) 84 GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2) 85 MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1 86 MINIMUM_SUPPORTED_GO_MINOR_VERSION = 15 87 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) 88 89 # GOOS/GOARCH of the build host, used to determine whether we're cross-compiling or not 90 BUILDER_GOOS_GOARCH="$(shell $(GO) env GOOS)_$(shell $(GO) env GOARCH)" 91 92 PLATFORM_FILES="./cmd/mattermost/main.go" 93 94 # Output paths 95 DIST_ROOT=dist 96 DIST_PATH=$(DIST_ROOT)/mattermost 97 98 # Tests 99 TESTS=. 100 101 # Packages lists 102 TE_PACKAGES=$(shell $(GO) list ./... | grep -v ./data) 103 104 TEMPLATES_DIR=templates 105 106 # Plugins Packages 107 PLUGIN_PACKAGES ?= mattermost-plugin-antivirus-v0.1.2 108 PLUGIN_PACKAGES += mattermost-plugin-autolink-v1.2.2 109 PLUGIN_PACKAGES += mattermost-plugin-aws-SNS-v1.2.0 110 PLUGIN_PACKAGES += mattermost-plugin-channel-export-v0.2.2 111 PLUGIN_PACKAGES += mattermost-plugin-custom-attributes-v1.3.0 112 PLUGIN_PACKAGES += mattermost-plugin-github-v2.0.1 113 PLUGIN_PACKAGES += mattermost-plugin-gitlab-v1.3.0 114 PLUGIN_PACKAGES += mattermost-plugin-playbooks-v1.16.1 115 PLUGIN_PACKAGES += mattermost-plugin-jenkins-v1.1.0 116 PLUGIN_PACKAGES += mattermost-plugin-jira-v2.4.0 117 PLUGIN_PACKAGES += mattermost-plugin-nps-v1.1.0 118 PLUGIN_PACKAGES += mattermost-plugin-welcomebot-v1.2.0 119 PLUGIN_PACKAGES += mattermost-plugin-zoom-v1.5.0 120 PLUGIN_PACKAGES += focalboard-v0.8.4 121 122 # Prepares the enterprise build if exists. The IGNORE stuff is a hack to get the Makefile to execute the commands outside a target 123 ifeq ($(BUILD_ENTERPRISE_READY),true) 124 IGNORE:=$(shell echo Enterprise build selected, preparing) 125 IGNORE:=$(shell rm -f imports/imports.go) 126 IGNORE:=$(shell cp $(BUILD_ENTERPRISE_DIR)/imports/imports.go imports/) 127 IGNORE:=$(shell rm -f enterprise) 128 IGNORE:=$(shell ln -s $(BUILD_ENTERPRISE_DIR) enterprise) 129 else 130 IGNORE:=$(shell rm -f imports/imports.go) 131 endif 132 133 EE_PACKAGES=$(shell $(GO) list ./enterprise/...) 134 135 ifeq ($(BUILD_ENTERPRISE_READY),true) 136 ALL_PACKAGES=$(TE_PACKAGES) $(EE_PACKAGES) 137 else 138 ALL_PACKAGES=$(TE_PACKAGES) 139 endif 140 141 all: run ## Alias for 'run'. 142 143 -include config.override.mk 144 include config.mk 145 include build/*.mk 146 147 LDFLAGS += -X "github.com/mattermost/mattermost-server/v5/model.MockCWS=$(MM_ENABLE_CWS_MOCK)" 148 149 RUN_IN_BACKGROUND ?= 150 ifeq ($(RUN_SERVER_IN_BACKGROUND),true) 151 RUN_IN_BACKGROUND := & 152 endif 153 154 start-docker-check: 155 ifeq (,$(findstring minio,$(ENABLED_DOCKER_SERVICES))) 156 TEMP_DOCKER_SERVICES:=$(TEMP_DOCKER_SERVICES) minio 157 endif 158 ifeq ($(BUILD_ENTERPRISE_READY),true) 159 ifeq (,$(findstring openldap,$(ENABLED_DOCKER_SERVICES))) 160 TEMP_DOCKER_SERVICES:=$(TEMP_DOCKER_SERVICES) openldap 161 endif 162 ifeq (,$(findstring elasticsearch,$(ENABLED_DOCKER_SERVICES))) 163 TEMP_DOCKER_SERVICES:=$(TEMP_DOCKER_SERVICES) elasticsearch 164 endif 165 endif 166 ENABLED_DOCKER_SERVICES:=$(ENABLED_DOCKER_SERVICES) $(TEMP_DOCKER_SERVICES) 167 168 start-docker: ## Starts the docker containers for local development. 169 ifneq ($(IS_CI),false) 170 @echo CI Build: skipping docker start 171 else ifeq ($(MM_NO_DOCKER),true) 172 @echo No Docker Enabled: skipping docker start 173 else 174 @echo Starting docker containers 175 176 $(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 177 ifneq (,$(findstring openldap,$(ENABLED_DOCKER_SERVICES))) 178 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'; 179 endif 180 ifneq (,$(findstring mysql-read-replica,$(ENABLED_DOCKER_SERVICES))) 181 ./scripts/replica-mysql-config.sh 182 endif 183 endif 184 185 run-haserver: 186 ifeq ($(BUILD_ENTERPRISE_READY),true) 187 @echo Starting mattermost in an HA topology '(3 node cluster)' 188 189 docker-compose -f docker-compose.yaml up --remove-orphans haproxy 190 endif 191 192 stop-haserver: 193 @echo Stopping docker containers for HA topology 194 docker-compose stop 195 196 stop-docker: ## Stops the docker containers for local development. 197 ifeq ($(MM_NO_DOCKER),true) 198 @echo No Docker Enabled: skipping docker stop 199 else 200 @echo Stopping docker containers 201 202 docker-compose stop 203 endif 204 205 clean-docker: ## Deletes the docker containers for local development. 206 ifeq ($(MM_NO_DOCKER),true) 207 @echo No Docker Enabled: skipping docker clean 208 else 209 @echo Removing docker containers 210 211 docker-compose down -v 212 docker-compose rm -v 213 endif 214 215 plugin-checker: 216 $(GO) run $(GOFLAGS) ./plugin/checker 217 218 prepackaged-plugins: ## Populate the prepackaged-plugins directory 219 @echo Downloading prepackaged plugins 220 mkdir -p prepackaged_plugins 221 @cd prepackaged_plugins && for plugin_package in $(PLUGIN_PACKAGES) ; do \ 222 curl -f -O -L https://plugins-store.test.mattermost.com/release/$$plugin_package.tar.gz; \ 223 curl -f -O -L https://plugins-store.test.mattermost.com/release/$$plugin_package.tar.gz.sig; \ 224 done 225 226 prepackaged-binaries: ## Populate the prepackaged-binaries to the bin directory 227 ifeq ($(shell test -f bin/mmctl && printf "yes"),yes) 228 @echo "MMCTL already exists in bin/mmctl not downloading a new version." 229 else 230 @scripts/download_mmctl_release.sh 231 endif 232 233 golangci-lint: ## Run golangci-lint on codebase 234 # https://stackoverflow.com/a/677212/1027058 (check if a command exists or not) 235 @if ! [ -x "$$(command -v golangci-lint)" ]; then \ 236 echo "golangci-lint is not installed. Please see https://github.com/golangci/golangci-lint#install for installation instructions."; \ 237 exit 1; \ 238 fi; \ 239 240 @echo Running golangci-lint 241 golangci-lint run ./... 242 ifeq ($(BUILD_ENTERPRISE_READY),true) 243 ifneq ($(MM_NO_ENTERPRISE_LINT),true) 244 golangci-lint run ./enterprise/... 245 endif 246 endif 247 248 app-layers: ## Extract interface from App struct 249 $(GO) get -modfile=go.tools.mod github.com/reflog/struct2interface 250 $(GOBIN)/struct2interface -f "app" -o "app/app_iface.go" -p "app" -s "App" -i "AppIface" -t ./app/layer_generators/app_iface.go.tmpl 251 $(GO) run ./app/layer_generators -in ./app/app_iface.go -out ./app/opentracing/opentracing_layer.go -template ./app/layer_generators/opentracing_layer.go.tmpl 252 253 i18n-extract: ## Extract strings for translation from the source code 254 $(GO) get -modfile=go.tools.mod github.com/mattermost/mattermost-utilities/mmgotool 255 $(GOBIN)/mmgotool i18n extract --portal-dir="" 256 257 i18n-check: ## Exit on empty translation strings and translation source strings 258 $(GO) get -modfile=go.tools.mod github.com/mattermost/mattermost-utilities/mmgotool 259 $(GOBIN)/mmgotool i18n clean-empty --portal-dir="" --check 260 $(GOBIN)/mmgotool i18n check-empty-src --portal-dir="" 261 262 store-mocks: ## Creates mock files. 263 $(GO) get -modfile=go.tools.mod github.com/vektra/mockery/... 264 $(GOBIN)/mockery -dir store -all -output store/storetest/mocks -note 'Regenerate this file using `make store-mocks`.' 265 266 telemetry-mocks: ## Creates mock files. 267 $(GO) get -modfile=go.tools.mod github.com/vektra/mockery/... 268 $(GOBIN)/mockery -dir services/telemetry -all -output services/telemetry/mocks -note 'Regenerate this file using `make telemetry-mocks`.' 269 270 store-layers: ## Generate layers for the store 271 $(GO) generate $(GOFLAGS) ./store 272 273 migration-prereqs: ## Builds prerequisite packages for migrations 274 $(GO) get -modfile=go.tools.mod github.com/golang-migrate/migrate/v4/cmd/migrate 275 276 new-migration: migration-prereqs ## Creates a new migration 277 @echo "Generating new migration for mysql" 278 $(GOBIN)/migrate create -ext sql -dir db/migrations/mysql -seq $(name) 279 280 @echo "Generating new migration for postgres" 281 $(GOBIN)/migrate create -ext sql -dir db/migrations/postgres -seq $(name) 282 283 @echo "When you are done writing your migration, run 'make migrations'" 284 285 migrations-bindata: ## Generates bindata migrations 286 $(GO) get -modfile=go.tools.mod github.com/go-bindata/go-bindata/... 287 288 @echo Generating bindata for migrations 289 $(GO) generate $(GOFLAGS) ./db/migrations/ 290 291 filestore-mocks: ## Creates mock files. 292 $(GO) get -modfile=go.tools.mod github.com/vektra/mockery/... 293 $(GOBIN)/mockery -dir shared/filestore -all -output shared/filestore/mocks -note 'Regenerate this file using `make filestore-mocks`.' 294 295 ldap-mocks: ## Creates mock files for ldap. 296 $(GO) get -modfile=go.tools.mod github.com/vektra/mockery/... 297 $(GOBIN)/mockery -dir enterprise/ldap -all -output enterprise/ldap/mocks -note 'Regenerate this file using `make ldap-mocks`.' 298 299 plugin-mocks: ## Creates mock files for plugins. 300 $(GO) get -modfile=go.tools.mod github.com/vektra/mockery/... 301 $(GOBIN)/mockery -dir plugin -name API -output plugin/plugintest -outpkg plugintest -case underscore -note 'Regenerate this file using `make plugin-mocks`.' 302 $(GOBIN)/mockery -dir plugin -name Hooks -output plugin/plugintest -outpkg plugintest -case underscore -note 'Regenerate this file using `make plugin-mocks`.' 303 $(GOBIN)/mockery -dir plugin -name Helpers -output plugin/plugintest -outpkg plugintest -case underscore -note 'Regenerate this file using `make plugin-mocks`.' 304 $(GOBIN)/mockery -dir plugin -name Driver -output plugin/plugintest -outpkg plugintest -case underscore -note 'Regenerate this file using `make plugin-mocks`.' 305 306 einterfaces-mocks: ## Creates mock files for einterfaces. 307 $(GO) get -modfile=go.tools.mod github.com/vektra/mockery/... 308 $(GOBIN)/mockery -dir einterfaces -all -output einterfaces/mocks -note 'Regenerate this file using `make einterfaces-mocks`.' 309 310 searchengine-mocks: ## Creates mock files for searchengines. 311 $(GO) get -modfile=go.tools.mod github.com/vektra/mockery/... 312 $(GOBIN)/mockery -dir services/searchengine -all -output services/searchengine/mocks -note 'Regenerate this file using `make searchengine-mocks`.' 313 314 sharedchannel-mocks: ## Creates mock files for shared channels. 315 $(GO) get -modfile=go.tools.mod github.com/vektra/mockery/... 316 $(GOBIN)/mockery -dir=./services/sharedchannel -name=ServerIface -output=./services/sharedchannel -inpkg -outpkg=sharedchannel -testonly -note 'Regenerate this file using `make sharedchannel-mocks`.' 317 $(GOBIN)/mockery -dir=./services/sharedchannel -name=AppIface -output=./services/sharedchannel -inpkg -outpkg=sharedchannel -testonly -note 'Regenerate this file using `make sharedchannel-mocks`.' 318 319 misc-mocks: ## Creates mocks for misc interfaces. 320 $(GO) get -modfile=go.tools.mod github.com/vektra/mockery/... 321 $(GOPATH)/bin/mockery -dir utils --name LicenseValidatorIface -output utils/mocks -note 'Regenerate this file using `make misc-mocks`.' 322 323 pluginapi: ## Generates api and hooks glue code for plugins 324 $(GO) generate $(GOFLAGS) ./plugin 325 326 check-prereqs: ## Checks prerequisite software status. 327 ./scripts/prereq-check.sh 328 329 check-prereqs-enterprise: ## Checks prerequisite software status for enterprise. 330 ifeq ($(BUILD_ENTERPRISE_READY),true) 331 ./scripts/prereq-check-enterprise.sh 332 endif 333 334 check-style: golangci-lint plugin-checker vet ## Runs style/lint checks 335 336 337 do-cover-file: ## Creates the test coverage report file. 338 @echo "mode: count" > cover.out 339 340 go-junit-report: 341 $(GO) get -modfile=go.tools.mod github.com/jstemmer/go-junit-report 342 343 test-compile: ## Compile tests. 344 @echo COMPILE TESTS 345 346 for package in $(TE_PACKAGES) $(EE_PACKAGES); do \ 347 $(GO) test $(GOFLAGS) -c $$package; \ 348 done 349 350 test-db-migration: start-docker ## Gets diff of upgrade vs new instance schemas. 351 ./scripts/mysql-migration-test.sh 352 ./scripts/psql-migration-test.sh 353 354 gomodtidy: 355 @cp go.mod go.mod.orig 356 @cp go.sum go.sum.orig 357 $(GO) mod tidy 358 @if [ "$$(diff go.mod go.mod.orig)" != "" -o "$$(diff go.sum go.sum.orig)" != "" ]; then \ 359 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\"."; \ 360 rm go.*.orig; \ 361 exit 1; \ 362 fi; 363 @rm go.*.orig; 364 365 test-server-pre: check-prereqs-enterprise start-docker-check start-docker go-junit-report do-cover-file ## Runs tests. 366 ifeq ($(BUILD_ENTERPRISE_READY),true) 367 @echo Running all tests 368 else 369 @echo Running only TE tests 370 endif 371 372 test-server-race: test-server-pre 373 ./scripts/test.sh "$(GO)" "-race $(GOFLAGS)" "$(ALL_PACKAGES)" "$(TESTS)" "$(TESTFLAGS)" "$(GOBIN)" "90m" "atomic" 374 ifneq ($(IS_CI),true) 375 ifneq ($(MM_NO_DOCKER),true) 376 ifneq ($(TEMP_DOCKER_SERVICES),) 377 @echo Stopping temporary docker services 378 docker-compose stop $(TEMP_DOCKER_SERVICES) 379 endif 380 endif 381 endif 382 383 test-server: test-server-pre 384 ./scripts/test.sh "$(GO)" "$(GOFLAGS)" "$(ALL_PACKAGES)" "$(TESTS)" "$(TESTFLAGS)" "$(GOBIN)" "45m" "count" 385 ifneq ($(IS_CI),true) 386 ifneq ($(MM_NO_DOCKER),true) 387 ifneq ($(TEMP_DOCKER_SERVICES),) 388 @echo Stopping temporary docker services 389 docker-compose stop $(TEMP_DOCKER_SERVICES) 390 endif 391 endif 392 endif 393 394 test-server-ee: check-prereqs-enterprise start-docker-check start-docker go-junit-report do-cover-file ## Runs EE tests. 395 @echo Running only EE tests 396 ./scripts/test.sh "$(GO)" "$(GOFLAGS)" "$(EE_PACKAGES)" "$(TESTS)" "$(TESTFLAGS)" "$(GOBIN)" "20m" "count" 397 398 test-server-quick: check-prereqs-enterprise ## Runs only quick tests. 399 ifeq ($(BUILD_ENTERPRISE_READY),true) 400 @echo Running all tests 401 $(GO) test $(GOFLAGS) -short $(ALL_PACKAGES) 402 else 403 @echo Running only TE tests 404 $(GO) test $(GOFLAGS) -short $(TE_PACKAGES) 405 endif 406 407 internal-test-web-client: ## Runs web client tests. 408 $(GO) run $(GOFLAGS) $(PLATFORM_FILES) test web_client_tests 409 410 run-server-for-web-client-tests: ## Tests the server for web client. 411 $(GO) run $(GOFLAGS) $(PLATFORM_FILES) test web_client_tests_server 412 413 test-client: ## Test client app. 414 @echo Running client tests 415 416 cd $(BUILD_WEBAPP_DIR) && $(MAKE) test 417 418 test: test-server test-client ## Runs all checks and tests below (except race detection and postgres). 419 420 cover: ## Runs the golang coverage tool. You must run the unit tests first. 421 @echo Opening coverage info in browser. If this failed run make test first 422 423 $(GO) tool cover -html=cover.out 424 $(GO) tool cover -html=ecover.out 425 426 test-data: start-docker ## Add test data to the local instance. 427 $(GO) run $(GOFLAGS) -ldflags '$(LDFLAGS)' $(PLATFORM_FILES) config set TeamSettings.MaxUsersPerTeam 100 428 $(GO) run $(GOFLAGS) -ldflags '$(LDFLAGS)' $(PLATFORM_FILES) sampledata -w 4 -u 60 429 430 @echo You may need to restart the Mattermost server before using the following 431 @echo ======================================================================== 432 @echo Login with a system admin account username=sysadmin password=Sys@dmin-sample1 433 @echo Login with a regular account username=user-1 password=SampleUs@r-1 434 @echo ======================================================================== 435 436 validate-go-version: ## Validates the installed version of go against Mattermost's minimum requirement. 437 @if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ 438 exit 0 ;\ 439 elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ 440 echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\ 441 exit 1; \ 442 elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \ 443 echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\ 444 exit 1; \ 445 fi 446 447 build-templates: ## Compile all mjml email templates 448 cd $(TEMPLATES_DIR) && $(MAKE) build 449 450 run-server: prepackaged-binaries validate-go-version start-docker ## Starts the server. 451 @echo Running mattermost for development 452 453 mkdir -p $(BUILD_WEBAPP_DIR)/dist/files 454 $(GO) run $(GOFLAGS) -ldflags '$(LDFLAGS)' $(PLATFORM_FILES) 2>&1 | \ 455 $(GO) run $(GOFLAGS) -ldflags '$(LDFLAGS)' $(PLATFORM_FILES) logs --logrus $(RUN_IN_BACKGROUND) 456 457 debug-server: start-docker ## Compile and start server using delve. 458 mkdir -p $(BUILD_WEBAPP_DIR)/dist/files 459 $(DELVE) debug $(PLATFORM_FILES) --build-flags="-ldflags '\ 460 -X github.com/mattermost/mattermost-server/v5/model.BuildNumber=$(BUILD_NUMBER)\ 461 -X \"github.com/mattermost/mattermost-server/v5/model.BuildDate=$(BUILD_DATE)\"\ 462 -X github.com/mattermost/mattermost-server/v5/model.BuildHash=$(BUILD_HASH)\ 463 -X github.com/mattermost/mattermost-server/v5/model.BuildHashEnterprise=$(BUILD_HASH_ENTERPRISE)\ 464 -X github.com/mattermost/mattermost-server/v5/model.BuildEnterpriseReady=$(BUILD_ENTERPRISE_READY)'" 465 466 debug-server-headless: start-docker ## Debug server from within an IDE like VSCode or IntelliJ. 467 mkdir -p $(BUILD_WEBAPP_DIR)/dist/files 468 $(DELVE) debug --headless --listen=:2345 --api-version=2 --accept-multiclient $(PLATFORM_FILES) --build-flags="-ldflags '\ 469 -X github.com/mattermost/mattermost-server/v5/model.BuildNumber=$(BUILD_NUMBER)\ 470 -X \"github.com/mattermost/mattermost-server/v5/model.BuildDate=$(BUILD_DATE)\"\ 471 -X github.com/mattermost/mattermost-server/v5/model.BuildHash=$(BUILD_HASH)\ 472 -X github.com/mattermost/mattermost-server/v5/model.BuildHashEnterprise=$(BUILD_HASH_ENTERPRISE)\ 473 -X github.com/mattermost/mattermost-server/v5/model.BuildEnterpriseReady=$(BUILD_ENTERPRISE_READY)'" 474 475 run-cli: start-docker ## Runs CLI. 476 @echo Running mattermost for development 477 @echo Example should be like 'make ARGS="-version" run-cli' 478 479 $(GO) run $(GOFLAGS) -ldflags '$(LDFLAGS)' $(PLATFORM_FILES) ${ARGS} 480 481 run-client: ## Runs the webapp. 482 @echo Running mattermost client for development 483 484 ln -nfs $(BUILD_WEBAPP_DIR)/dist client 485 cd $(BUILD_WEBAPP_DIR) && $(MAKE) run 486 487 run-client-fullmap: ## Legacy alias to run-client 488 @echo Running mattermost client for development 489 490 cd $(BUILD_WEBAPP_DIR) && $(MAKE) run 491 492 run: check-prereqs run-server run-client ## Runs the server and webapp. 493 494 run-fullmap: run-server run-client ## Legacy alias to run 495 496 stop-server: ## Stops the server. 497 @echo Stopping mattermost 498 499 ifeq ($(BUILDER_GOOS_GOARCH),"windows_amd64") 500 wmic process where "Caption='go.exe' and CommandLine like '%go.exe run%'" call terminate 501 wmic process where "Caption='mattermost.exe' and CommandLine like '%go-build%'" call terminate 502 else 503 @for PID in $$(ps -ef | grep "[g]o run" | awk '{ print $$2 }'); do \ 504 echo stopping go $$PID; \ 505 kill $$PID; \ 506 done 507 @for PID in $$(ps -ef | grep "[g]o-build" | awk '{ print $$2 }'); do \ 508 echo stopping mattermost $$PID; \ 509 kill $$PID; \ 510 done 511 endif 512 513 stop-client: ## Stops the webapp. 514 @echo Stopping mattermost client 515 516 cd $(BUILD_WEBAPP_DIR) && $(MAKE) stop 517 518 stop: stop-server stop-client stop-docker ## Stops server, client and the docker compose. 519 520 restart: restart-server restart-client ## Restarts the server and webapp. 521 522 restart-server: | stop-server run-server ## Restarts the mattermost server to pick up development change. 523 524 restart-haserver: 525 @echo Restarting mattermost in an HA topology 526 527 docker-compose restart follower2 528 docker-compose restart follower 529 docker-compose restart leader 530 docker-compose restart haproxy 531 532 restart-client: | stop-client run-client ## Restarts the webapp. 533 534 run-job-server: ## Runs the background job server. 535 @echo Running job server for development 536 $(GO) run $(GOFLAGS) -ldflags '$(LDFLAGS)' $(PLATFORM_FILES) jobserver & 537 538 config-ldap: ## Configures LDAP. 539 @echo Setting up configuration for local LDAP 540 541 @sed -i'' -e 's|"LdapServer": ".*"|"LdapServer": "localhost"|g' config/config.json 542 @sed -i'' -e 's|"BaseDN": ".*"|"BaseDN": "dc=mm,dc=test,dc=com"|g' config/config.json 543 @sed -i'' -e 's|"BindUsername": ".*"|"BindUsername": "cn=admin,dc=mm,dc=test,dc=com"|g' config/config.json 544 @sed -i'' -e 's|"BindPassword": ".*"|"BindPassword": "mostest"|g' config/config.json 545 @sed -i'' -e 's|"FirstNameAttribute": ".*"|"FirstNameAttribute": "cn"|g' config/config.json 546 @sed -i'' -e 's|"LastNameAttribute": ".*"|"LastNameAttribute": "sn"|g' config/config.json 547 @sed -i'' -e 's|"NicknameAttribute": ".*"|"NicknameAttribute": "cn"|g' config/config.json 548 @sed -i'' -e 's|"EmailAttribute": ".*"|"EmailAttribute": "mail"|g' config/config.json 549 @sed -i'' -e 's|"UsernameAttribute": ".*"|"UsernameAttribute": "uid"|g' config/config.json 550 @sed -i'' -e 's|"IdAttribute": ".*"|"IdAttribute": "uid"|g' config/config.json 551 @sed -i'' -e 's|"LoginIdAttribute": ".*"|"LoginIdAttribute": "uid"|g' config/config.json 552 @sed -i'' -e 's|"GroupDisplayNameAttribute": ".*"|"GroupDisplayNameAttribute": "cn"|g' config/config.json 553 @sed -i'' -e 's|"GroupIdAttribute": ".*"|"GroupIdAttribute": "entryUUID"|g' config/config.json 554 555 config-reset: ## Resets the config/config.json file to the default. 556 @echo Resetting configuration to default 557 rm -f config/config.json 558 OUTPUT_CONFIG=$(PWD)/config/config.json $(GO) $(GOFLAGS) run ./scripts/config_generator 559 560 diff-config: ## Compares default configuration between two mattermost versions 561 @./scripts/diff-config.sh 562 563 clean: stop-docker ## Clean up everything except persistant server data. 564 @echo Cleaning 565 566 rm -Rf $(DIST_ROOT) 567 $(GO) clean $(GOFLAGS) -i ./... 568 569 cd $(BUILD_WEBAPP_DIR) && $(MAKE) clean 570 571 find . -type d -name data -not -path './vendor/*' | xargs rm -rf 572 rm -rf logs 573 574 rm -f mattermost.log 575 rm -f mattermost.log.jsonl 576 rm -f npm-debug.log 577 rm -f .prepare-go 578 rm -f enterprise 579 rm -f cover.out 580 rm -f ecover.out 581 rm -f *.out 582 rm -f *.test 583 rm -f imports/imports.go 584 rm -f cmd/mattermost/cprofile*.out 585 586 nuke: clean clean-docker ## Clean plus removes persistent server data. 587 @echo BOOM 588 589 rm -rf data 590 591 setup-mac: ## Adds macOS hosts entries for Docker. 592 echo $$(boot2docker ip 2> /dev/null) dockerhost | sudo tee -a /etc/hosts 593 594 update-dependencies: ## Uses go get -u to update all the dependencies while holding back any that require it. 595 @echo Updating Dependencies 596 597 # Update all dependencies (does not update across major versions) 598 $(GO) get -u ./... 599 600 # Tidy up 601 $(GO) mod tidy 602 603 # Copy everything to vendor directory 604 $(GO) mod vendor 605 606 # Tidy up 607 $(GO) mod tidy 608 609 vet: ## Run mattermost go vet specific checks 610 @if ! [ -x "$$(command -v $(GOBIN)/mattermost-govet)" ]; then \ 611 echo "mattermost-govet is not installed. Please install it executing \"GO111MODULE=off GOBIN=$(PWD)/bin go get -u github.com/mattermost/mattermost-govet\""; \ 612 exit 1; \ 613 fi; 614 @VET_CMD="-license -structuredLogging -inconsistentReceiverName -inconsistentReceiverName.ignore=session_serial_gen.go,team_member_serial_gen.go,user_serial_gen.go -emptyStrCmp -tFatal -configtelemetry -errorAssertions"; \ 615 if ! [ -z "${MM_VET_OPENSPEC_PATH}" ] && [ -f "${MM_VET_OPENSPEC_PATH}" ]; then \ 616 VET_CMD="$$VET_CMD -openApiSync -openApiSync.spec=$$MM_VET_OPENSPEC_PATH"; \ 617 else \ 618 echo "MM_VET_OPENSPEC_PATH not set or spec yaml path in it is incorrect. Skipping API check"; \ 619 fi; \ 620 $(GO) vet -vettool=$(GOBIN)/mattermost-govet $$VET_CMD ./... 621 ifeq ($(BUILD_ENTERPRISE_READY),true) 622 ifneq ($(MM_NO_ENTERPRISE_LINT),true) 623 $(GO) vet -vettool=$(GOBIN)/mattermost-govet -enterpriseLicense -structuredLogging -tFatal ./enterprise/... 624 endif 625 endif 626 627 gen-serialized: ## Generates serialization methods for hot structs 628 # This tool only works at a file level, not at a package level. 629 # There will be some warnings about "unresolved identifiers", 630 # but that is because of the above problem. Since we are generating 631 # methods for all the relevant files at a package level, all 632 # identifiers will be resolved. An alternative to remove the warnings 633 # would be to temporarily move all the structs to the same file, 634 # but that involves a lot of manual work. 635 $(GO) get -modfile=go.tools.mod github.com/tinylib/msgp 636 $(GOBIN)/msgp -file=./model/session.go -tests=false -o=./model/session_serial_gen.go 637 $(GOBIN)/msgp -file=./model/user.go -tests=false -o=./model/user_serial_gen.go 638 $(GOBIN)/msgp -file=./model/team_member.go -tests=false -o=./model/team_member_serial_gen.go 639 640 todo: ## Display TODO and FIXME items in the source code. 641 @! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime TODO 642 @! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime XXX 643 @! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime FIXME 644 @! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime "FIX ME" 645 ifeq ($(BUILD_ENTERPRISE_READY),true) 646 @! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime TODO enterprise/ 647 @! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime XXX enterprise/ 648 @! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime FIXME enterprise/ 649 @! ag --ignore Makefile --ignore-dir vendor --ignore-dir runtime "FIX ME" enterprise/ 650 endif 651 652 ## Help documentatin à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html 653 help: 654 @grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' ./Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' 655 @echo 656 @echo You can modify the default settings for this Makefile creating a file config.mk based on the default-config.mk 657 @echo