Skip to content

Commit

Permalink
Makefile Help (#1638)
Browse files Browse the repository at this point in the history
Signed-off-by: Ken Sipe <kensipe@gmail.com>
  • Loading branch information
kensipe authored Aug 12, 2020
1 parent 97a7558 commit 3be4d12
Showing 1 changed file with 76 additions and 46 deletions.
122 changes: 76 additions & 46 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@ SUPPORTED_PLATFORMS = amd64 arm64

export GO111MODULE=on

.PHONY: all
all: test manager
.PHONY: help
help: ## Show this help screen
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
@echo ''
@echo 'Available targets are:'
@echo ''
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)


##############################
# Tests #
##############################

##@ Tests

# Run unit tests
.PHONY: test
test:
test: ## Runs unit tests
ifdef _INTELLIJ_FORCE_SET_GOFLAGS
# Run tests from a Goland terminal. Goland already set '-mod=readonly'
go test ./pkg/... ./cmd/... -v -coverprofile cover.out
Expand All @@ -38,7 +50,7 @@ e2e-test: cli-fast manager-fast

.PHONY: integration-test
# Run integration tests
integration-test: cli-fast manager-fast
integration-test: cli-fast manager-fast ##Runs integration tests
TEST_ONLY=$(TEST) ./hack/run-integration-tests.sh

.PHONY: operator-test
Expand All @@ -51,11 +63,20 @@ upgrade-test: cli-fast manager-fast

.PHONY: test-clean
# Clean test reports
test-clean:
test-clean: ## cleans test outputs
rm -f cover.out cover-integration.out

##############################
# Development #
##############################

##@ Development

.PHONY: all
all: test manager ## Build manager and runs unit tests

.PHONY: lint
lint:
lint: ## Run golangci-lint
ifneq (${GOLANGCI_LINT_VER}, "$(shell golangci-lint --version 2>/dev/null | cut -b 27-32)")
./hack/install-golangcilint.sh
endif
Expand All @@ -70,11 +91,11 @@ prebuild: generate lint


# Build manager binary
manager: prebuild manager-fast
manager: prebuild manager-fast ## Builds manager

.PHONY: manager-fast
# Build manager binary
manager-fast:
manager-fast: ## Builds manager without code generation
# developer convenience for platform they are running
go build -ldflags "${LDFLAGS}" -o bin/$(EXECUTABLE) github.com/kudobuilder/kudo/cmd/manager

Expand All @@ -86,7 +107,7 @@ manager-clean:

.PHONY: run
# Run against the configured Kubernetes cluster in ~/.kube/config
run:
run: ## Runs Manager locally (requires ngrok or webhook management)
# for local development, webhooks are disabled by default
# if you enable them, you have to take care of providing the TLS certs locally
go run -ldflags "${LDFLAGS}" ./cmd/manager
Expand All @@ -96,9 +117,52 @@ run:
deploy:
go run -ldflags "${LDFLAGS}" ./cmd/kubectl-kudo init

.PHONY: cli
# Build CLI
cli: prebuild cli-fast ## Builds CLI with code generation

.PHONY: cli-clean
# Clean CLI build
cli-clean:
rm -f bin/${CLI}

# Install CLI
cli-install: ## Installs kubectl-kudo to GOBIN
go install -ldflags "${LDFLAGS}" ./cmd/kubectl-kudo

.PHONY: clean
# Clean all
clean: cli-clean test-clean manager-clean ## Cleans cli, tests and manager

# Build CLI but don't lint or run code generation first.
cli-fast:
go build -ldflags "${LDFLAGS}" -o bin/${CLI} ./cmd/kubectl-kudo

.PHONY: docker-build
# Build the docker image for each supported platform
docker-build: generate lint ## Docker Build (for dev only)
docker build --build-arg ldflags_arg="$(LDFLAGS)" -f Dockerfile -t $(DOCKER_IMG):$(DOCKER_TAG) .


# requires manifests. generate-manifests should be run first
# quickly sets a local dev env with the minimum necessary configurations to run
# the kudo manager locally. after running dev-ready, it is possible to 'make run' or run from an editor for debugging.
# it currently does require ngrok.
.PHONY: dev-ready
dev-ready: ## Installs KUDO manifests and updates webhook to work with ngrok
./hack/deploy-dev-prereqs.sh
./hack/update-webhook-config.sh


##############################
# Generate Artifacts #
##############################

##@ Generate

.PHONY: generate
# Generate code
generate:
generate: ## (Re)Generates CRDs and go-bindata
ifneq ($(shell go list -f '{{.Version}}' -m sigs.k8s.io/controller-tools), $(shell controller-gen --version 2>/dev/null | cut -b 10-))
@echo "(Re-)installing controller-gen. Current version: $(controller-gen --version 2>/dev/null | cut -b 10-). Need $(go list -f '{{.Version}}' -m sigs.k8s.io/controller-tools)"
go get sigs.k8s.io/controller-tools/cmd/controller-gen@$$(go list -f '{{.Version}}' -m sigs.k8s.io/controller-tools)
Expand All @@ -114,31 +178,6 @@ endif
generate-clean:
rm -rf ./hack/code-gen

# Build CLI but don't lint or run code generation first.
cli-fast:
go build -ldflags "${LDFLAGS}" -o bin/${CLI} ./cmd/kubectl-kudo

.PHONY: cli
# Build CLI
cli: prebuild cli-fast

.PHONY: cli-clean
# Clean CLI build
cli-clean:
rm -f bin/${CLI}

# Install CLI
cli-install:
go install -ldflags "${LDFLAGS}" ./cmd/kubectl-kudo

.PHONY: clean
# Clean all
clean: cli-clean test-clean manager-clean

.PHONY: docker-build
# Build the docker image for each supported platform
docker-build: generate lint
docker build --build-arg ldflags_arg="$(LDFLAGS)" -f Dockerfile -t $(DOCKER_IMG):$(DOCKER_TAG) .

.PHONY: imports
# used to update imports on project. NOT a linter.
Expand All @@ -152,7 +191,7 @@ endif
# used to update the golden files present in ./pkg/.../testdata
# example: make update-golden
# tests in update==true mode show as failures
update-golden:
update-golden: ## Updates golden files
go test ./pkg/... -v -mod=readonly --update=true

.PHONY: todo
Expand All @@ -171,7 +210,7 @@ todo:
# updating webhook requires ngrok to be running and updates the wh-config with the latest
# ngrok configuration. ngrok config changes for each restart which is why this is a separate target
.PHONY: update-webhook-config
update-webhook-config:
update-webhook-config: # Updates webhook when using ngrok
./hack/update-webhook-config.sh

# generates manifests from the kudo cli (kudo init) and captures the manifests needed for
Expand All @@ -180,12 +219,3 @@ update-webhook-config:
.PHONY: generate-manifests
generate-manifests:
./hack/update-manifests.sh

# requires manifests. generate-manifests should be run first
# quickly sets a local dev env with the minimum necessary configurations to run
# the kudo manager locally. after running dev-ready, it is possible to 'make run' or run from an editor for debugging.
# it currently does require ngrok.
.PHONY: dev-ready
dev-ready:
./hack/deploy-dev-prereqs.sh
./hack/update-webhook-config.sh

0 comments on commit 3be4d12

Please sign in to comment.