[VOL-2875] Documentation update
Also, update the Makefile "help" target to self-generate from comments
Change-Id: I26d329a2838ea360f3b2c96d44357b9fb8c51b84
diff --git a/Makefile b/Makefile
index a46a2e6..6f257c0 100644
--- a/Makefile
+++ b/Makefile
@@ -56,32 +56,11 @@
GOLANGCI_LINT = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") -v gocache:/.cache -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-golangci-lint golangci-lint
HADOLINT = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-hadolint hadolint
-.PHONY: docker-build local-protos local-lib-go
-
-# This should to be the first and default target in this Makefile
-help:
- @echo "Usage: make [<target>]"
- @echo "where available targets are:"
- @echo ""
- @echo "clean : Removes any local filesystem artifacts generated by a build"
- @echo "distclean : Removes any local filesystem artifacts generated by a build or test run"
- @echo "build : Build all openolt adapter artifacts"
- @echo "docker-build : Build openolt adapter docker image"
- @echo "docker-build-profile : Build openolt adapter docker image with profiling enabled"
- @echo "docker-push : Push the docker images to an external repository"
- @echo "help : Print this help"
- @echo "lint : Run all lint targets"
- @echo "lint-dockerfile : Perform static analysis on Dockerfiles"
- @echo "lint-mod : Verify the Go dependencies"
- @echo "local-protos : Copies a local verison of the VOLTHA protos into the vendor directory"
- @echo "local-lib-go : Copies a local version of the VOTLHA dependencies into the vendor directory"
- @echo "sca : Runs various SCA through golangci-lint tool"
- @echo "test : Run unit tests, if any"
- @echo
+.PHONY: docker-build local-protos local-lib-go help
+.DEFAULT_GOAL := help
## Local Development Helpers
-
-local-protos:
+local-protos: ## Copies a local version of the voltha-protos dependency into the vendor directory
ifdef LOCAL_PROTOS
rm -rf vendor/github.com/opencord/voltha-protos/v3/go
mkdir -p vendor/github.com/opencord/voltha-protos/v3/go
@@ -89,39 +68,35 @@
rm -rf vendor/github.com/opencord/voltha-protos/v3/go/vendor
endif
-## Local Development Helpers
-local-lib-go:
+local-lib-go: ## Copies a local version of the voltha-lib-go dependency into the vendor directory
ifdef LOCAL_LIB_GO
mkdir -p vendor/github.com/opencord/voltha-lib-go/v3/pkg
cp -r ${LOCAL_LIB_GO}/pkg/* vendor/github.com/opencord/voltha-lib-go/v3/pkg/
endif
## Docker targets
+build: docker-build ## Alias for 'docker build'
-build: docker-build
-
-docker-build: local-protos local-lib-go
+docker-build: local-protos local-lib-go ## Build openolt adapter docker image
docker build $(DOCKER_BUILD_ARGS) -t ${ADAPTER_IMAGENAME} -f docker/Dockerfile.openolt .
-docker-build-profile: local-protos local-lib-go
+docker-build-profile: local-protos local-lib-go ## Build openolt adapter docker image with profiling enabled
docker build $(DOCKER_BUILD_ARGS) -t ${ADAPTER_IMAGENAME}-profile -f docker/Dockerfile.openolt_profile .
-docker-push:
+docker-push: ## Push the docker images to an external repository
docker push ${ADAPTER_IMAGENAME}
-docker-kind-load:
+docker-kind-load: ## Load docker images into a KinD cluster
@if [ "`kind get clusters | grep voltha-$(TYPE)`" = '' ]; then echo "no voltha-$(TYPE) cluster found" && exit 1; fi
kind load docker-image ${ADAPTER_IMAGENAME} --name=voltha-$(TYPE) --nodes $(shell kubectl get nodes --template='{{range .items}}{{.metadata.name}},{{end}}' | sed 's/,$$//')
-
## lint and unit tests
-
-lint-dockerfile:
+lint-dockerfile: ## Perform static analysis on Dockerfile
@echo "Running Dockerfile lint check ..."
@${HADOLINT} $$(find . -name "Dockerfile.*")
@echo "Dockerfile lint check OK"
-lint-mod:
+lint-mod: ## Verify the Go dependencies
@echo "Running dependency check..."
@${GO} mod verify
@echo "Dependency check OK. Running vendor check..."
@@ -135,9 +110,9 @@
@[[ `git ls-files --exclude-standard --others go.mod go.sum vendor` == "" ]] || (echo "ERROR: Untracked files detected after running go mod tidy / go mod vendor" && git status -- go.mod go.sum vendor && git checkout -- go.mod go.sum vendor && exit 1)
@echo "Vendor check OK."
-lint: local-lib-go lint-mod lint-dockerfile
+lint: local-lib-go lint-mod lint-dockerfile ## Run all lint targets
-test:
+test: ## Run unit tests
@mkdir -p ./tests/results
@${GO} test -mod=vendor -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
RETURN=$$? ;\
@@ -145,7 +120,7 @@
${GOCOVER_COBERTURA} < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
exit $$RETURN
-sca:
+sca: ## Runs static code analysis with the golangci-lint tool
@rm -rf ./sca-report
@mkdir -p ./sca-report
@echo "Running static code analysis..."
@@ -153,11 +128,19 @@
@echo ""
@echo "Static code analysis OK"
-clean: distclean
+clean: distclean ## Removes any local filesystem artifacts generated by a build
-distclean:
+distclean: ## Removes any local filesystem artifacts generated by a build or test run
rm -rf ./sca-report
-mod-update:
+mod-update: ## Update go mod files
${GO} mod tidy
${GO} mod vendor
+
+# For each makefile target, add ## <description> on the target line and it will be listed by 'make help'
+help: ## Print help for each Makefile target
+ @echo "Usage: make [<target>]"
+ @echo "where available targets are:"
+ @echo
+ @grep '^[[:alpha:]_-]*:.* ##' $(MAKEFILE_LIST) \
+ | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s : %s\n", $$1, $$2};'
diff --git a/README.md b/README.md
index 9f68195..7b1ce81 100644
--- a/README.md
+++ b/README.md
@@ -1,29 +1,60 @@
-# How to Build the Golang based OpenOLT Adapter
+# OpenOLT adapter
-## Working with Go Dependencies
-This project uses Go Modules https://github.com/golang/go/wiki/Modules to manage
-dependencies. As a local best pratice this project also vendors the dependencies.
-If you need to update dependencies please follow the Go Modules best practices
-and also perform the following steps before committing a patch:
-```bash
-go mod tidy
-go mod verify
-go mod vendor
+The OpenOLT adapter connects the [VOLTHA
+core](https://gerrit.opencord.org/gitweb?p=voltha-go.git) to an OLT device
+running the [OpenOLT agent](https://gerrit.opencord.org/gitweb?p=openolt.git).
+
+## Development `make` targets
+
+The `Makefile` contains many commands that are useful in development:
+
+```
+build : Alias for 'docker build'
+clean : Removes any local filesystem artifacts generated by a build
+distclean : Removes any local filesystem artifacts generated by a build or test run
+docker-build-profile : Build openolt adapter docker image with profiling enabled
+docker-build : Build openolt adapter docker image
+docker-kind-load : Load docker images into a KinD cluster
+docker-push : Push the docker images to an external repository
+help : Print help for each Makefile target
+lint-dockerfile : Perform static analysis on Dockerfile
+lint-mod : Verify the Go dependencies
+lint : Run all lint targets
+local-lib-go : Copies a local version of the voltha-lib-go dependency into the vendor directory
+local-protos : Copies a local version of the voltha-protos dependency into the vendor directory
+mod-update : Update go mod files
+sca : Runs static code analysis with the golangci-lint tool
+test : Run unit tests
```
-## Building with a Local Copy of `voltha-protos` or `voltha-lib-go`
-If you want to build/test using a local copy or `voltha-protos` or `voltha-lib-go`
-this can be accomplished by using the environment variables `LOCAL_PROTOS` and
-`LOCAL_LIB_GO`. These environment variables should be set to the filesystem
-path where the local source is located, e.g.
+Some highlights:
+
+- It's recommended that you run the `lint`, `sca`, and `test` targets before
+ submitting code changes.
+
+- The `docker-*` targets for building and pushing Docker images depend on the
+ variables `DOCKER_REGISTRY`, `DOCKER_REPOSITORY`, and `DOCKER_TAG` as
+ [described in the CORD
+ documentation](https://guide.opencord.org/developer/test_release_software.html#publish-docker-container-images-to-public-dockerhub-job-docker-publish)
+
+- If you make changes the dependencies in the `go.mod` file, you will need to
+ run `make mod-update` to update the `go.sum` and `vendor` directory.
+
+### Building with a Local Copy of `voltha-protos` or `voltha-lib-go`
+
+If you want to build/test using a local copy of the `voltha-protos` or
+`voltha-lib-go` libraries this can be accomplished by using the environment
+variables `LOCAL_PROTOS` and `LOCAL_LIB_GO`. These environment variables should
+be set to the filesystem path where the local source is located, e.g.:
```bash
-LOCAL\_PROTOS=$HOME/src/voltha-protos
-LOCAL\_LIB\_GO=$HOME/src/voltha-lib-go
+export LOCAL_PROTOS=/path/to/voltha-protos
+export LOCAL_LIB_GO=/path/to/voltha-lib-go
```
-When these environment variables are set the vendored versions of these packages
-will be removed from the `vendor` directory and replaced by coping the files from
-the specified locations to the `vendor` directory. *NOTE:* _this means that
-the files in the `vendor` directory are no longer what is in the `git` repository
-and it will take manual `git` intervention to put the original files back._
+Then run `make local-protos` and/or `make local-lib-go` as is appropriate to
+copy them into the `vendor` directory.
+
+> NOTE: That the files in the `vendor` directory are no longer what is in the
+> most recent commit, and it will take manual `git` intervention to put the
+> original files back.