From 0cc3998a4f54b294b99941351fa2c63aa0a92cc2 Mon Sep 17 00:00:00 2001 From: Ahmed Kamal Date: Wed, 14 Feb 2018 16:18:01 +0100 Subject: [PATCH] :large_blue_circle: Circle CI integration. --- .circleci/config.yml | 27 +++++++++++++++++++++++++ .mailmap | 1 + .travis.yml | 2 +- MAINTAINERS | 28 ++++++++++++++++++++++++++ Makefile | 44 ----------------------------------------- Makefile.conf | 4 ++++ README.md | 4 ++-- app/http_server_test.go | 10 +++++----- mk/docker.mk | 10 +++++----- mk/main.mk | 1 + mk/utils.mk | 43 ++++++++++++++++++++++++++++++++++++++++ mk/validate.mk | 10 +++++++++- 12 files changed, 126 insertions(+), 58 deletions(-) create mode 100644 .circleci/config.yml create mode 100644 .mailmap create mode 100644 MAINTAINERS create mode 100644 mk/utils.mk diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..72a9a20 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,27 @@ +version: 2 +jobs: + validation: + docker: + - image: circleci/golang:1.9-alpine + working_directory: /go/src/github.com/ahmedkamals/foo-protocol-proxy + steps: + - checkout + - run: make get-deps setup validate nuke + + unit: + docker: + - image: circleci/golang:1.9-alpine + + working_directory: /go/src/github.com/ahmedkamals/foo-protocol-proxy + steps: + - checkout + - run: make setup unit nuke + + integration: + docker: + - image: circleci/golang:1.9-alpine + + working_directory: /go/src/github.com/ahmedkamals/foo-protocol-proxy + steps: + - checkout + - run: make setup integration nuke diff --git a/.mailmap b/.mailmap new file mode 100644 index 0000000..9d729bf --- /dev/null +++ b/.mailmap @@ -0,0 +1 @@ +Ahmed Kamal Ahmed Kamal diff --git a/.travis.yml b/.travis.yml index 9fe62c7..0d8635f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -75,7 +75,7 @@ script: # This to fix the error "fatal: ref HEAD is not a symbolic ref", that appears after every make call. - git checkout -b build-${TRAVIS_PULL_REQUEST} - if [ "$BUILD" == true ]; then make build ; else echo 'skipping build.'; fi - - if [ "$VALIDATE" == true ]; then make validate ; else echo 'skipping verfication.'; fi + - if [ "$VALIDATE" == true ]; then make validate ; else echo 'skipping verification.'; fi - if [ "$COVERAGE" == true ]; then make cover; travis_retry make coverage-send || true ; else echo 'skipping coverage.'; fi - if [ "$TESTS" == true ]; then make unit race bench ; else echo 'skipping tests.'; fi diff --git a/MAINTAINERS b/MAINTAINERS new file mode 100644 index 0000000..b215b35 --- /dev/null +++ b/MAINTAINERS @@ -0,0 +1,28 @@ +# InfraKit maintainers file +# +# This file describes who runs the foo-protocol-proxy project and how. +# This is a living document - if you see something out of date or missing, speak up! +# +# It is structured to be consumable by both humans and programs. +# To extract its contents programmatically, use any TOML-compliant parser. +# +# This file is compiled into the MAINTAINERS file in docker/opensource. +# +[Org] + [Org."Core maintainers"] + people = [ + "ahmedkamals" + ] + +[people] + +# A reference list of all people associated with the project. +# All other sections should refer to people by their canonical key +# in the people section. + + # ADD YOURSELF HERE IN ALPHABETICAL ORDER + + [people.ahmedkamals] + Name = "Ahmed Kamal" + Email = "me.ahmed.kamal@gmail.com" + GitHub = "ahmedkamals" diff --git a/Makefile b/Makefile index 647c026..5eb94e8 100644 --- a/Makefile +++ b/Makefile @@ -4,47 +4,3 @@ include Makefile.conf include mk/main.mk - -all: setup generate test coverage-html validate format nuke build-x install clean list help deploy ## to run all targets. - -list: ## to list all targets. - @$(MAKE) -rRpqn | awk -F':' '/^[a-z0-9][^$#\/\t=]*:([^=]|$$)/ {split($$1,A,/ /);for(i in A)printf "$(DISCLAIMER_COLOR)%-30s$(NO_COLOR)\n", A[i]}' | sort -u 2>&1 - -help: ## to get help about the targets. - @echo "$(OK_COLOR)$$FOO_PROTOCOL_PROXY$(NO_COLOR)" - @echo "$(INFO_COLOR)Please use \`make \`, Available options for are:$(NO_COLOR)\n" - @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z._-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf " $(HELP_COLOR)%-28s$(NO_COLOR) %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort -u 2>&1 - @echo "Useful variables:" - @awk 'BEGIN { FS = ":=" } /^## /{x = substr($$0, 4); getline; if (NF >= 2) printf " $(DISCLAIMER_COLOR)%-28s$(NO_COLOR) %s\n", $$1, x}' $(MAKEFILE_LIST) | sort -u 2>&1 - -setup: ## to setup the external used tools. - @echo "$(OK_COLOR)$(MSG_PREFIX) Setting-up required components$(MSG_SUFFIX)$(NO_COLOR)" - @$(GO) install $(GO_FLAGS) -tags $(GO_TAGS) $(PKGS) 2>&1 - -get-deps: ## to get required dependencies. - @echo "$(OK_COLOR)$(MSG_PREFIX) Installing required dependencies$(MSG_SUFFIX)$(NO_COLOR)" - @$(foreach dependency, $(DEPENDENCIES), $(call getDependency,$(dependency))) - -generate: ## to generate related files. - @echo "$(OK_COLOR)$(MSG_PREFIX) Generating files via go generate$(MSG_SUFFIX)$(NO_COLOR)" - @$(GO) generate $(GO_FLAGS) $(PKGS) 2>&1 - -install: ## to install the generated binary. - @echo "$(OK_COLOR)$(MSG_PREFIX) Installing generated binary$(MSG_SUFFIX)$(NO_COLOR)" - @if [ ! -f $(TARGET_BINARY) ] ; then $(MAKE) build; fi - @cp $(TARGET_BINARY) /usr/local/bin 2>&1 - -clean: clean-bin clean-coverage ## to clean up all generated files. - -nuke: clean ## to do clean up and enforce removing the corresponding installed archive or binary. - @echo "$(OK_COLOR)$(MSG_PREFIX) Cleaning go dependencies$(MSG_SUFFIX)$(NO_COLOR)" - @$(GO) clean -i $(GO_FLAGS) ./... net 2>&1 - -run: ## to run the generated binary, and build a new one if not existed. - @echo "$(OK_COLOR)$(MSG_PREFIX) Running generated binary$(MSG_SUFFIX)$(NO_COLOR)" - @if [ ! -f $(TARGET_BINARY) ] ; then $(MAKE) build; fi - @$(TARGET_BINARY) $(args) 2>&1 - -kill: ## to send a kill signal to the running process of the binary. - @echo "$(OK_COLOR)$(MSG_PREFIX) Sending kill signal $(args)$(MSG_SUFFIX)$(NO_COLOR)" - @pkill $(args) $(notdir $(TARGET_BINARY)) > /dev/null 2>&1 diff --git a/Makefile.conf b/Makefile.conf index 0892780..782a8c4 100644 --- a/Makefile.conf +++ b/Makefile.conf @@ -10,6 +10,8 @@ MSG_SUFFIX := ... DEPENDENCIES := golang.org/x/tools/cmd/cover \ github.com/golang/lint/golint \ + github.com/client9/misspell/cmd/misspell \ + github.com/gordonklaus/ineffassign \ github.com/mattn/goveralls \ github.com/wadey/gocovmerge @@ -35,6 +37,8 @@ STATIC := true ## Set an output prefix, which is the local directory if not specified. BINARY_PATH_PREFIX := $(CURDIR) BINARY_PATH := ${BINARY_PATH_PREFIX}/bin +## Base path used to install. +INSTALLATION_BASE_PATH := /usr/local/bin # Tests ## The number of parallel tests. diff --git a/README.md b/README.md index 7e7ba3f..cdb09d3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Foo Protocol Proxy [![Build Status](https://travis-ci.org/ahmedkamals/foo-protocol-proxy.svg)](https://travis-ci.org/ahmedkamals/foo-protocol-proxy "Build Status") +Foo Protocol Proxy [![Travis CI](https://travis-ci.org/ahmedkamals/foo-protocol-proxy.svg)](https://travis-ci.org/ahmedkamals/foo-protocol-proxy "Build Status") [![CircleCI](https://circleci.com/ahmedkamals/foo-protocol-prox.svg?style=svg&circle-token=50d2063f283f98b7d94746416c979af3102275b5)](https://circleci.com/ahmedkamals/foo-protocol-proxy "Build Status") ================== [![GitHub tag](https://img.shields.io/github/tag/ahmedkamals/foo-protocol-proxy.svg?style=flat)](https://github.com/ahmedkamals/foo-protocol-proxy/releases "Version Tag") @@ -200,7 +200,7 @@ $ make test | [`Proxy`][7] | orchestrates the interactions between the components. | | [`Listner`][8] | awaits for client connections, and on every new connection, a `BridgeConnection` instance is created. | | [`BridgeConnection`][9] | acts as Bi-directional communication object, that passes data forward and backward to the server. | -| [`Analyzer`][10] | perform `analysis` by sniffing all the data read and written from the server. | +| [`Analyzer`][10] | performs `analysis` by sniffing all the data read and written from the server. | | [`Stats`][11] | wraps stats data the would be flushed to stdout upon request. | | [`TimeTable`][12] | contains snapshot of aggregated number of requests/responses at specific timestamp. | | [`Saver`][13] | handles reading/writing data. | diff --git a/app/http_server_test.go b/app/http_server_test.go index 9d6e22d..7bb39ed 100644 --- a/app/http_server_test.go +++ b/app/http_server_test.go @@ -48,12 +48,12 @@ func TestShouldConfigureRoutesCorrectly(t *testing.T) { t.Error(testCase.Format(actual)) } continue - } else { - expected := testCase.Expected.(*http.ServeMux) + } - if !reflect.DeepEqual(expected, actual) { - t.Error(testCase.Format(actual)) - } + expected := testCase.Expected.(*http.ServeMux) + + if !reflect.DeepEqual(expected, actual) { + t.Error(testCase.Format(actual)) } } } diff --git a/mk/docker.mk b/mk/docker.mk index 0c7f616..2542f46 100644 --- a/mk/docker.mk +++ b/mk/docker.mk @@ -1,21 +1,21 @@ DOCKER := $(shell docker info > /dev/null 2>&1 || $(SUDO) 2>&1) docker image: ## to build a docker image. - @echo "$(WARN_COLOR)$(MSG_PREFIX) Creating Docker Image$(MSG_SUFFIX)$(NO_COLOR)" + @echo "$(WARN_COLOR)$(MSG_PREFIX) 🐳 Creating Docker Image$(MSG_SUFFIX)$(NO_COLOR)" @$(DOCKER) build ${DOCKER_BUILD_FLAGS} -t $(REGISTRY_REPO):$(DOCKER_TAG) -f $(DOCKER_FILE) $(args) 2>&1 deploy: ## to deploy a docker container. - @echo "$(WARN_COLOR)$(MSG_PREFIX) Deploying Docker Container$(MSG_SUFFIX)$(NO_COLOR)" + @echo "$(WARN_COLOR)$(MSG_PREFIX) 🐳 Deploying Docker Container$(MSG_SUFFIX)$(NO_COLOR)" @$(SUDO) bash ./deploy.sh $(args) 2>&1 publish: ## to publish the docker image to dockerhub repository. - @echo "$(WARN_COLOR)$(MSG_PREFIX) Pushing Docker Image to $(REGISTRY_REPO):$(DOCKER_TAG)$(MSG_SUFFIX)$(NO_COLOR)" + @echo "$(WARN_COLOR)$(MSG_PREFIX) 🐳 Pushing Docker Image to $(REGISTRY_REPO):$(DOCKER_TAG)$(MSG_SUFFIX)$(NO_COLOR)" @$(DOCKER) push $(REGISTRY_REPO):$(DOCKER_TAG) 2>&1 docker-kill: ## to send kill signal to the main process at the docker container. - @echo "$(WARN_COLOR)$(MSG_PREFIX) Sending kill signal to main Docker process$(MSG_SUFFIX)$(NO_COLOR)" + @echo "$(WARN_COLOR)$(MSG_PREFIX) 🐳 Sending kill signal to main Docker process$(MSG_SUFFIX)$(NO_COLOR)" @$(DOCKER) exec -it $(BINARY_PREFIX)-${DOCKER_TAG} pkill $(args) $(BINARY_PREFIX) > /dev/null 2>&1 docker-logs: ## to get logs from the docker container. - @echo "$(WARN_COLOR)$(MSG_PREFIX) Getting logs of the Docker container$(MSG_SUFFIX)$(NO_COLOR)" + @echo "$(WARN_COLOR)$(MSG_PREFIX) 🐳 Getting logs of the Docker container$(MSG_SUFFIX)$(NO_COLOR)" @$(DOCKER) logs -f $(BINARY_PREFIX)-${DOCKER_TAG} 2>&1 diff --git a/mk/main.mk b/mk/main.mk index cda673a..e4af697 100644 --- a/mk/main.mk +++ b/mk/main.mk @@ -9,6 +9,7 @@ PKG_BASE ?= $(shell $(GO) list -e ./ 2> /dev/null) PKGS ?= $(shell $(GO) list ./... 2> /dev/null | grep -v /vendor/) GO_FILES := $(shell find . -name "*.go" -type f -not -path "./vendor/*" 2> /dev/null) +include mk/utils.mk include mk/build.mk include mk/coverage.mk include mk/docker.mk diff --git a/mk/utils.mk b/mk/utils.mk new file mode 100644 index 0000000..c890cce --- /dev/null +++ b/mk/utils.mk @@ -0,0 +1,43 @@ +all: setup generate test coverage-html validate format nuke build-x install clean list help deploy ## to run all targets. + +list: ## to list all targets. + @$(MAKE) -rRpqn | awk -F':' '/^[a-z0-9][^$#\/\t=]*:([^=]|$$)/ {split($$1,A,/ /);for(i in A)printf "$(DISCLAIMER_COLOR)%-30s$(NO_COLOR)\n", A[i]}' | sort -u 2>&1 + +help: ## to get help about the targets. + @echo "$(OK_COLOR)$$FOO_PROTOCOL_PROXY$(NO_COLOR)" + @echo "$(INFO_COLOR)Please use \`make \`, Available options for are:$(NO_COLOR)\n" + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z._-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf " $(HELP_COLOR)%-28s$(NO_COLOR) %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort -u 2>&1 + @echo "Useful variables:" + @awk 'BEGIN { FS = ":=" } /^## /{x = substr($$0, 4); getline; if (NF >= 2) printf " $(DISCLAIMER_COLOR)%-28s$(NO_COLOR) %s\n", $$1, x}' $(MAKEFILE_LIST) | sort -u 2>&1 + +setup: ## to setup the external used tools. + @echo "$(OK_COLOR)$(MSG_PREFIX) Setting-up required components$(MSG_SUFFIX)$(NO_COLOR)" + @$(GO) install $(GO_FLAGS) -tags $(GO_TAGS) $(PKGS) 2>&1 + +get-deps: ## to get required dependencies. + @echo "$(OK_COLOR)$(MSG_PREFIX) Installing required dependencies$(MSG_SUFFIX)$(NO_COLOR)" + @$(foreach dependency, $(DEPENDENCIES), $(call getDependency,$(dependency))) + +generate: ## to generate related files. + @echo "$(OK_COLOR)$(MSG_PREFIX) Generating files via go generate$(MSG_SUFFIX)$(NO_COLOR)" + @$(GO) generate $(GO_FLAGS) $(PKGS) 2>&1 + +install: ## to install the generated binary. + @echo "$(OK_COLOR)$(MSG_PREFIX) Installing generated binary$(MSG_SUFFIX)$(NO_COLOR)" + @if [ ! -f $(TARGET_BINARY) ] ; then $(MAKE) build; fi + @cp $(TARGET_BINARY) $(INSTALLATION_BASE_PATH) 2>&1 + +clean: clean-bin clean-coverage ## to clean up all generated files. + +nuke: clean ## to do clean up and enforce removing the corresponding installed archive or binary. + @echo "$(OK_COLOR)$(MSG_PREFIX) Cleaning go dependencies$(MSG_SUFFIX)$(NO_COLOR)" + @$(GO) clean -i $(GO_FLAGS) ./... net 2>&1 + +run: ## to run the generated binary, and build a new one if not existed. + @echo "$(OK_COLOR)$(MSG_PREFIX) Running generated binary$(MSG_SUFFIX)$(NO_COLOR)" + @if [ ! -f $(TARGET_BINARY) ] ; then $(MAKE) build; fi + @$(TARGET_BINARY) $(args) 2>&1 + +kill: ## to send a kill signal to the running process of the binary. + @echo "$(OK_COLOR)$(MSG_PREFIX) Sending kill signal $(args)$(MSG_SUFFIX)$(NO_COLOR)" + @pkill $(args) $(notdir $(TARGET_BINARY)) > /dev/null 2>&1 diff --git a/mk/validate.mk b/mk/validate.mk index 1657af3..a6fea85 100644 --- a/mk/validate.mk +++ b/mk/validate.mk @@ -1,4 +1,4 @@ -validate: vet lint format-check ## to validate the code. +validate: vet lint format-check misspell ineffassign ## to validate the code. # Simplified dead code detector. Used for skipping certain checks on unreachable code # (for instance, shift checks on arch-specific code). @@ -23,3 +23,11 @@ format-check: ## to check if the go files are formatted correctly. format: ## to format all go files. @echo "$(WARN_COLOR)$(MSG_PREFIX) Formatting code$(MSG_SUFFIX)$(NO_COLOR)" @test -z "$$($(GO_FMT) -s -w $(GO_FLAGS) $(GO_FILES) 2>&1 | tee /dev/stderr)" + +misspell: ## to run misspell. + @echo "$(WARN_COLOR)$(MSG_PREFIX) Running misspell$(MSG_SUFFIX)$(NO_COLOR)" + @test -z "$$(find . -type f | grep -v vendor/ | grep -v bin/ | grep -v .git/ | grep -v MAINTAINERS | xargs misspell | tee /dev/stderr)" + +ineffassign: ## to run ineffassign. + @echo "$(WARN_COLOR)$(MSG_PREFIX) Running ineffassign$(MSG_SUFFIX)$(NO_COLOR)" + @test -z "$$(ineffassign . | grep -v vendor/ | grep -v ".pb.go:" | tee /dev/stderr)"