Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Makefile help #505

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ VERSION = 0.11.0
TAG = $(VERSION)
PREFIX = nginx/nginx-prometheus-exporter

.DEFAULT_GOAL:=help

.PHONY: help
help: Makefile ## Display this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "; printf "Usage:\n\n make \033[36m<target>\033[0m [VARIABLE=value...]\n\nTargets:\n\n"}; {printf " \033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: nginx-prometheus-exporter
nginx-prometheus-exporter:
nginx-prometheus-exporter: ## Build nginx-prometheus-exporter binary
CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X github.com/prometheus/common/version.Version=$(VERSION)" -o nginx-prometheus-exporter

.PHONY: build-goreleaser
Expand All @@ -12,26 +18,26 @@ build-goreleaser: ## Build all binaries using GoReleaser
GOPATH=$(shell go env GOPATH) goreleaser build --clean --snapshot

.PHONY: lint
lint:
lint: ## Run linter
docker run --pull always --rm -v $(shell pwd):/nginx-prometheus-exporter -w /nginx-prometheus-exporter -v $(shell go env GOCACHE):/cache/go -e GOCACHE=/cache/go -e GOLANGCI_LINT_CACHE=/cache/go -v $(shell go env GOPATH)/pkg:/go/pkg golangci/golangci-lint:latest golangci-lint --color always run

.PHONY: test
test:
test: ## Run tests
go test ./... -race -shuffle=on

.PHONY: container
container:
container: ## Build container image
docker build --build-arg VERSION=$(VERSION) --target container -f build/Dockerfile -t $(PREFIX):$(TAG) .

.PHONY: push
push: container
push: container ## Push container image
docker push $(PREFIX):$(TAG)

.PHONY: deps
deps:
deps: ## Add missing and remove unused modules, verify deps and download them to local cache
@go mod tidy && go mod verify && go mod download

.PHONY: clean
clean:
clean: ## Clean up
-rm -r dist
-rm nginx-prometheus-exporter