github.com/hashicorp/packer@v1.14.3/Makefile (about)

     1  TEST?=$(shell go list ./...)
     2  COUNT?=1
     3  VET?=$(shell go list ./...)
     4  
     5  ACC_TEST_BUILDERS?=all
     6  ACC_TEST_PROVISIONERS?=all
     7  # Get the current full sha from git
     8  GITSHA:=$(shell git rev-parse HEAD)
     9  # Get the current local branch name from git (if we can, this may be blank)
    10  GITBRANCH:=$(shell git symbolic-ref --short HEAD 2>/dev/null)
    11  GOOS=$(shell go env GOOS)
    12  GOARCH=$(shell go env GOARCH)
    13  GOPATH=$(shell go env GOPATH)
    14  
    15  # Get the git commit
    16  GIT_DIRTY=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true)
    17  GIT_COMMIT=$(shell git rev-parse --short HEAD)
    18  GIT_IMPORT=github.com/hashicorp/packer/version
    19  UNAME_S := $(shell uname -s)
    20  LDFLAGS=-s -w
    21  GOLDFLAGS=-X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT)$(GIT_DIRTY) $(LDFLAGS)
    22  
    23  export GOLDFLAGS
    24  
    25  .PHONY: bin checkversion ci ci-lint default install-build-deps install-gen-deps fmt fmt-docs fmt-examples generate install-lint-deps lint \
    26  	releasebin test testacc testrace version
    27  
    28  default: install-build-deps install-gen-deps generate dev
    29  
    30  ci: testrace ## Test in continuous integration
    31  
    32  release: install-build-deps test releasebin package ## Build a release build
    33  
    34  bin: install-build-deps ## Build debug/test build
    35  	@echo "WARN: 'make bin' is for debug / test builds only. Use 'make release' for release builds."
    36  	@GO111MODULE=auto sh -c "$(CURDIR)/scripts/build.sh"
    37  
    38  releasebin: install-build-deps
    39  	@grep 'const VersionPrerelease = "dev"' version/version.go > /dev/null ; if [ $$? -eq 0 ]; then \
    40  		echo "ERROR: You must remove prerelease tags from version/version.go prior to release."; \
    41  		exit 1; \
    42  	fi
    43  	@GO111MODULE=auto sh -c "$(CURDIR)/scripts/build.sh"
    44  
    45  package:
    46  	$(if $(VERSION),,@echo 'VERSION= needed to release; Use make package skip compilation'; exit 1)
    47  	@sh -c "$(CURDIR)/scripts/dist.sh $(VERSION)"
    48  
    49  install-build-deps: ## Install dependencies for bin build
    50  	@go install github.com/mitchellh/gox@v1.0.1
    51  
    52  install-gen-deps: ## Install dependencies for code generation
    53  	@GO111MODULE=on go install github.com/dmarkham/enumer@master
    54  	@go install github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc@latest
    55  
    56  install-lint-deps: ## Install linter dependencies
    57  	@echo "==> Updating linter dependencies..."
    58  	@curl -sSfL -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.64.8
    59  
    60  dev: ## Build and install a development build
    61  	@grep 'const VersionPrerelease = ""' version/version.go > /dev/null ; if [ $$? -eq 0 ]; then \
    62  		echo "ERROR: You must add prerelease tags to version/version.go prior to making a dev build."; \
    63  		exit 1; \
    64  	fi
    65  	@mkdir -p pkg/$(GOOS)_$(GOARCH)
    66  	@mkdir -p bin
    67  	@go install -ldflags '$(GOLDFLAGS)'
    68  	@cp $(GOPATH)/bin/packer bin/packer
    69  	@cp $(GOPATH)/bin/packer pkg/$(GOOS)_$(GOARCH)
    70  
    71  # Docker build variables and targets
    72  REGISTRY_NAME?=docker.io/hashicorp
    73  IMAGE_NAME=packer
    74  IMAGE_TAG_DEV=$(REGISTRY_NAME)/$(IMAGE_NAME):latest-$(GIT_COMMIT)
    75  
    76  docker: docker-dev
    77  
    78  # Builds from the locally generated binary in ./bin/
    79  # To generate the local binary, run `make dev`
    80  docker-dev:
    81  	@GOOS=linux \
    82  	GOARCH=amd64 \
    83  	CGO_ENABLED=0 \
    84  	go build -ldflags '$(GOLDFLAGS)' -o bin/packer .
    85  	@docker build \
    86  		--tag $(IMAGE_TAG_DEV) \
    87  		--target=dev \
    88  		.
    89  	@rm -f bin/packer # Clean up the Linux/amd64 binary to avoid conficts on other OS/archs
    90  
    91  lint: install-lint-deps ## Lint Go code
    92  	@if [ ! -z  $(PKG_NAME) ]; then \
    93  		echo "golangci-lint run ./$(PKG_NAME)/..."; \
    94  		golangci-lint run ./$(PKG_NAME)/...; \
    95  	else \
    96  		echo "golangci-lint run ./..."; \
    97  		golangci-lint run ./...; \
    98  	fi
    99  
   100  ci-lint: install-lint-deps ## On ci only lint newly added Go source files
   101  	@echo "==> Running linter on newly added Go source files..."
   102  	GO111MODULE=on golangci-lint run --new-from-rev=$(shell git merge-base origin/main HEAD) ./...
   103  
   104  fmt: ## Format Go code
   105  	@go fmt ./...
   106  
   107  fmt-check: fmt ## Check go code formatting
   108  	@echo "==> Checking that code complies with go fmt requirements..."
   109  	@git diff --exit-code; if [ $$? -eq 1 ]; then \
   110  		echo "Found files that are not fmt'ed."; \
   111  		echo "You can use the command: \`make fmt\` to reformat code."; \
   112  		exit 1; \
   113  	fi
   114  
   115  fmt-docs:
   116  	@find ./website/pages/docs -name "*.md" -exec pandoc --wrap auto --columns 79 --atx-headers -s -f "markdown_github+yaml_metadata_block" -t "markdown_github+yaml_metadata_block" {} -o {} \;
   117  
   118  # Install js-beautify with npm install -g js-beautify
   119  fmt-examples:
   120  	find examples -name *.json | xargs js-beautify -r -s 2 -n -eol "\n"
   121  
   122  # generate runs `go generate` to build the dynamically generated
   123  # source files.
   124  generate: install-gen-deps ## Generate dynamically generated code
   125  	@echo "==> removing autogenerated markdown..." # but don't remove partials generated in the SDK and copied over.
   126  	@find website/pages -path website/pages/partials/packer-plugin-sdk -prune -o -type f | xargs grep -l '^<!-- Code generated' | xargs rm -f
   127  	@echo "==> removing autogenerated code..."
   128  	@find post-processor helper builder provisioner -type f | xargs grep -l '^// Code generated' | xargs rm -f
   129  	PROJECT_ROOT="$(shell pwd)" go generate $(shell go list ./... | grep -v packer-plugin-sdk)
   130  
   131  generate-check: generate ## Check go code generation is on par
   132  	@echo "==> Checking that auto-generated code is not changed..."
   133  	@git diff --exit-code; if [ $$? -eq 1 ]; then \
   134  		echo "Found diffs in go generated code."; \
   135  		echo "You can use the command: \`make generate\` to reformat code."; \
   136  		exit 1; \
   137  	fi
   138  
   139  test: vet ## Run unit tests
   140  	@go test -count $(COUNT) $(TEST) $(TESTARGS) -timeout=3m
   141  
   142  # acctest runs provisioners acceptance tests
   143  provisioners-acctest: #install-build-deps generate
   144  	ACC_TEST_BUILDERS=$(ACC_TEST_BUILDERS) go test $(TEST) $(TESTARGS) -timeout=1h
   145  
   146  # testacc runs acceptance tests
   147  testacc: # install-build-deps generate ## Run acceptance tests
   148  	@echo "WARN: Acceptance tests will take a long time to run and may cost money. Ctrl-C if you want to cancel."
   149  	PACKER_ACC=1 go test -count $(COUNT) -v $(TEST) $(TESTARGS) -timeout=120m
   150  
   151  testrace: vet ## Test with race detection enabled
   152  	@go test -count $(COUNT) -race $(TEST) $(TESTARGS) -timeout=3m -p=8
   153  
   154  # Runs code coverage and open a html page with report
   155  cover:
   156  	go test -count $(COUNT) $(TEST) $(TESTARGS) -timeout=3m -coverprofile=coverage.out
   157  	go tool cover -html=coverage.out
   158  	rm coverage.out
   159  
   160  vet: ## Vet Go code
   161  	@go vet $(VET)  ; if [ $$? -eq 1 ]; then \
   162  		echo "ERROR: Vet found problems in the code."; \
   163  		exit 1; \
   164  	fi
   165  
   166  help:
   167  	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
   168