github.com/masterhung0112/hk_server/v5@v5.0.0-20220302090640-ec71aef15e1c/Makefile (about)

     1  .PHONY: build package run stop run-client run-server run-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 ?= ../hungknow-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  # Go Flags
    70  GOFLAGS ?= $(GOFLAGS:)
    71  # We need to export GOBIN to allow it to be set
    72  # for processes spawned from the Makefile
    73  export GOBIN ?= $(PWD)/bin
    74  GO ?= /usr/local/go/bin/go
    75  
    76  LDFLAGS += -X "github.com/masterhung0112/hk_server/v5/model.BuildNumber=$(BUILD_NUMBER)"
    77  LDFLAGS += -X "github.com/masterhung0112/hk_server/v5/model.BuildDate=$(BUILD_DATE)"
    78  LDFLAGS += -X "github.com/masterhung0112/hk_server/v5/model.BuildHash=$(BUILD_HASH)"
    79  LDFLAGS += -X "github.com/masterhung0112/hk_server/v5/model.BuildHashEnterprise=$(BUILD_HASH_ENTERPRISE)"
    80  LDFLAGS += -X "github.com/masterhung0112/hk_server/v5/model.BuildEnterpriseReady=$(BUILD_ENTERPRISE_READY)"
    81  
    82  GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
    83  GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
    84  MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
    85  MINIMUM_SUPPORTED_GO_MINOR_VERSION = 15
    86  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)
    87  
    88  # GOOS/GOARCH of the build host, used to determine whether we're cross-compiling or not
    89  BUILDER_GOOS_GOARCH="$(shell $(GO) env GOOS)_$(shell $(GO) env GOARCH)"
    90  
    91  PLATFORM_FILES="./cmd/hkserver/main.go"
    92  
    93  # Output paths
    94  DIST_ROOT=dist
    95  DIST_PATH=$(DIST_ROOT)/hkserver
    96  
    97  # Tests
    98  TESTS=.
    99  
   100  # Packages lists
   101  TE_PACKAGES=$(shell $(GO) list ./... | grep -v ./data)
   102  
   103  TEMPLATES_DIR=templates
   104  
   105  # Plugins Packages
   106  PLUGIN_PACKAGES ?= mattermost-plugin-antivirus-v0.1.2
   107  PLUGIN_PACKAGES += mattermost-plugin-autolink-v1.2.2
   108  PLUGIN_PACKAGES += mattermost-plugin-aws-SNS-v1.2.0
   109  PLUGIN_PACKAGES += mattermost-plugin-channel-export-v0.2.2
   110  PLUGIN_PACKAGES += mattermost-plugin-custom-attributes-v1.3.0
   111  PLUGIN_PACKAGES += mattermost-plugin-github-v2.0.1
   112  PLUGIN_PACKAGES += mattermost-plugin-gitlab-v1.3.0
   113  PLUGIN_PACKAGES += mattermost-plugin-incident-collaboration-v1.12.0
   114  PLUGIN_PACKAGES += mattermost-plugin-jenkins-v1.1.0
   115  PLUGIN_PACKAGES += mattermost-plugin-jira-v2.4.0
   116  PLUGIN_PACKAGES += mattermost-plugin-nps-v1.1.0
   117  PLUGIN_PACKAGES += mattermost-plugin-welcomebot-v1.2.0
   118  PLUGIN_PACKAGES += mattermost-plugin-zoom-v1.5.0
   119  PLUGIN_PACKAGES += focalboard-v0.6.7-plugin
   120  
   121  # Prepares the enterprise build if exists. The IGNORE stuff is a hack to get the Makefile to execute the commands outside a target
   122  ifeq ($(BUILD_ENTERPRISE_READY),true)
   123  	IGNORE:=$(shell echo Enterprise build selected, preparing)
   124  	IGNORE:=$(shell rm -f imports/imports.go)
   125  	IGNORE:=$(shell cp $(BUILD_ENTERPRISE_DIR)/imports/imports.go imports/)
   126  	IGNORE:=$(shell rm -f enterprise)
   127  	IGNORE:=$(shell ln -s $(BUILD_ENTERPRISE_DIR) enterprise)
   128  else
   129  	IGNORE:=$(shell rm -f imports/imports.go)
   130  endif
   131  
   132  EE_PACKAGES=$(shell $(GO) list ./enterprise/...)
   133  
   134  ifeq ($(BUILD_ENTERPRISE_READY),true)
   135  ALL_PACKAGES=$(TE_PACKAGES) $(EE_PACKAGES)
   136  else
   137  ALL_PACKAGES=$(TE_PACKAGES)
   138  endif
   139  
   140  all: run ## Alias for 'run'.
   141  
   142  -include config.override.mk
   143  include config.mk
   144  include build/*.mk
   145  
   146  LDFLAGS += -X "github.com/masterhung0112/hk_server/v5/model.MockCWS=$(MM_ENABLE_CWS_MOCK)"
   147  RUN_IN_BACKGROUND ?=
   148  ifeq ($(RUN_SERVER_IN_BACKGROUND),true)
   149  	RUN_IN_BACKGROUND := &
   150  endif
   151  
   152  start-docker-check:
   153  ifeq (,$(findstring minio,$(ENABLED_DOCKER_SERVICES)))
   154    TEMP_DOCKER_SERVICES:=$(TEMP_DOCKER_SERVICES) minio
   155  endif
   156  ifeq ($(BUILD_ENTERPRISE_READY),true)
   157    ifeq (,$(findstring openldap,$(ENABLED_DOCKER_SERVICES)))
   158      TEMP_DOCKER_SERVICES:=$(TEMP_DOCKER_SERVICES) openldap
   159    endif
   160    ifeq (,$(findstring elasticsearch,$(ENABLED_DOCKER_SERVICES)))
   161      TEMP_DOCKER_SERVICES:=$(TEMP_DOCKER_SERVICES) elasticsearch
   162    endif
   163  endif
   164  ENABLED_DOCKER_SERVICES:=$(ENABLED_DOCKER_SERVICES) $(TEMP_DOCKER_SERVICES)
   165  
   166  start-docker: ## Starts the docker containers for local development.
   167  ifneq ($(IS_CI),false)
   168  	@echo CI Build: skipping docker start
   169  else ifeq ($(MM_NO_DOCKER),true)
   170  	@echo No Docker Enabled: skipping docker start
   171  else
   172  	@echo Starting docker containers
   173  
   174  	$(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
   175  ifneq (,$(findstring openldap,$(ENABLED_DOCKER_SERVICES)))
   176  	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';
   177  endif
   178  ifneq (,$(findstring mysql-read-replica,$(ENABLED_DOCKER_SERVICES)))
   179  	./scripts/replica-mysql-config.sh
   180  endif
   181  endif
   182  
   183  run-haserver:
   184  ifeq ($(BUILD_ENTERPRISE_READY),true)
   185  	@echo Starting mattermost in an HA topology '(3 node cluster)'
   186  
   187  	docker-compose -f docker-compose.yaml up --remove-orphans haproxy
   188  endif
   189  stop-haserver:
   190  	@echo Stopping docker containers for HA topology
   191  	docker-compose stop
   192  
   193  stop-docker: ## Stops the docker containers for local development.
   194  ifeq ($(MM_NO_DOCKER),true)
   195  	@echo No Docker Enabled: skipping docker stop
   196  else
   197  	@echo Stopping docker containers
   198  
   199  	docker-compose stop
   200  endif
   201  clean-docker: ## Deletes the docker containers for local development.
   202  ifeq ($(MM_NO_DOCKER),true)
   203  	@echo No Docker Enabled: skipping docker clean
   204  else
   205  	@echo Removing docker containers
   206  
   207  	docker-compose down -v
   208  	docker-compose rm -v
   209  endif
   210  
   211  plugin-checker:
   212  	$(GO) run $(GOFLAGS) ./plugin/checker
   213  
   214  prepackaged-plugins: ## Populate the prepackaged-plugins directory
   215  	@echo Downloading prepackaged plugins
   216  	mkdir -p prepackaged_plugins
   217  	@cd prepackaged_plugins && for plugin_package in $(PLUGIN_PACKAGES) ; do \
   218  		curl -f -O -L https://plugins-store.test.mattermost.com/release/$$plugin_package.tar.gz; \
   219  		curl -f -O -L https://plugins-store.test.mattermost.com/release/$$plugin_package.tar.gz.sig; \
   220  	done
   221  
   222  prepackaged-binaries: ## Populate the prepackaged-binaries to the bin directory
   223  ifeq ($(shell test -f bin/mmctl && printf "yes"),yes)
   224  	@echo "MMCTL already exists in bin/mmctl not downloading a new version."
   225  else
   226  	@scripts/download_mmctl_release.sh
   227  endif
   228  
   229  golangci-lint: ## Run golangci-lint on codebase
   230  # https://stackoverflow.com/a/677212/1027058 (check if a command exists or not)
   231  	@if ! [ -x "$$(command -v golangci-lint)" ]; then \
   232  		echo "golangci-lint is not installed. Please see https://github.com/golangci/golangci-lint#install for installation instructions."; \
   233  		exit 1; \
   234  	fi; \
   235  
   236  	@echo Running golangci-lint
   237  	golangci-lint run ./...
   238  ifeq ($(BUILD_ENTERPRISE_READY),true)
   239  ifneq ($(MM_NO_ENTERPRISE_LINT),true)
   240  	golangci-lint run ./enterprise/...
   241  endif
   242  endif
   243  
   244  app-layers: ## Extract interface from App struct
   245  	$(GO) get -modfile=go.tools.mod github.com/reflog/struct2interface
   246  	$(GOBIN)/struct2interface -f "app" -o "app/app_iface.go" -p "app" -s "App" -i "AppIface" -t ./app/layer_generators/app_iface.go.tmpl
   247  	$(GO) run ./app/layer_generators -in ./app/app_iface.go -out ./app/opentracing/opentracing_layer.go -template ./app/layer_generators/opentracing_layer.go.tmpl
   248  
   249  i18n-extract: ## Extract strings for translation from the source code
   250  	$(GO) get -modfile=go.tools.mod github.com/mattermost/mattermost-utilities/mmgotool
   251  	$(GOBIN)/mmgotool i18n extract --portal-dir=""
   252  
   253  i18n-check: ## Exit on empty translation strings and translation source strings
   254  	$(GO) get -modfile=go.tools.mod github.com/mattermost/mattermost-utilities/mmgotool
   255  	$(GOBIN)/mmgotool i18n clean-empty --portal-dir="" --check
   256  	$(GOBIN)/mmgotool i18n check-empty-src --portal-dir=""
   257  
   258  store-mocks: ## Creates mock files.
   259  	$(GO) get -modfile=go.tools.mod github.com/vektra/mockery/...
   260  	$(GOBIN)/mockery -dir store -all -output store/storetest/mocks -note 'Regenerate this file using `make store-mocks`.'
   261  telemetry-mocks: ## Creates mock files.
   262  	$(GO) get -modfile=go.tools.mod github.com/vektra/mockery/...
   263  	$(GOBIN)/mockery -dir services/telemetry -all -output services/telemetry/mocks -note 'Regenerate this file using `make telemetry-mocks`.'
   264  
   265  store-layers: ## Generate layers for the store
   266  	$(GO) generate $(GOFLAGS) ./store
   267  migration-prereqs: ## Builds prerequisite packages for migrations
   268  	$(GO) get -modfile=go.tools.mod github.com/golang-migrate/migrate/v4/cmd/migrate
   269  
   270  new-migration: migration-prereqs ## Creates a new migration
   271  	@echo "Generating new migration for mysql"
   272  	$(GOBIN)/migrate create -ext sql -dir db/migrations/mysql -seq $(name)
   273  
   274  	@echo "Generating new migration for postgres"
   275  	$(GOBIN)/migrate create -ext sql -dir db/migrations/postgres -seq $(name)
   276  
   277  	@echo "When you are done writing your migration, run 'make migrations'"
   278  
   279  migrations-bindata: ## Generates bindata migrations
   280  	$(GO) get -modfile=go.tools.mod github.com/go-bindata/go-bindata/...
   281  
   282  	@echo Generating bindata for migrations
   283  	$(GO) generate $(GOFLAGS) ./db/migrations/
   284  
   285  filestore-mocks: ## Creates mock files.
   286  	$(GO) get -modfile=go.tools.mod github.com/vektra/mockery/...
   287  	$(GOBIN)/mockery -dir shared/filestore -all -output shared/filestore/mocks -note 'Regenerate this file using `make filestore-mocks`.'
   288  
   289  ldap-mocks: ## Creates mock files for ldap.
   290  	$(GO) get -modfile=go.tools.mod github.com/vektra/mockery/...
   291  	$(GOBIN)/mockery -dir enterprise/ldap -all -output enterprise/ldap/mocks -note 'Regenerate this file using `make ldap-mocks`.'
   292  
   293  plugin-mocks: ## Creates mock files for plugins.
   294  	$(GO) get -modfile=go.tools.mod github.com/vektra/mockery/...
   295  	$(GOBIN)/mockery -dir plugin -name API -output plugin/plugintest -outpkg plugintest -case underscore -note 'Regenerate this file using `make plugin-mocks`.'
   296  	$(GOBIN)/mockery -dir plugin -name Hooks -output plugin/plugintest -outpkg plugintest -case underscore -note 'Regenerate this file using `make plugin-mocks`.'
   297  	$(GOBIN)/mockery -dir plugin -name Helpers -output plugin/plugintest -outpkg plugintest -case underscore -note 'Regenerate this file using `make plugin-mocks`.'
   298  
   299  einterfaces-mocks: ## Creates mock files for einterfaces.
   300  	$(GO) get -modfile=go.tools.mod github.com/vektra/mockery/...
   301  	$(GOBIN)/mockery -dir einterfaces -all -output einterfaces/mocks -note 'Regenerate this file using `make einterfaces-mocks`.'
   302  
   303  searchengine-mocks: ## Creates mock files for searchengines.
   304  	$(GO) get -modfile=go.tools.mod github.com/vektra/mockery/...
   305  	$(GOBIN)/mockery -dir services/searchengine -all -output services/searchengine/mocks -note 'Regenerate this file using `make searchengine-mocks`.'
   306  
   307  sharedchannel-mocks: ## Creates mock files for shared channels.
   308  	$(GO) get -modfile=go.tools.mod github.com/vektra/mockery/...
   309  	$(GOBIN)/mockery -dir=./services/sharedchannel -name=ServerIface -output=./services/sharedchannel -inpkg -outpkg=sharedchannel -testonly -note 'Regenerate this file using `make sharedchannel-mocks`.'
   310  	$(GOBIN)/mockery -dir=./services/sharedchannel -name=AppIface -output=./services/sharedchannel -inpkg -outpkg=sharedchannel -testonly -note 'Regenerate this file using `make sharedchannel-mocks`.'
   311  pluginapi: ## Generates api and hooks glue code for plugins
   312  	$(GO) generate $(GOFLAGS) ./plugin
   313  
   314  check-prereqs: ## Checks prerequisite software status.
   315  	./scripts/prereq-check.sh
   316  
   317  check-prereqs-enterprise: ## Checks prerequisite software status for enterprise.
   318  ifeq ($(BUILD_ENTERPRISE_READY),true)
   319  	./scripts/prereq-check-enterprise.sh
   320  endif
   321  
   322  check-style: golangci-lint plugin-checker vet ## Runs style/lint checks
   323  
   324  
   325  do-cover-file: ## Creates the test coverage report file.
   326  	@echo "mode: count" > cover.out
   327  
   328  go-junit-report:
   329  	$(GO) get -modfile=go.tools.mod github.com/jstemmer/go-junit-report
   330  
   331  test-compile: ## Compile tests.
   332  	@echo COMPILE TESTS
   333  
   334  	for package in $(TE_PACKAGES) $(EE_PACKAGES); do \
   335  		$(GO) test $(GOFLAGS) -c $$package; \
   336  	done
   337  
   338  test-db-migration: start-docker ## Gets diff of upgrade vs new instance schemas.
   339  	./scripts/mysql-migration-test.sh
   340  	./scripts/psql-migration-test.sh
   341  
   342  gomodtidy:
   343  	@cp go.mod go.mod.orig
   344  	@cp go.sum go.sum.orig
   345  	$(GO) mod tidy
   346  	@if [ "$$(diff go.mod go.mod.orig)" != "" -o "$$(diff go.sum go.sum.orig)" != "" ]; then \
   347  		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\"."; \
   348  		rm go.*.orig; \
   349  		exit 1; \
   350  	fi;
   351  	@rm go.*.orig;
   352  
   353  test-server-pre: check-prereqs-enterprise start-docker-check start-docker go-junit-report do-cover-file ## Runs tests.
   354  ifeq ($(BUILD_ENTERPRISE_READY),true)
   355  	@echo Running all tests
   356  else
   357  	@echo Running only TE tests
   358  endif
   359  	./scripts/test.sh "$(GO)" "$(GOFLAGS)" "$(ALL_PACKAGES)" "$(TESTS)" "$(TESTFLAGS)" "$(GOBIN)"
   360    ifneq ($(IS_CI),true)
   361      ifneq ($(MM_NO_DOCKER),true)
   362        ifneq ($(TEMP_DOCKER_SERVICES),)
   363  	      @echo Stopping temporary docker services
   364  	      docker-compose stop $(TEMP_DOCKER_SERVICES)
   365        endif
   366      endif
   367    endif
   368  
   369  test-server-ci:
   370  	./scripts/test.sh "$(GO)" "$(GOFLAGS)" "$(ALL_PACKAGES)" "$(TESTS)" "$(TESTFLAGS)" "$(GOBIN)"