Skip to content

Commit

Permalink
Add verbose make help (#123)
Browse files Browse the repository at this point in the history
Signed-off-by: Micah Hausler <[email protected]>

## Description

Enable verbose `make help` output and re-arrange some targets. This uses the help formatting from [kubebuilder](https://github.com/kubernetes-sigs/kubebuilder/blob/028566615757f423b09872b18bab189a65de2b3d/testdata/project-v2/Makefile#L30-L32) 

Before
```
$ make help
buf-lint                       run linting
build                          compile the binary for the native OS
cover                          Run unit tests with coverage report
darwin                         complie for darwin
evans                          run evans grpc client
goimports-ci                   run goimports for ci
goimports                      run goimports
image                          make the Container Image
linux                          complie for linux
pbs-docker-image               generate container image for building protocol buffers 
pbs-docker                     generate go stubs from protocol buffers in a container
pbs-install-deps               locally install dependencies in order to generate go stubs from protocol buffers
pbs                            locally generate go stubs from protocol buffers
ruby-client-demo               run ruby client demo
run-image                      run PBnJ container image
run-server                     run server locally
test-ci                        run tests for ci and codecov
test-functional                run functional tests
test                           run tests
```

after
```
$ make help

Usage:
  make <target>
  help             Display this help.

Build
  darwin           complie for darwin
  linux            complie for linux
  build            compile the binary for the native OS
  image            make the Container Image

Development
  test             run tests
  test-ci          run tests for ci and codecov
  test-functional  run functional tests
  goimports-ci     run goimports for ci
  goimports        run goimports
  cover            Run unit tests with coverage report
  buf-lint         run linting
  run-server       run server locally
  pbs              locally generate go stubs from protocol buffers
  pbs-install-deps  locally install dependencies in order to generate go stubs from protocol buffers
  pbs-docker       generate go stubs from protocol buffers in a container
  pbs-docker-image  generate container image for building protocol buffers
  run-image        run PBnJ container image

Clients
  ruby-client-demo  run ruby client demo
  evans            run evans grpc client

```

## Why is this needed

Working on #121, the kube-bulider generated make targets can be viewed in their own sections 

## How Has This Been Tested?

N/A

## How are existing users impacted? What migration steps/scripts do we need?

No Change

## Checklist:

I have:

- [ ] updated the documentation and/or roadmap (if required)
- [ ] added unit or e2e tests
- [ ] provided instructions on how to upgrade
  • Loading branch information
mergify[bot] authored Apr 11, 2022
2 parents 276cf3e + 095eb55 commit d919dd5
Showing 1 changed file with 41 additions and 35 deletions.
76 changes: 41 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,33 @@ GIT_COMMIT:=$(shell git rev-parse --short HEAD)
BUILD_ARGS:=GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags '-s -w -extldflags "-static"'
PROTOBUF_BUILDER_IMG:=pbnj-protobuf-builder

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

##@ Build

.PHONY: darwin
darwin: ## complie for darwin
GOOS=darwin ${BUILD_ARGS} -o bin/${BINARY}-darwin-amd64 main.go

.PHONY: linux
linux: ## complie for linux
GOOS=linux ${BUILD_ARGS} -o bin/${BINARY}-linux-amd64 main.go

.PHONY: build
build: ## compile the binary for the native OS
ifeq (${OSFLAG},linux)
@$(MAKE) linux
else
@$(MAKE) darwin
endif

.PHONY: image
image: ## make the Container Image
docker build -t pbnj:local .

##@ Development

.PHONY: test
test: ## run tests
Expand Down Expand Up @@ -43,22 +68,6 @@ buf-lint: ## run linting
@echo be sure buf is installed: https://buf.build/docs/installation
buf check lint

.PHONY: darwin
darwin: ## complie for darwin
GOOS=darwin ${BUILD_ARGS} -o bin/${BINARY}-darwin-amd64 main.go

.PHONY: linux
linux: ## complie for linux
GOOS=linux ${BUILD_ARGS} -o bin/${BINARY}-linux-amd64 main.go

.PHONY: build
build: ## compile the binary for the native OS
ifeq (${OSFLAG},linux)
@$(MAKE) linux
else
@$(MAKE) darwin
endif

PHONY: run-server
run-server: ## run server locally
ifeq (, $(shell which jq))
Expand All @@ -80,29 +89,13 @@ pbs-docker: pbs-docker-image ## generate go stubs from protocol buffers in a con
docker run -it --rm -v ${PWD}:/code -w /code ${PROTOBUF_BUILDER_IMG} scripts/protoc.sh

.PHONY: pbs-docker-image
pbs-docker-image: ## generate container image for building protocol buffers
pbs-docker-image: ## generate container image for building protocol buffers
docker build -t ${PROTOBUF_BUILDER_IMG} -f scripts/Dockerfile.pbbuilder .

.PHONY: image
image: ## make the Container Image
docker build -t pbnj:local .

.PHONY: run-image
run-image: ## run PBnJ container image
scripts/run-image.sh


.PHONY: ruby-client-demo
ruby-client-demo: image ## run ruby client demo
# make ruby-client-demo host=10.10.10.10 user=ADMIN pass=ADMIN
docker run -d --name pbnj pbnj:local
docker run -it --rm --net container:pbnj -v ${PWD}:/code -w /code/examples/clients/ruby --entrypoint /bin/bash ruby /code/examples/clients/ruby/demo.sh ${host} ${user} ${pass}
docker rm -f pbnj

.PHONY: evans
evans: ## run evans grpc client
evans --path $$(go env GOMODCACHE) --path . --proto $$(find api/v1 -type f -name '*.proto'| xargs | tr " " ",") -p "$${PBNJ_PORT:-50051}" repl

# BEGIN: lint-install .
# http://github.com/tinkerbell/lint-install

Expand Down Expand Up @@ -143,3 +136,16 @@ out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH):
mv out/linters/golangci-lint out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH)

# END: lint-install .

##@ Clients

.PHONY: ruby-client-demo
ruby-client-demo: image ## run ruby client demo
# make ruby-client-demo host=10.10.10.10 user=ADMIN pass=ADMIN
docker run -d --name pbnj pbnj:local
docker run -it --rm --net container:pbnj -v ${PWD}:/code -w /code/examples/clients/ruby --entrypoint /bin/bash ruby /code/examples/clients/ruby/demo.sh ${host} ${user} ${pass}
docker rm -f pbnj

.PHONY: evans
evans: ## run evans grpc client
evans --path $$(go env GOMODCACHE) --path . --proto $$(find api/v1 -type f -name '*.proto'| xargs | tr " " ",") -p "$${PBNJ_PORT:-50051}" repl

0 comments on commit d919dd5

Please sign in to comment.