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