github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/GNUmakefile (about)

     1  SHELL = bash
     2  PROJECT_ROOT := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
     3  THIS_OS := $(shell uname)
     4  
     5  GIT_COMMIT := $(shell git rev-parse HEAD)
     6  GIT_DIRTY := $(if $(shell git status --porcelain),+CHANGES)
     7  
     8  GO_LDFLAGS := "-X github.com/hashicorp/nomad/version.GitCommit=$(GIT_COMMIT)$(GIT_DIRTY)"
     9  GO_TAGS =
    10  
    11  default: help
    12  
    13  ifeq (,$(findstring $(THIS_OS),Darwin Linux FreeBSD))
    14  $(error Building Nomad is currently only supported on Darwin and Linux.)
    15  endif
    16  
    17  # On Linux we build for Linux, Windows, and potentially Linux+LXC
    18  ifeq (Linux,$(THIS_OS))
    19  
    20  # Detect if we have LXC on the path
    21  ifeq (0,$(shell pkg-config --exists lxc; echo $$?))
    22  HAS_LXC="true"
    23  endif
    24  
    25  ALL_TARGETS += linux_386 \
    26  	linux_amd64 \
    27  	linux_arm \
    28  	linux_arm64 \
    29  	windows_386 \
    30  	windows_amd64
    31  
    32  ifeq ("true",$(HAS_LXC))
    33  ALL_TARGETS += linux_amd64-lxc
    34  endif
    35  endif
    36  
    37  # On MacOS, we only build for MacOS
    38  ifeq (Darwin,$(THIS_OS))
    39  ALL_TARGETS += darwin_amd64
    40  endif
    41  
    42  # On FreeBSD, we only build for FreeBSD
    43  ifeq (FreeBSD,$(THIS_OS))
    44  ALL_TARGETS += freebsd_amd64
    45  endif
    46  
    47  pkg/darwin_amd64/nomad: $(SOURCE_FILES) ## Build Nomad for darwin/amd64
    48  	@echo "==> Building $@ with tags $(GO_TAGS)..."
    49  	@CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 \
    50  		go build \
    51  		-ldflags $(GO_LDFLAGS) \
    52  		-tags "$(GO_TAGS)" \
    53  		-o "$@"
    54  
    55  pkg/freebsd_amd64/nomad: $(SOURCE_FILES) ## Build Nomad for freebsd/amd64
    56  	@echo "==> Building $@..."
    57  	@CGO_ENABLED=1 GOOS=freebsd GOARCH=amd64 \
    58  		go build \
    59  		-ldflags $(GO_LDFLAGS) \
    60  		-tags "$(GO_TAGS)" \
    61  		-o "$@"
    62  
    63  pkg/linux_386/nomad: $(SOURCE_FILES) ## Build Nomad for linux/386
    64  	@echo "==> Building $@ with tags $(GO_TAGS)..."
    65  	@CGO_ENABLED=1 GOOS=linux GOARCH=386 \
    66  		go build \
    67  		-ldflags $(GO_LDFLAGS) \
    68  		-tags "$(GO_TAGS)" \
    69  		-o "$@"
    70  
    71  pkg/linux_amd64/nomad: $(SOURCE_FILES) ## Build Nomad for linux/amd64
    72  	@echo "==> Building $@ with tags $(GO_TAGS)..."
    73  	@CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \
    74  		go build \
    75  		-ldflags $(GO_LDFLAGS) \
    76  		-tags "$(GO_TAGS)" \
    77  		-o "$@"
    78  
    79  pkg/linux_arm/nomad: $(SOURCE_FILES) ## Build Nomad for linux/arm
    80  	@echo "==> Building $@ with tags $(GO_TAGS)..."
    81  	@CGO_ENABLED=1 GOOS=linux GOARCH=arm CC=arm-linux-gnueabihf-gcc-5 \
    82  		go build \
    83  		-ldflags $(GO_LDFLAGS) \
    84  		-tags "$(GO_TAGS)" \
    85  		-o "$@"
    86  
    87  pkg/linux_arm64/nomad: $(SOURCE_FILES) ## Build Nomad for linux/arm64
    88  	@echo "==> Building $@ with tags $(GO_TAGS)..."
    89  	@CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc-5 \
    90  		go build \
    91  		-ldflags $(GO_LDFLAGS) \
    92  		-tags "$(GO_TAGS)" \
    93  		-o "$@"
    94  
    95  # If CGO support for Windows is ever required, set the following variables
    96  # in the environment for `go build` for both the windows/amd64 and the
    97  # windows/386 targets:
    98  #	CC=i686-w64-mingw32-gcc
    99  #	CXX=i686-w64-mingw32-g++
   100  pkg/windows_386/nomad: $(SOURCE_FILES) ## Build Nomad for windows/386
   101  	@echo "==> Building $@ with tags $(GO_TAGS)..."
   102  	@CGO_ENABLED=1 GOOS=windows GOARCH=386 \
   103  		go build \
   104  		-ldflags $(GO_LDFLAGS) \
   105  		-tags "$(GO_TAGS)" \
   106  		-o "$@.exe"
   107  
   108  pkg/windows_amd64/nomad: $(SOURCE_FILES) ## Build Nomad for windows/amd64
   109  	@echo "==> Building $@ with tags $(GO_TAGS)..."
   110  	@CGO_ENABLED=1 GOOS=windows GOARCH=amd64 \
   111  		go build \
   112  		-ldflags $(GO_LDFLAGS) \
   113  		-tags "$(GO_TAGS)" \
   114  		-o "$@.exe"
   115  
   116  pkg/linux_amd64-lxc/nomad: $(SOURCE_FILES) ## Build Nomad+LXC for linux/amd64
   117  	@echo "==> Building $@ with tags $(GO_TAGS)..."
   118  	@CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \
   119  		go build \
   120  		-ldflags $(GO_LDFLAGS) \
   121  		-tags "$(GO_TAGS) lxc" \
   122  		-o "$@"
   123  
   124  # Define package targets for each of the build targets we actually have on this system
   125  define makePackageTarget
   126  
   127  pkg/$(1).zip: pkg/$(1)/nomad
   128  	@echo "==> Packaging for $(1)..."
   129  	@zip -j pkg/$(1).zip pkg/$(1)/*
   130  
   131  endef
   132  
   133  # Reify the package targets
   134  $(foreach t,$(ALL_TARGETS),$(eval $(call makePackageTarget,$(t))))
   135  
   136  .PHONY: bootstrap
   137  bootstrap: deps lint-deps # Install all dependencies
   138  
   139  .PHONY: deps
   140  deps:  ## Install build and development dependencies
   141  	@echo "==> Updating build dependencies..."
   142  	go get -u github.com/kardianos/govendor
   143  	go get -u github.com/ugorji/go/codec/codecgen
   144  	go get -u github.com/jteeuwen/go-bindata/...
   145  	go get -u github.com/elazarl/go-bindata-assetfs/...
   146  	go get -u github.com/a8m/tree/cmd/tree
   147  
   148  .PHONY: lint-deps
   149  lint-deps: ## Install linter dependencies
   150  	@echo "==> Updating linter dependencies..."
   151  	go get -u github.com/alecthomas/gometalinter
   152  	gometalinter --install
   153  
   154  .PHONY: check
   155  check: ## Lint the source code
   156  	@echo "==> Linting source code..."
   157  	@gometalinter \
   158  		--deadline 10m \
   159  		--vendor \
   160  		--exclude='.*\.generated\.go' \
   161  		--exclude='.*bindata_assetfs\.go' \
   162  		--skip="ui/" \
   163  		--sort="path" \
   164  		--aggregate \
   165  		--enable-gc \
   166  		--disable-all \
   167  		--enable goimports \
   168  		--enable misspell \
   169  		--enable vet \
   170  		--enable deadcode \
   171  		--enable varcheck \
   172  		--enable ineffassign \
   173  		--enable structcheck \
   174  		--enable unconvert \
   175  		--enable gofmt \
   176  		./...
   177  	@echo "==> Spell checking website..."
   178  	@misspell -error -source=text website/source/
   179  
   180  .PHONY: checkscripts
   181  checkscripts: ## Lint shell scripts
   182  	@echo "==> Linting scripts..."
   183  	@shellcheck ./scripts/*
   184  
   185  generate: LOCAL_PACKAGES = $(shell go list ./... | grep -v '/vendor/')
   186  generate: ## Update generated code
   187  	@go generate $(LOCAL_PACKAGES)
   188  
   189  .PHONY: dev
   190  dev: GOOS=$(shell go env GOOS)
   191  dev: GOARCH=$(shell go env GOARCH)
   192  dev: GOPATH=$(shell go env GOPATH)
   193  dev: DEV_TARGET=pkg/$(GOOS)_$(GOARCH)$(if $(HAS_LXC),-lxc)/nomad
   194  dev: ## Build for the current development platform
   195  	@echo "==> Removing old development build..."
   196  	@rm -f $(PROJECT_ROOT)/$(DEV_TARGET)
   197  	@rm -f $(PROJECT_ROOT)/bin/nomad
   198  	@rm -f $(GOPATH)/bin/nomad
   199  	@$(MAKE) --no-print-directory \
   200  		$(DEV_TARGET) \
   201  		GO_TAGS="nomad_test $(NOMAD_UI_TAG)"
   202  	@mkdir -p $(PROJECT_ROOT)/bin
   203  	@mkdir -p $(GOPATH)/bin
   204  	@cp $(PROJECT_ROOT)/$(DEV_TARGET) $(PROJECT_ROOT)/bin/
   205  	@cp $(PROJECT_ROOT)/$(DEV_TARGET) $(GOPATH)/bin
   206  
   207  .PHONY: prerelease
   208  prerelease: GO_TAGS=ui
   209  prerelease: check generate ember-dist static-assets ## Generate all the static assets for a Nomad release
   210  
   211  .PHONY: release
   212  release: GO_TAGS=ui
   213  release: clean $(foreach t,$(ALL_TARGETS),pkg/$(t).zip) ## Build all release packages which can be built on this platform.
   214  	@echo "==> Results:"
   215  	@tree --dirsfirst $(PROJECT_ROOT)/pkg
   216  
   217  .PHONY: test
   218  test: ## Run the Nomad test suite and/or the Nomad UI test suite
   219  	@if [ ! $(SKIP_NOMAD_TESTS) ]; then \
   220  		make test-nomad; \
   221  		fi
   222  	@if [ $(RUN_UI_TESTS) ]; then \
   223  		make test-ui; \
   224  		fi
   225  
   226  .PHONY: test-nomad
   227  test-nomad: dev ## Run Nomad test suites
   228  	@echo "==> Running Nomad test suites:"
   229  	@NOMAD_TEST_RKT=1 \
   230  		go test \
   231  			-v \
   232  			-cover \
   233  			-timeout=900s \
   234  			-tags="nomad_test $(if $(HAS_LXC),lxc)" ./... >test.log ; echo $$? > exit-code
   235  	@echo "Exit code: $$(cat exit-code)" >> test.log
   236  	@grep -A1 -- '--- FAIL:' test.log || true
   237  	@grep '^FAIL' test.log || true
   238  	@grep -A10 'panic' test.log || true
   239  	@test "$$TRAVIS" == "true" && cat test.log || true
   240  	@if [ "$$(cat exit-code)" == "0" ] ; then echo "PASS" ; exit 0 ; else exit 1 ; fi
   241  
   242  .PHONY: clean
   243  clean: GOPATH=$(shell go env GOPATH)
   244  clean: ## Remove build artifacts
   245  	@echo "==> Cleaning build artifacts..."
   246  	@rm -rf "$(PROJECT_ROOT)/bin/"
   247  	@rm -rf "$(PROJECT_ROOT)/pkg/"
   248  	@rm -f "$(GOPATH)/bin/nomad"
   249  
   250  .PHONY: travis
   251  travis: ## Run Nomad test suites with output to prevent timeouts under Travis CI
   252  	@sh -C "$(PROJECT_ROOT)/scripts/travis.sh"
   253  
   254  .PHONY: testcluster
   255  testcluster: ## Bring up a Linux test cluster using Vagrant. Set PROVIDER if necessary.
   256  	vagrant up nomad-server01 \
   257  		nomad-server02 \
   258  		nomad-server03 \
   259  		nomad-client01 \
   260  		nomad-client02 \
   261  		nomad-client03 \
   262  		$(if $(PROVIDER),--provider $(PROVIDER))
   263  
   264  .PHONY: static-assets
   265  static-assets: ## Compile the static routes to serve alongside the API
   266  	@echo "--> Generating static assets"
   267  	@go-bindata-assetfs -pkg agent -prefix ui -modtime 1480000000 -tags ui ./ui/dist/...
   268  	@mv bindata_assetfs.go command/agent
   269  
   270  .PHONY: test-ui
   271  test-ui: ## Run Nomad UI test suite
   272  	@echo "--> Installing JavaScript assets"
   273  	@cd ui && yarn install
   274  	@cd ui && npm install phantomjs-prebuilt
   275  	@echo "--> Running ember tests"
   276  	@cd ui && phantomjs --version
   277  	@cd ui && npm test
   278  
   279  .PHONY: ember-dist
   280  ember-dist: ## Build the static UI assets from source
   281  	@echo "--> Installing JavaScript assets"
   282  	@cd ui && yarn install
   283  	@cd ui && npm rebuild node-sass
   284  	@echo "--> Building Ember application"
   285  	@cd ui && npm run build
   286  
   287  .PHONY: dev-ui
   288  dev-ui: ember-dist static-assets
   289  	@$(MAKE) NOMAD_UI_TAG="ui" dev ## Build a dev binary with the UI baked in
   290  
   291  HELP_FORMAT="    \033[36m%-25s\033[0m %s\n"
   292  .PHONY: help
   293  help: ## Display this usage information
   294  	@echo "Valid targets:"
   295  	@grep -E '^[^ ]+:.*?## .*$$' $(MAKEFILE_LIST) | \
   296  		sort | \
   297  		awk 'BEGIN {FS = ":.*?## "}; \
   298  			{printf $(HELP_FORMAT), $$1, $$2}'
   299  	@echo ""
   300  	@echo "This host will build the following targets if 'make release' is invoked:"
   301  	@echo $(ALL_TARGETS) | sed 's/^/    /'